Commit 603b5b5d authored by Lukas Fleischer's avatar Lukas Fleischer
Browse files

Add a main() method to all Python scripts



Move the main program logic of all scripts to main() methods such that
they can be used as modules and easily be invoked by setuptools wrapper
scripts.
Signed-off-by: Lukas Fleischer's avatarLukas Fleischer <lfleischer@archlinux.org>
parent f3fb614f
......@@ -18,12 +18,14 @@ db_path = config.get('aurblup', 'db-path')
sync_dbs = config.get('aurblup', 'sync-dbs').split(' ')
servers = config.get('aurblup', 'servers').split(' ')
blacklist = set()
providers = set()
repomap = dict()
h = pyalpm.Handle("/", db_path)
for sync_db in sync_dbs:
def main():
blacklist = set()
providers = set()
repomap = dict()
h = pyalpm.Handle("/", db_path)
for sync_db in sync_dbs:
repo = h.register_syncdb(sync_db, pyalpm.SIG_DATABASE_OPTIONAL)
repo.servers = [server.replace("%s", sync_db) for server in servers]
t = h.init_transaction()
......@@ -40,21 +42,25 @@ for sync_db in sync_dbs:
providers.add((pkg.name, provisionname))
repomap[(pkg.name, provisionname)] = repo.name
db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
passwd=aur_db_pass, db=aur_db_name,
unix_socket=aur_db_socket, buffered=True)
cur = db.cursor()
cur = db.cursor()
cur.execute("SELECT Name, Provides FROM OfficialProviders")
oldproviders = set(cur.fetchall())
cur.execute("SELECT Name, Provides FROM OfficialProviders")
oldproviders = set(cur.fetchall())
for pkg, provides in providers.difference(oldproviders):
for pkg, provides in providers.difference(oldproviders):
repo = repomap[(pkg, provides)]
cur.execute("INSERT INTO OfficialProviders (Name, Repo, Provides) "
"VALUES (%s, %s, %s)", [pkg, repo, provides])
for pkg, provides in oldproviders.difference(providers):
for pkg, provides in oldproviders.difference(providers):
cur.execute("DELETE FROM OfficialProviders "
"WHERE Name = %s AND Provides = %s", [pkg, provides])
db.commit()
db.close()
db.commit()
db.close()
if __name__ == '__main__':
main()
......@@ -17,25 +17,33 @@ aur_db_user = config.get('database', 'user')
aur_db_pass = config.get('database', 'password')
aur_db_socket = config.get('database', 'socket')
db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
def main():
db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
passwd=aur_db_pass, db=aur_db_name,
unix_socket=aur_db_socket, buffered=True)
cur = db.cursor()
cur = db.cursor()
datestr = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")
pkglist_header = "# AUR package list, generated on " + datestr
pkgbaselist_header = "# AUR package base list, generated on " + datestr
datestr = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")
pkglist_header = "# AUR package list, generated on " + datestr
pkgbaselist_header = "# AUR package base list, generated on " + datestr
with gzip.open(docroot + "packages.gz", "w") as f:
with gzip.open(docroot + "packages.gz", "w") as f:
f.write(bytes(pkglist_header + "\n", "UTF-8"))
cur.execute("SELECT Packages.Name FROM Packages INNER JOIN PackageBases " +
cur.execute("SELECT Packages.Name FROM Packages " +
"INNER JOIN PackageBases " +
"ON PackageBases.ID = Packages.PackageBaseID " +
"WHERE PackageBases.PackagerUID IS NOT NULL")
f.writelines([bytes(x[0] + "\n", "UTF-8") for x in cur.fetchall()])
with gzip.open(docroot + "pkgbase.gz", "w") as f:
with gzip.open(docroot + "pkgbase.gz", "w") as f:
f.write(bytes(pkgbaselist_header + "\n", "UTF-8"))
cur.execute("SELECT Name FROM PackageBases WHERE PackagerUID IS NOT NULL")
cur.execute("SELECT Name FROM PackageBases " +
"WHERE PackagerUID IS NOT NULL")
f.writelines([bytes(x[0] + "\n", "UTF-8") for x in cur.fetchall()])
db.close()
db.close()
if __name__ == '__main__':
main()
......@@ -427,7 +427,7 @@ def tu_vote_reminder(cur, vote_id):
send_notification(to, subject, body, refs)
if __name__ == '__main__':
def main():
action = sys.argv[1]
action_map = {
'send-resetkey': send_resetkey,
......@@ -454,3 +454,7 @@ if __name__ == '__main__':
db.commit()
db.close()
if __name__ == '__main__':
main()
......@@ -13,13 +13,20 @@ aur_db_user = config.get('database', 'user')
aur_db_pass = config.get('database', 'password')
aur_db_socket = config.get('database', 'socket')
db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
def main():
db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
passwd=aur_db_pass, db=aur_db_name,
unix_socket=aur_db_socket, buffered=True)
cur = db.cursor()
cur = db.cursor()
cur.execute("DELETE FROM PackageBases WHERE " +
"UNIX_TIMESTAMP() - SubmittedTS > 86400 " +
"AND PackagerUID IS NULL")
db.commit()
db.close()
cur.execute("DELETE FROM PackageBases WHERE " +
"UNIX_TIMESTAMP() - SubmittedTS > 86400 AND PackagerUID IS NULL")
db.commit()
db.close()
if __name__ == '__main__':
main()
......@@ -13,18 +13,25 @@ aur_db_user = config.get('database', 'user')
aur_db_pass = config.get('database', 'password')
aur_db_socket = config.get('database', 'socket')
db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
def main():
db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
passwd=aur_db_pass, db=aur_db_name,
unix_socket=aur_db_socket, buffered=True)
cur = db.cursor()
cur = db.cursor()
cur.execute("UPDATE PackageBases SET NumVotes = (SELECT COUNT(*) FROM " +
"PackageVotes WHERE PackageVotes.PackageBaseID = PackageBases.ID)")
cur.execute("UPDATE PackageBases SET NumVotes = (" +
"SELECT COUNT(*) FROM PackageVotes " +
"WHERE PackageVotes.PackageBaseID = PackageBases.ID)")
cur.execute("UPDATE PackageBases SET Popularity = (" +
cur.execute("UPDATE PackageBases SET Popularity = (" +
"SELECT COALESCE(SUM(POWER(0.98, (UNIX_TIMESTAMP() - VoteTS) / 86400)), 0.0) " +
"FROM PackageVotes WHERE PackageVotes.PackageBaseID = " +
"PackageBases.ID AND NOT VoteTS IS NULL)")
db.commit()
db.close()
db.commit()
db.close()
if __name__ == '__main__':
main()
......@@ -16,17 +16,23 @@ aur_db_pass = config.get('database', 'password')
aur_db_socket = config.get('database', 'socket')
notify_cmd = config.get('notifications', 'notify-cmd')
db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
def main():
db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
passwd=aur_db_pass, db=aur_db_name,
unix_socket=aur_db_socket, buffered=True)
cur = db.cursor()
cur = db.cursor()
now = int(time.time())
filter_from = now + 500
filter_to = now + 172800
now = int(time.time())
filter_from = now + 500
filter_to = now + 172800
cur.execute("SELECT ID FROM TU_VoteInfo WHERE End >= %s AND End <= %s",
cur.execute("SELECT ID FROM TU_VoteInfo WHERE End >= %s AND End <= %s",
[filter_from, filter_to])
for vote_id in [row[0] for row in cur.fetchall()]:
for vote_id in [row[0] for row in cur.fetchall()]:
subprocess.Popen((notify_cmd, 'tu-vote-reminder', str(vote_id)))
if __name__ == '__main__':
main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment