Code for importing packagesite.yaml information into FreshPorts https://www.freshports.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.3KB

  1. #!/usr/local/bin/python
  2. # Update the packages_raw table with port_id and abi_id
  3. # Then update the packages tables from packages_raw
  4. import psycopg2
  5. import psycopg2.extras
  6. import configparser # for config.ini parsing
  7. import re # for escaping the database passwords
  8. import syslog # for logging
  9. from pathlib import Path # for touching the signal file
  10. import os
  11. syslog.openlog(ident=os.path.basename(__file__), facility=syslog.LOG_LOCAL3)
  12. syslog.syslog(syslog.LOG_NOTICE, 'Starting up')
  13. config = configparser.ConfigParser()
  14. config.read('/usr/local/etc/freshports/config.ini')
  15. SCRIPT_DIR = config['filesystem']['SCRIPT_DIR']
  16. DSN = 'host=' + config['database']['HOST'] + ' dbname=' + config['database']['DBNAME'] + ' user=' + config['database']['PACKAGER_DBUSER'] + ' password=' + re.escape(config['database']['PACKAGER_PASSWORD'])
  17. # the flag we will remove
  18. SIGNAL_NEW_REPO_IMPORTED = config['filesystem']['SIGNAL_NEW_REPO_IMPORTED']
  19. dbh = psycopg2.connect(DSN)
  20. curs = dbh.cursor(cursor_factory=psycopg2.extras.DictCursor)
  21. # for updating the rows
  22. cursUpdate = dbh.cursor(cursor_factory=psycopg2.extras.DictCursor)
  23. curs.execute("SELECT * from PackagesGetImportedReposNeedingProcessing()")
  24. NumRows = curs.rowcount
  25. if (NumRows > 0):
  26. rows = curs.fetchall()
  27. for row in rows:
  28. syslog.syslog(syslog.LOG_NOTICE, 'updating packages table for ' + row['abi_name'] + '/' + row['package_set']);
  29. cursUpdate.execute("BEGIN");
  30. cursUpdate.callproc('UpdatePackagesFromRawPackages', (row['abi_name'],row['package_set']))
  31. # I'm not sure how to properly check the return value so,
  32. # be sure to terminate this transaction one way or another
  33. cursUpdate.execute("COMMIT");
  34. cursUpdate.execute("ROLLBACK");
  35. cursUpdate.execute("ROLLBACK");
  36. # we must always remove the flag
  37. Path(SIGNAL_NEW_REPO_IMPORTED).unlink()
  38. if NumRows > 0:
  39. # set the flag for job-waiting.pl
  40. syslog.syslog(syslog.LOG_NOTICE, 'There were ' + str(NumRows) + ' repos updated in packages.')
  41. # this will prompt the front ends to clear their package caches
  42. cursUpdate.execute("NOTIFY packages_imported")
  43. else:
  44. syslog.syslog(syslog.LOG_NOTICE, 'There were no packages to update. I should never be called like this. It is such an inconvenience. Have you no shame?')
  45. dbh.close();
  46. syslog.syslog(syslog.LOG_NOTICE, 'Finishing')