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.

76 lines
2.6KB

  1. #!/usr/local/bin/python
  2. # check the repos for new build
  3. import psycopg2
  4. import psycopg2.extras
  5. import configparser # for config.ini parsing
  6. import re # for escaping the database passwords
  7. import syslog # for logging
  8. from pathlib import Path # for touching the signal file
  9. import os
  10. import sys
  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. SIGNAL_NEW_REPO_READY_FOR_IMPORT = config['filesystem']['SIGNAL_NEW_REPO_READY_FOR_IMPORT']
  18. SIGNAL_JOB_WAITING = config['filesystem']['SIGNAL_JOB_WAITING']
  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. # There are no repos to import
  24. ReposWhichNeedImporting = []
  25. curs.execute("SELECT * from GetReposToReview()")
  26. NumRows = curs.rowcount
  27. dbh.commit();
  28. if (NumRows > 0):
  29. rows = curs.fetchall()
  30. for row in rows:
  31. command = SCRIPT_DIR + "/get_packagesite.txz_date " + row['abi_name'] + " " + row['package_set']
  32. timestamp = os.popen(command).readlines()
  33. if timestamp == []:
  34. repo_date = None
  35. else:
  36. repo_date = timestamp[0].strip()
  37. syslog.syslog(syslog.LOG_NOTICE, 'checking: ' + row['abi_name'] + '/' + row['package_set'] + ' : ' + str(repo_date or ""))
  38. # now we update the last_checked and repo_date in the packages_last_checked table
  39. # PackagesLastCheckedSetRepoDate(a_abi_name text, a_package_set text, a_CheckedDate text)
  40. cursUpdate.callproc('PackagesLastCheckedSetRepoDate', (row['abi_name'],row['package_set'], repo_date))
  41. retval = cursUpdate.fetchone()[0]
  42. if retval == 1:
  43. ReposWhichNeedImporting.append(row['abi_name'] + '/' + row['package_set'] + ' : ' + str(repo_date or ""))
  44. dbh.commit();
  45. dbh.close();
  46. if len(ReposWhichNeedImporting) > 0:
  47. # set the flag for job-waiting.pl
  48. Path(SIGNAL_NEW_REPO_READY_FOR_IMPORT).touch()
  49. Path(SIGNAL_JOB_WAITING).touch()
  50. syslog.syslog(syslog.LOG_NOTICE, 'There are ' + str(len(ReposWhichNeedImporting)) + ' new repos ready for import: ' + str(ReposWhichNeedImporting))
  51. else:
  52. syslog.syslog(syslog.LOG_NOTICE, 'No repos need importing')
  53. syslog.syslog(syslog.LOG_NOTICE, 'finishes');