summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2016-09-20 20:48:34 +0200
committerLukas Fleischer <lfleischer@archlinux.org>2016-09-29 22:07:23 +0200
commit8c99184f6d0922a7a4076d0c050a924e07a42b3d (patch)
treed3aeb2eb3bfc7f08e495a29da5953cebcd48ed1e /scripts
parentdc3fd60715a5b17b9542ec888c6eaeb14c284e2b (diff)
downloadaur-8c99184f6d0922a7a4076d0c050a924e07a42b3d.tar.gz
aur-8c99184f6d0922a7a4076d0c050a924e07a42b3d.tar.xz
Use config and db in scripts
Instead of using configparser and mysql.connector directly, change all Python scripts to use the config and db Python modules which are now accessible from a common location. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/aurblup.py37
-rwxr-xr-xscripts/mkpkglists.py32
-rwxr-xr-xscripts/notify.py273
-rwxr-xr-xscripts/pkgmaint.py28
-rwxr-xr-xscripts/popupdate.py40
-rwxr-xr-xscripts/tuvotereminder.py24
6 files changed, 184 insertions, 250 deletions
diff --git a/scripts/aurblup.py b/scripts/aurblup.py
index 07119b5f..0009715f 100755
--- a/scripts/aurblup.py
+++ b/scripts/aurblup.py
@@ -1,22 +1,14 @@
#!/usr/bin/python3
-import configparser
-import mysql.connector
-import os
import pyalpm
import re
-config = configparser.RawConfigParser()
-config.read(os.path.dirname(os.path.realpath(__file__)) + "/../conf/config")
+import aurweb.config
+import aurweb.db
-aur_db_host = config.get('database', 'host')
-aur_db_name = config.get('database', 'name')
-aur_db_user = config.get('database', 'user')
-aur_db_pass = config.get('database', 'password')
-aur_db_socket = config.get('database', 'socket')
-db_path = config.get('aurblup', 'db-path')
-sync_dbs = config.get('aurblup', 'sync-dbs').split(' ')
-servers = config.get('aurblup', 'servers').split(' ')
+db_path = aurweb.config.get('aurblup', 'db-path')
+sync_dbs = aurweb.config.get('aurblup', 'sync-dbs').split(' ')
+servers = aurweb.config.get('aurblup', 'servers').split(' ')
def main():
@@ -42,24 +34,21 @@ def main():
providers.add((pkg.name, provisionname))
repomap[(pkg.name, provisionname)] = repo.name
- 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()
+ conn = aurweb.db.Connection()
- cur.execute("SELECT Name, Provides FROM OfficialProviders")
+ cur = conn.execute("SELECT Name, Provides FROM OfficialProviders")
oldproviders = set(cur.fetchall())
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])
+ conn.execute("INSERT INTO OfficialProviders (Name, Repo, Provides) "
+ "VALUES (?, ?, ?)", [pkg, repo, provides])
for pkg, provides in oldproviders.difference(providers):
- cur.execute("DELETE FROM OfficialProviders "
- "WHERE Name = %s AND Provides = %s", [pkg, provides])
+ conn.execute("DELETE FROM OfficialProviders "
+ "WHERE Name = ? AND Provides = ?", [pkg, provides])
- db.commit()
- db.close()
+ conn.commit()
+ conn.close()
if __name__ == '__main__':
diff --git a/scripts/mkpkglists.py b/scripts/mkpkglists.py
index 8cab0a97..70cbd139 100755
--- a/scripts/mkpkglists.py
+++ b/scripts/mkpkglists.py
@@ -1,28 +1,16 @@
#!/usr/bin/python3
-import configparser
import datetime
import gzip
-import mysql.connector
import os
-docroot = os.path.dirname(os.path.realpath(__file__)) + "/../web/html/"
-
-config = configparser.RawConfigParser()
-config.read(os.path.dirname(os.path.realpath(__file__)) + "/../conf/config")
+import aurweb.db
-aur_db_host = config.get('database', 'host')
-aur_db_name = config.get('database', 'name')
-aur_db_user = config.get('database', 'user')
-aur_db_pass = config.get('database', 'password')
-aur_db_socket = config.get('database', 'socket')
+docroot = os.path.dirname(os.path.realpath(__file__)) + "/../web/html/"
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()
+ conn = aurweb.db.Connection()
datestr = datetime.datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT")
pkglist_header = "# AUR package list, generated on " + datestr
@@ -30,19 +18,19 @@ def main():
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 " +
- "ON PackageBases.ID = Packages.PackageBaseID " +
- "WHERE PackageBases.PackagerUID IS NOT NULL")
+ cur = conn.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:
f.write(bytes(pkgbaselist_header + "\n", "UTF-8"))
- cur.execute("SELECT Name FROM PackageBases " +
- "WHERE PackagerUID IS NOT NULL")
+ cur = conn.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()
+ conn.close()
if __name__ == '__main__':
diff --git a/scripts/notify.py b/scripts/notify.py
index e8210a87..ddd6e49b 100755
--- a/scripts/notify.py
+++ b/scripts/notify.py
@@ -1,28 +1,19 @@
#!/usr/bin/python3
-import configparser
import email.mime.text
-import mysql.connector
-import os
import subprocess
import sys
import textwrap
-config = configparser.RawConfigParser()
-config.read(os.path.dirname(os.path.realpath(__file__)) + '/../conf/config')
+import aurweb.config
+import aurweb.db
-aur_db_host = config.get('database', 'host')
-aur_db_name = config.get('database', 'name')
-aur_db_user = config.get('database', 'user')
-aur_db_pass = config.get('database', 'password')
-aur_db_socket = config.get('database', 'socket')
+aur_location = aurweb.config.get('options', 'aur_location')
+aur_request_ml = aurweb.config.get('options', 'aur_request_ml')
-aur_location = config.get('options', 'aur_location')
-aur_request_ml = config.get('options', 'aur_request_ml')
-
-sendmail = config.get('notifications', 'sendmail')
-sender = config.get('notifications', 'sender')
-reply_to = config.get('notifications', 'reply-to')
+sendmail = aurweb.config.get('notifications', 'sendmail')
+sender = aurweb.config.get('notifications', 'sender')
+reply_to = aurweb.config.get('notifications', 'reply-to')
def headers_cc(cclist):
@@ -60,120 +51,127 @@ def send_notification(to, subject, body, refs, headers={}):
p.communicate(msg.as_bytes())
-def username_from_id(cur, uid):
- cur.execute('SELECT UserName FROM Users WHERE ID = %s', [uid])
+def username_from_id(conn, uid):
+ cur = conn.execute('SELECT UserName FROM Users WHERE ID = ?', [uid])
return cur.fetchone()[0]
-def pkgbase_from_id(cur, pkgbase_id):
- cur.execute('SELECT Name FROM PackageBases WHERE ID = %s', [pkgbase_id])
+def pkgbase_from_id(conn, pkgbase_id):
+ cur = conn.execute('SELECT Name FROM PackageBases WHERE ID = ?',
+ [pkgbase_id])
return cur.fetchone()[0]
-def pkgbase_from_pkgreq(cur, reqid):
- cur.execute('SELECT PackageBaseID FROM PackageRequests WHERE ID = %s',
- [reqid])
+def pkgbase_from_pkgreq(conn, reqid):
+ cur = conn.execute('SELECT PackageBaseID FROM PackageRequests ' +
+ 'WHERE ID = ?', [reqid])
return cur.fetchone()[0]
-def get_user_email(cur, uid):
- cur.execute('SELECT Email FROM Users WHERE ID = %s', [uid])
+def get_user_email(conn, uid):
+ cur = conn.execute('SELECT Email FROM Users WHERE ID = ?', [uid])
return cur.fetchone()[0]
-def get_maintainer_email(cur, pkgbase_id):
- cur.execute('SELECT Users.Email FROM Users ' +
- 'INNER JOIN PackageBases ' +
- 'ON PackageBases.MaintainerUID = Users.ID WHERE ' +
- 'PackageBases.ID = %s', [pkgbase_id])
+def get_maintainer_email(conn, pkgbase_id):
+ cur = conn.execute('SELECT Users.Email FROM Users ' +
+ 'INNER JOIN PackageBases ' +
+ 'ON PackageBases.MaintainerUID = Users.ID WHERE ' +
+ 'PackageBases.ID = ?', [pkgbase_id])
return cur.fetchone()[0]
-def get_recipients(cur, pkgbase_id, uid):
- cur.execute('SELECT DISTINCT Users.Email FROM Users ' +
- 'INNER JOIN PackageNotifications ' +
- 'ON PackageNotifications.UserID = Users.ID WHERE ' +
- 'PackageNotifications.UserID != %s AND ' +
- 'PackageNotifications.PackageBaseID = %s', [uid, pkgbase_id])
+def get_recipients(conn, pkgbase_id, uid):
+ cur = conn.execute('SELECT DISTINCT Users.Email FROM Users ' +
+ 'INNER JOIN PackageNotifications ' +
+ 'ON PackageNotifications.UserID = Users.ID WHERE ' +
+ 'PackageNotifications.UserID != ? AND ' +
+ 'PackageNotifications.PackageBaseID = ?',
+ [uid, pkgbase_id])
return [row[0] for row in cur.fetchall()]
-def get_comment_recipients(cur, pkgbase_id, uid):
- cur.execute('SELECT DISTINCT Users.Email FROM Users ' +
- 'INNER JOIN PackageNotifications ' +
- 'ON PackageNotifications.UserID = Users.ID WHERE ' +
- 'Users.CommentNotify = 1 AND ' +
- 'PackageNotifications.UserID != %s AND ' +
- 'PackageNotifications.PackageBaseID = %s', [uid, pkgbase_id])
+def get_comment_recipients(conn, pkgbase_id, uid):
+ cur = conn.execute('SELECT DISTINCT Users.Email FROM Users ' +
+ 'INNER JOIN PackageNotifications ' +
+ 'ON PackageNotifications.UserID = Users.ID WHERE ' +
+ 'Users.CommentNotify = 1 AND ' +
+ 'PackageNotifications.UserID != ? AND ' +
+ 'PackageNotifications.PackageBaseID = ?',
+ [uid, pkgbase_id])
return [row[0] for row in cur.fetchall()]
-def get_update_recipients(cur, pkgbase_id, uid):
- cur.execute('SELECT DISTINCT Users.Email FROM Users ' +
- 'INNER JOIN PackageNotifications ' +
- 'ON PackageNotifications.UserID = Users.ID WHERE ' +
- 'Users.UpdateNotify = 1 AND ' +
- 'PackageNotifications.UserID != %s AND ' +
- 'PackageNotifications.PackageBaseID = %s', [uid, pkgbase_id])
+def get_update_recipients(conn, pkgbase_id, uid):
+ cur = conn.execute('SELECT DISTINCT Users.Email FROM Users ' +
+ 'INNER JOIN PackageNotifications ' +
+ 'ON PackageNotifications.UserID = Users.ID WHERE ' +
+ 'Users.UpdateNotify = 1 AND ' +
+ 'PackageNotifications.UserID != ? AND ' +
+ 'PackageNotifications.PackageBaseID = ?',
+ [uid, pkgbase_id])
return [row[0] for row in cur.fetchall()]
-def get_ownership_recipients(cur, pkgbase_id, uid):
- cur.execute('SELECT DISTINCT Users.Email FROM Users ' +
- 'INNER JOIN PackageNotifications ' +
- 'ON PackageNotifications.UserID = Users.ID WHERE ' +
- 'Users.OwnershipNotify = 1 AND ' +
- 'PackageNotifications.UserID != %s AND ' +
- 'PackageNotifications.PackageBaseID = %s', [uid, pkgbase_id])
+def get_ownership_recipients(conn, pkgbase_id, uid):
+ cur = conn.execute('SELECT DISTINCT Users.Email FROM Users ' +
+ 'INNER JOIN PackageNotifications ' +
+ 'ON PackageNotifications.UserID = Users.ID WHERE ' +
+ 'Users.OwnershipNotify = 1 AND ' +
+ 'PackageNotifications.UserID != ? AND ' +
+ 'PackageNotifications.PackageBaseID = ?',
+ [uid, pkgbase_id])
return [row[0] for row in cur.fetchall()]
-def get_request_recipients(cur, reqid):
- cur.execute('SELECT DISTINCT Users.Email FROM PackageRequests ' +
- 'INNER JOIN PackageBases ' +
- 'ON PackageBases.ID = PackageRequests.PackageBaseID ' +
- 'INNER JOIN Users ' +
- 'ON Users.ID = PackageRequests.UsersID ' +
- 'OR Users.ID = PackageBases.MaintainerUID ' +
- 'WHERE PackageRequests.ID = %s', [reqid])
+def get_request_recipients(conn, reqid):
+ cur = conn.execute('SELECT DISTINCT Users.Email FROM PackageRequests ' +
+ 'INNER JOIN PackageBases ' +
+ 'ON PackageBases.ID = PackageRequests.PackageBaseID ' +
+ 'INNER JOIN Users ' +
+ 'ON Users.ID = PackageRequests.UsersID ' +
+ 'OR Users.ID = PackageBases.MaintainerUID ' +
+ 'WHERE PackageRequests.ID = ?', [reqid])
return [row[0] for row in cur.fetchall()]
-def get_tu_vote_reminder_recipients(cur, vote_id):
- cur.execute('SELECT Users.Email FROM Users WHERE AccountTypeID = 2 ' +
- 'EXCEPT SELECT Users.Email FROM Users ' +
- 'INNER JOIN TU_Votes ' +
- 'ON TU_Votes.UserID = Users.ID ' +
- 'WHERE TU_Votes.VoteID = %s', [vote_id])
+def get_tu_vote_reminder_recipients(conn, vote_id):
+ cur = conn.execute('SELECT Users.Email FROM Users ' +
+ 'WHERE AccountTypeID = 2 ' +
+ 'EXCEPT SELECT Users.Email FROM Users ' +
+ 'INNER JOIN TU_Votes ' +
+ 'ON TU_Votes.UserID = Users.ID ' +
+ 'WHERE TU_Votes.VoteID = ?', [vote_id])
return [row[0] for row in cur.fetchall()]
-def get_comment(cur, comment_id):
- cur.execute('SELECT Comments FROM PackageComments WHERE ID = %s',
- [comment_id])
+def get_comment(conn, comment_id):
+ cur = conn.execute('SELECT Comments FROM PackageComments WHERE ID = ?',
+ [comment_id])
return cur.fetchone()[0]
-def get_flagger_comment(cur, pkgbase_id):
- cur.execute('SELECT FlaggerComment FROM PackageBases WHERE ID = %s',
- [pkgbase_id])
+def get_flagger_comment(conn, pkgbase_id):
+ cur = conn.execute('SELECT FlaggerComment FROM PackageBases WHERE ID = ?',
+ [pkgbase_id])
return cur.fetchone()[0]
-def get_request_comment(cur, reqid):
- cur.execute('SELECT Comments FROM PackageRequests WHERE ID = %s', [reqid])
+def get_request_comment(conn, reqid):
+ cur = conn.execute('SELECT Comments FROM PackageRequests WHERE ID = ?',
+ [reqid])
return cur.fetchone()[0]
-def get_request_closure_comment(cur, reqid):
- cur.execute('SELECT ClosureComment FROM PackageRequests WHERE ID = %s',
- [reqid])
+def get_request_closure_comment(conn, reqid):
+ cur = conn.execute('SELECT ClosureComment FROM PackageRequests ' +
+ 'WHERE ID = ?', [reqid])
return cur.fetchone()[0]
-def send_resetkey(cur, uid):
- cur.execute('SELECT UserName, Email, ResetKey FROM Users WHERE ID = %s',
- [uid])
+def send_resetkey(conn, uid):
+ cur = conn.execute('SELECT UserName, Email, ResetKey FROM Users ' +
+ 'WHERE ID = ?', [uid])
username, to, resetkey = cur.fetchone()
subject = 'AUR Password Reset'
@@ -186,9 +184,9 @@ def send_resetkey(cur, uid):
send_notification([to], subject, body, refs)
-def welcome(cur, uid):
- cur.execute('SELECT UserName, Email, ResetKey FROM Users WHERE ID = %s',
- [uid])
+def welcome(conn, uid):
+ cur = conn.execute('SELECT UserName, Email, ResetKey FROM Users ' +
+ 'WHERE ID = ?', [uid])
username, to, resetkey = cur.fetchone()
subject = 'Welcome to the Arch User Repository'
@@ -201,11 +199,11 @@ def welcome(cur, uid):
send_notification([to], subject, body, refs)
-def comment(cur, uid, pkgbase_id, comment_id):
- user = username_from_id(cur, uid)
- pkgbase = pkgbase_from_id(cur, pkgbase_id)
- to = get_comment_recipients(cur, pkgbase_id, uid)
- text = get_comment(cur, comment_id)
+def comment(conn, uid, pkgbase_id, comment_id):
+ user = username_from_id(conn, uid)
+ pkgbase = pkgbase_from_id(conn, pkgbase_id)
+ to = get_comment_recipients(conn, pkgbase_id, uid)
+ text = get_comment(conn, comment_id)
user_uri = aur_location + '/account/' + user + '/'
pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/'
@@ -224,10 +222,10 @@ def comment(cur, uid, pkgbase_id, comment_id):
send_notification(to, subject, body, refs, headers)
-def update(cur, uid, pkgbase_id):
- user = username_from_id(cur, uid)
- pkgbase = pkgbase_from_id(cur, pkgbase_id)
- to = get_update_recipients(cur, pkgbase_id, uid)
+def update(conn, uid, pkgbase_id):
+ user = username_from_id(conn, uid)
+ pkgbase = pkgbase_from_id(conn, pkgbase_id)
+ to = get_update_recipients(conn, pkgbase_id, uid)
user_uri = aur_location + '/account/' + user + '/'
pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/'
@@ -246,11 +244,11 @@ def update(cur, uid, pkgbase_id):
send_notification(to, subject, body, refs, headers)
-def flag(cur, uid, pkgbase_id):
- user = username_from_id(cur, uid)
- pkgbase = pkgbase_from_id(cur, pkgbase_id)
- to = [get_maintainer_email(cur, pkgbase_id)]
- text = get_flagger_comment(cur, pkgbase_id)
+def flag(conn, uid, pkgbase_id):
+ user = username_from_id(conn, uid)
+ pkgbase = pkgbase_from_id(conn, pkgbase_id)
+ to = [get_maintainer_email(conn, pkgbase_id)]
+ text = get_flagger_comment(conn, pkgbase_id)
user_uri = aur_location + '/account/' + user + '/'
pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/'
@@ -265,10 +263,10 @@ def flag(cur, uid, pkgbase_id):
send_notification(to, subject, body, refs)
-def adopt(cur, pkgbase_id, uid):
- user = username_from_id(cur, uid)
- pkgbase = pkgbase_from_id(cur, pkgbase_id)
- to = get_ownership_recipients(cur, pkgbase_id, uid)
+def adopt(conn, pkgbase_id, uid):
+ user = username_from_id(conn, uid)
+ pkgbase = pkgbase_from_id(conn, pkgbase_id)
+ to = get_ownership_recipients(conn, pkgbase_id, uid)
user_uri = aur_location + '/account/' + user + '/'
pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/'
@@ -281,10 +279,10 @@ def adopt(cur, pkgbase_id, uid):
send_notification(to, subject, body, refs)
-def disown(cur, pkgbase_id, uid):
- user = username_from_id(cur, uid)
- pkgbase = pkgbase_from_id(cur, pkgbase_id)
- to = get_ownership_recipients(cur, pkgbase_id, uid)
+def disown(conn, pkgbase_id, uid):
+ user = username_from_id(conn, uid)
+ pkgbase = pkgbase_from_id(conn, pkgbase_id)
+ to = get_ownership_recipients(conn, pkgbase_id, uid)
user_uri = aur_location + '/account/' + user + '/'
pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/'
@@ -297,9 +295,9 @@ def disown(cur, pkgbase_id, uid):
send_notification(to, subject, body, refs)
-def comaintainer_add(cur, pkgbase_id, uid):
- pkgbase = pkgbase_from_id(cur, pkgbase_id)
- to = [get_user_email(cur, uid)]
+def comaintainer_add(conn, pkgbase_id, uid):
+ pkgbase = pkgbase_from_id(conn, pkgbase_id)
+ to = [get_user_email(conn, uid)]
pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/'
@@ -310,9 +308,9 @@ def comaintainer_add(cur, pkgbase_id, uid):
send_notification(to, subject, body, refs)
-def comaintainer_remove(cur, pkgbase_id, uid):
- pkgbase = pkgbase_from_id(cur, pkgbase_id)
- to = [get_user_email(cur, uid)]
+def comaintainer_remove(conn, pkgbase_id, uid):
+ pkgbase = pkgbase_from_id(conn, pkgbase_id)
+ to = [get_user_email(conn, uid)]
pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/'
@@ -324,12 +322,12 @@ def comaintainer_remove(cur, pkgbase_id, uid):
send_notification(to, subject, body, refs)
-def delete(cur, uid, old_pkgbase_id, new_pkgbase_id=None):
- user = username_from_id(cur, uid)
- old_pkgbase = pkgbase_from_id(cur, old_pkgbase_id)
+def delete(conn, uid, old_pkgbase_id, new_pkgbase_id=None):
+ user = username_from_id(conn, uid)
+ old_pkgbase = pkgbase_from_id(conn, old_pkgbase_id)
if new_pkgbase_id:
- new_pkgbase = pkgbase_from_id(cur, new_pkgbase_id)
- to = get_recipients(cur, old_pkgbase_id, uid)
+ new_pkgbase = pkgbase_from_id(conn, new_pkgbase_id)
+ to = get_recipients(conn, old_pkgbase_id, uid)
user_uri = aur_location + '/account/' + user + '/'
pkgbase_uri = aur_location + '/pkgbase/' + old_pkgbase + '/'
@@ -354,12 +352,12 @@ def delete(cur, uid, old_pkgbase_id, new_pkgbase_id=None):
send_notification(to, subject, body, refs)
-def request_open(cur, uid, reqid, reqtype, pkgbase_id, merge_into=None):
- user = username_from_id(cur, uid)
- pkgbase = pkgbase_from_id(cur, pkgbase_id)
+def request_open(conn, uid, reqid, reqtype, pkgbase_id, merge_into=None):
+ user = username_from_id(conn, uid)
+ pkgbase = pkgbase_from_id(conn, pkgbase_id)
to = [aur_request_ml]
- cc = get_request_recipients(cur, reqid)
- text = get_request_comment(cur, reqid)
+ cc = get_request_recipients(conn, reqid)
+ text = get_request_comment(conn, reqid)
user_uri = aur_location + '/account/' + user + '/'
pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/'
@@ -388,14 +386,14 @@ def request_open(cur, uid, reqid, reqtype, pkgbase_id, merge_into=None):
send_notification(to, subject, body, refs, headers)
-def request_close(cur, uid, reqid, reason):
+def request_close(conn, uid, reqid, reason):
to = [aur_request_ml]
- cc = get_request_recipients(cur, reqid)
- text = get_request_closure_comment(cur, reqid)
+ cc = get_request_recipients(conn, reqid)
+ text = get_request_closure_comment(conn, reqid)
subject = '[PRQ#%d] Request %s' % (int(reqid), reason.title())
if int(uid):
- user = username_from_id(cur, uid)
+ user = username_from_id(conn, uid)
user_uri = aur_location + '/account/' + user + '/'
body = 'Request #%d has been %s by %s [1]' % (int(reqid), reason, user)
refs = '[1] ' + user_uri
@@ -414,8 +412,8 @@ def request_close(cur, uid, reqid, reason):
send_notification(to, subject, body, refs, headers)
-def tu_vote_reminder(cur, vote_id):
- to = get_tu_vote_reminder_recipients(cur, vote_id)
+def tu_vote_reminder(conn, vote_id):
+ to = get_tu_vote_reminder_recipients(conn, vote_id)
vote_uri = aur_location + '/tu/?id=' + vote_id
@@ -445,15 +443,12 @@ def main():
'tu-vote-reminder': tu_vote_reminder,
}
- 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()
+ conn = aurweb.db.Connection()
- action_map[action](cur, *sys.argv[2:])
+ action_map[action](conn, *sys.argv[2:])
- db.commit()
- db.close()
+ conn.commit()
+ conn.close()
if __name__ == '__main__':
diff --git a/scripts/pkgmaint.py b/scripts/pkgmaint.py
index 346b046f..d0f8fe70 100755
--- a/scripts/pkgmaint.py
+++ b/scripts/pkgmaint.py
@@ -1,31 +1,17 @@
#!/usr/bin/python3
-import configparser
-import mysql.connector
-import os
-
-config = configparser.RawConfigParser()
-config.read(os.path.dirname(os.path.realpath(__file__)) + "/../conf/config")
-
-aur_db_host = config.get('database', 'host')
-aur_db_name = config.get('database', 'name')
-aur_db_user = config.get('database', 'user')
-aur_db_pass = config.get('database', 'password')
-aur_db_socket = config.get('database', 'socket')
+import aurweb.db
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()
+ conn = aurweb.db.Connection()
- cur.execute("DELETE FROM PackageBases WHERE " +
- "UNIX_TIMESTAMP() - SubmittedTS > 86400 " +
- "AND PackagerUID IS NULL")
+ conn.execute("DELETE FROM PackageBases WHERE " +
+ "UNIX_TIMESTAMP() - SubmittedTS > 86400 " +
+ "AND PackagerUID IS NULL")
- db.commit()
- db.close()
+ conn.commit()
+ conn.close()
if __name__ == '__main__':
diff --git a/scripts/popupdate.py b/scripts/popupdate.py
index 26d83790..f5e09d97 100755
--- a/scripts/popupdate.py
+++ b/scripts/popupdate.py
@@ -1,36 +1,22 @@
#!/usr/bin/python3
-import configparser
-import mysql.connector
-import os
+import aurweb.db
-config = configparser.RawConfigParser()
-config.read(os.path.dirname(os.path.realpath(__file__)) + "/../conf/config")
-aur_db_host = config.get('database', 'host')
-aur_db_name = config.get('database', 'name')
-aur_db_user = config.get('database', 'user')
-aur_db_pass = config.get('database', 'password')
-aur_db_socket = config.get('database', 'socket')
+def main():
+ conn = aurweb.db.Connection()
+ conn.execute("UPDATE PackageBases SET NumVotes = (" +
+ "SELECT COUNT(*) FROM PackageVotes " +
+ "WHERE PackageVotes.PackageBaseID = PackageBases.ID)")
-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.execute("UPDATE PackageBases SET NumVotes = (" +
- "SELECT COUNT(*) FROM PackageVotes " +
- "WHERE PackageVotes.PackageBaseID = PackageBases.ID)")
-
- 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()
+ conn.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)")
+
+ conn.commit()
+ conn.close()
if __name__ == '__main__':
diff --git a/scripts/tuvotereminder.py b/scripts/tuvotereminder.py
index dc16397e..a053608d 100755
--- a/scripts/tuvotereminder.py
+++ b/scripts/tuvotereminder.py
@@ -1,34 +1,24 @@
#!/usr/bin/python3
-import configparser
-import mysql.connector
-import os
import subprocess
import time
-config = configparser.RawConfigParser()
-config.read(os.path.dirname(os.path.realpath(__file__)) + "/../conf/config")
+import aurweb.config
+import aurweb.db
-aur_db_host = config.get('database', 'host')
-aur_db_name = config.get('database', 'name')
-aur_db_user = config.get('database', 'user')
-aur_db_pass = config.get('database', 'password')
-aur_db_socket = config.get('database', 'socket')
-notify_cmd = config.get('notifications', 'notify-cmd')
+notify_cmd = aurweb.config.get('notifications', 'notify-cmd')
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()
+ conn = aurweb.db.Connection()
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",
- [filter_from, filter_to])
+ cur = conn.execute("SELECT ID FROM TU_VoteInfo " +
+ "WHERE End >= ? AND End <= ?",
+ [filter_from, filter_to])
for vote_id in [row[0] for row in cur.fetchall()]:
subprocess.Popen((notify_cmd, 'tu-vote-reminder', str(vote_id)))