Code for importing packagesite.yaml information into FreshPorts
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.

69 lines
2.3 KiB

# Update the packages_raw table with port_id and abi_id
# Then update the packages tables from packages_raw
import psycopg2
import psycopg2.extras
import configparser # for config.ini parsing
import re # for escaping the database passwords
import syslog # for logging
from pathlib import Path # for touching the signal file
import os
syslog.openlog(ident=os.path.basename(__file__), facility=syslog.LOG_LOCAL3)
syslog.syslog(syslog.LOG_NOTICE, 'Starting up')
config = configparser.ConfigParser()'/usr/local/etc/freshports/config.ini')
SCRIPT_DIR = config['filesystem']['SCRIPT_DIR']
DSN = 'host=' + config['database']['HOST'] + ' dbname=' + config['database']['DBNAME'] + ' user=' + config['database']['PACKAGER_DBUSER'] + ' password=' + re.escape(config['database']['PACKAGER_PASSWORD'])
# the flag we will remove
dbh = psycopg2.connect(DSN)
curs = dbh.cursor(cursor_factory=psycopg2.extras.DictCursor)
# for updating the rows
cursUpdate = dbh.cursor(cursor_factory=psycopg2.extras.DictCursor)
curs.execute("SELECT * from PackagesGetImportedReposNeedingProcessing()")
NumRows = curs.rowcount
if (NumRows > 0):
rows = curs.fetchall()
for row in rows:
syslog.syslog(syslog.LOG_NOTICE, 'updating packages table for ' + row['abi_name'] + '/' + row['package_set']);
cursUpdate.callproc('UpdatePackagesFromRawPackages', (row['abi_name'],row['package_set']))
# I'm not sure how to properly check the return value so,
# be sure to terminate this transaction one way or another
# we must always remove the flag
if NumRows > 0:
# set the flag for
syslog.syslog(syslog.LOG_NOTICE, 'There were ' + str(NumRows) + ' repos updated in packages.')
# this will prompt the front ends to clear their package caches
cursUpdate.execute("NOTIFY packages_imported")
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?')
syslog.syslog(syslog.LOG_NOTICE, 'Finishing')