summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgit-interface/git-auth.py2
-rwxr-xr-xgit-interface/git-serve.py11
-rwxr-xr-xgit-interface/git-update.py37
-rwxr-xr-xscripts/notify.py34
4 files changed, 63 insertions, 21 deletions
diff --git a/git-interface/git-auth.py b/git-interface/git-auth.py
index c7de777..83bd20c 100755
--- a/git-interface/git-auth.py
+++ b/git-interface/git-auth.py
@@ -39,7 +39,7 @@ ssh_opts = config.get('auth', 'ssh-options')
keytype = sys.argv[1]
keytext = sys.argv[2]
-if not keytype in valid_keytypes:
+if keytype not in valid_keytypes:
exit(1)
db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
diff --git a/git-interface/git-serve.py b/git-interface/git-serve.py
index 62410e9..8581590 100755
--- a/git-interface/git-serve.py
+++ b/git-interface/git-serve.py
@@ -25,6 +25,7 @@ ssh_cmdline = config.get('serve', 'ssh-cmdline')
enable_maintenance = config.getboolean('options', 'enable-maintenance')
maintenance_exc = config.get('options', 'maintenance-exceptions').split()
+
def pkgbase_from_name(pkgbase):
db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
passwd=aur_db_pass, db=aur_db_name,
@@ -36,9 +37,11 @@ def pkgbase_from_name(pkgbase):
row = cur.fetchone()
return row[0] if row else None
+
def pkgbase_exists(pkgbase):
return pkgbase_from_name(pkgbase) is not None
+
def list_repos(user):
db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
passwd=aur_db_pass, db=aur_db_name,
@@ -56,6 +59,7 @@ def list_repos(user):
print((' ' if row[1] else '*') + row[0])
db.close()
+
def create_pkgbase(pkgbase, user):
if not re.match(repo_regex, pkgbase):
die('{:s}: invalid repository name: {:s}'.format(action, pkgbase))
@@ -83,6 +87,7 @@ def create_pkgbase(pkgbase, user):
db.commit()
db.close()
+
def pkgbase_config_keywords(pkgbase, keywords):
pkgbase_id = pkgbase_from_name(pkgbase)
if not pkgbase_id:
@@ -102,6 +107,7 @@ def pkgbase_config_keywords(pkgbase, keywords):
db.commit()
db.close()
+
def check_permissions(pkgbase, user):
db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
passwd=aur_db_pass, db=aur_db_name,
@@ -120,13 +126,16 @@ def check_permissions(pkgbase, user):
"WHERE Name = %s AND Username = %s", [pkgbase, user])
return cur.fetchone()[0] > 0
+
def die(msg):
sys.stderr.write("{:s}\n".format(msg))
exit(1)
+
def die_with_help(msg):
die(msg + "\nTry `{:s} help` for a list of commands.".format(ssh_cmdline))
+
user = os.environ.get("AUR_USER")
cmd = os.environ.get("SSH_ORIGINAL_COMMAND")
if not cmd:
@@ -136,7 +145,7 @@ action = cmdargv[0]
if enable_maintenance:
remote_addr = os.environ["SSH_CLIENT"].split(" ")[0]
- if not remote_addr in maintenance_exc:
+ if remote_addr not in maintenance_exc:
die("The AUR is down due to maintenance. We will be back soon.")
if action == 'git-upload-pack' or action == 'git-receive-pack':
diff --git a/git-interface/git-update.py b/git-interface/git-update.py
index 6e09517..5efc9b1 100755
--- a/git-interface/git-update.py
+++ b/git-interface/git-update.py
@@ -1,6 +1,5 @@
#!/usr/bin/python3
-from copy import copy, deepcopy
import configparser
import mysql.connector
import os
@@ -22,6 +21,7 @@ aur_db_socket = config.get('database', 'socket')
repo_path = config.get('serve', 'repo-path')
repo_regex = config.get('serve', 'repo-regex')
+
def extract_arch_fields(pkginfo, field):
values = []
@@ -36,6 +36,7 @@ def extract_arch_fields(pkginfo, field):
return values
+
def parse_dep(depstring):
dep, _, desc = depstring.partition(': ')
depname = re.sub(r'(<|=|>).*', '', dep)
@@ -46,6 +47,7 @@ def parse_dep(depstring):
else:
return (depname, depcond)
+
def save_srcinfo(srcinfo, db, cur, user):
# Obtain package base ID and previous maintainer.
pkgbase = srcinfo._pkgbase['pkgname']
@@ -72,13 +74,14 @@ def save_srcinfo(srcinfo, db, cur, user):
pkginfo = srcinfo.GetMergedPackage(pkgname)
if 'epoch' in pkginfo and int(pkginfo['epoch']) > 0:
- ver = '{:d}:{:s}-{:s}'.format(int(pkginfo['epoch']), pkginfo['pkgver'],
+ ver = '{:d}:{:s}-{:s}'.format(int(pkginfo['epoch']),
+ pkginfo['pkgver'],
pkginfo['pkgrel'])
else:
ver = '{:s}-{:s}'.format(pkginfo['pkgver'], pkginfo['pkgrel'])
for field in ('pkgdesc', 'url'):
- if not field in pkginfo:
+ if field not in pkginfo:
pkginfo[field] = None
# Create a new package.
@@ -165,13 +168,16 @@ def save_srcinfo(srcinfo, db, cur, user):
db.commit()
+
def die(msg):
sys.stderr.write("error: {:s}\n".format(msg))
exit(1)
+
def warn(msg):
sys.stderr.write("warning: {:s}\n".format(msg))
+
def die_commit(msg, commit):
sys.stderr.write("error: The following error " +
"occurred when parsing commit\n")
@@ -179,6 +185,7 @@ def die_commit(msg, commit):
sys.stderr.write("error: {:s}\n".format(msg))
exit(1)
+
repo = pygit2.Repository(repo_path)
user = os.environ.get("AUR_USER")
@@ -207,7 +214,7 @@ cur = db.cursor()
if sha1_old != "0000000000000000000000000000000000000000":
walker = repo.walk(sha1_old, pygit2.GIT_SORT_TOPOLOGICAL)
walker.hide(sha1_new)
- if next(walker, None) != None:
+ if next(walker, None) is not None:
cur.execute("SELECT AccountTypeID FROM Users WHERE UserName = %s ",
[user])
if cur.fetchone()[0] == 1:
@@ -221,7 +228,7 @@ if sha1_old != "0000000000000000000000000000000000000000":
# Validate all new commits.
for commit in walker:
for fname in ('.SRCINFO', 'PKGBUILD'):
- if not fname in commit.tree:
+ if fname not in commit.tree:
die_commit("missing {:s}".format(fname), str(commit.id))
for treeobj in commit.tree:
@@ -232,7 +239,8 @@ for commit in walker:
str(commit.id))
if not isinstance(blob, pygit2.Blob):
- die_commit("not a blob object: {:s}".format(treeobj), str(commit.id))
+ die_commit("not a blob object: {:s}".format(treeobj),
+ str(commit.id))
if blob.size > 250000:
die_commit("maximum blob size (250kB) exceeded", str(commit.id))
@@ -252,17 +260,20 @@ for commit in walker:
srcinfo_pkgbase = srcinfo._pkgbase['pkgname']
if not re.match(repo_regex, srcinfo_pkgbase):
- die_commit('invalid pkgbase: {:s}'.format(srcinfo_pkgbase), str(commit.id))
+ die_commit('invalid pkgbase: {:s}'.format(srcinfo_pkgbase),
+ str(commit.id))
for pkgname in srcinfo.GetPackageNames():
pkginfo = srcinfo.GetMergedPackage(pkgname)
for field in ('pkgver', 'pkgrel', 'pkgname'):
- if not field in pkginfo:
- die_commit('missing mandatory field: {:s}'.format(field), str(commit.id))
+ if field not in pkginfo:
+ die_commit('missing mandatory field: {:s}'.format(field),
+ str(commit.id))
if 'epoch' in pkginfo and not pkginfo['epoch'].isdigit():
- die_commit('invalid epoch: {:s}'.format(pkginfo['epoch']), str(commit.id))
+ die_commit('invalid epoch: {:s}'.format(pkginfo['epoch']),
+ str(commit.id))
if not re.match(r'[a-z0-9][a-z0-9\.+_-]*$', pkginfo['pkgname']):
die_commit('invalid package name: {:s}'.format(pkginfo['pkgname']),
@@ -282,8 +293,10 @@ for commit in walker:
fname = field['value']
if "://" in fname or "lp:" in fname:
continue
- if not fname in commit.tree:
- die_commit('missing source file: {:s}'.format(fname), str(commit.id))
+ if fname not in commit.tree:
+ die_commit('missing source file: {:s}'.format(fname),
+ str(commit.id))
+
# Display a warning if .SRCINFO is unchanged.
if sha1_old not in ("0000000000000000000000000000000000000000", sha1_new):
diff --git a/scripts/notify.py b/scripts/notify.py
index b5bf518..7b10efb 100755
--- a/scripts/notify.py
+++ b/scripts/notify.py
@@ -4,7 +4,6 @@ import configparser
import email.mime.text
import mysql.connector
import os
-import smtplib
import subprocess
import sys
import textwrap
@@ -29,12 +28,15 @@ reply_to = config.get('notifications', 'reply-to')
def headers_cc(cclist):
return {'Cc': str.join(', ', cclist)}
+
def headers_msgid(thread_id):
return {'Message-ID': thread_id}
+
def headers_reply(thread_id):
return {'In-Reply-To': thread_id, 'References': thread_id}
+
def send_notification(to, subject, body, refs, headers={}):
wrapped = ''
for line in body.splitlines():
@@ -54,23 +56,28 @@ def send_notification(to, subject, body, refs, headers={}):
p = subprocess.Popen([sendmail, '-t', '-oi'], stdin=subprocess.PIPE)
p.communicate(msg.as_bytes())
+
def username_from_id(cur, uid):
cur.execute('SELECT UserName FROM Users WHERE ID = %s', [uid])
return cur.fetchone()[0]
+
def pkgbase_from_id(cur, pkgbase_id):
cur.execute('SELECT Name FROM PackageBases WHERE ID = %s', [pkgbase_id])
return cur.fetchone()[0]
+
def pkgbase_from_pkgreq(cur, reqid):
cur.execute('SELECT PackageBaseID FROM PackageRequests WHERE ID = %s',
[reqid])
return cur.fetchone()[0]
+
def get_user_email(cur, uid):
cur.execute('SELECT Email FROM Users WHERE ID = %s', [uid])
return cur.fetchone()[0]
+
def get_maintainer_email(cur, pkgbase_id):
cur.execute('SELECT Users.Email FROM Users ' +
'INNER JOIN PackageBases ' +
@@ -78,6 +85,7 @@ def get_maintainer_email(cur, pkgbase_id):
'PackageBases.ID = %s', [pkgbase_id])
return cur.fetchone()[0]
+
def get_recipients(cur, pkgbase_id, uid):
cur.execute('SELECT DISTINCT Users.Email FROM Users ' +
'INNER JOIN CommentNotify ' +
@@ -86,6 +94,7 @@ def get_recipients(cur, pkgbase_id, uid):
'CommentNotify.PackageBaseID = %s', [uid, pkgbase_id])
return [row[0] for row in cur.fetchall()]
+
def get_request_recipients(cur, pkgbase_id, uid):
cur.execute('SELECT DISTINCT Users.Email FROM Users ' +
'INNER JOIN PackageBases ' +
@@ -93,25 +102,30 @@ def get_request_recipients(cur, pkgbase_id, uid):
'Users.ID = %s OR PackageBases.ID = %s', [uid, pkgbase_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])
return cur.fetchone()[0]
+
def get_flagger_comment(cur, pkgbase_id):
cur.execute('SELECT FlaggerComment FROM PackageBases WHERE ID = %s',
[pkgbase_id])
return cur.fetchone()[0]
+
def get_request_comment(cur, reqid):
cur.execute('SELECT Comments FROM PackageRequests WHERE ID = %s', [reqid])
return cur.fetchone()[0]
+
def get_request_closure_comment(cur, reqid):
cur.execute('SELECT ClosureComment FROM PackageRequests WHERE ID = %s',
[reqid])
return cur.fetchone()[0]
+
def send_resetkey(cur, uid):
cur.execute('SELECT UserName, Email, ResetKey FROM Users WHERE ID = %s',
[uid])
@@ -126,6 +140,7 @@ 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])
@@ -140,14 +155,13 @@ 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_recipients(cur, pkgbase_id, uid)
text = get_comment(cur, comment_id)
- uri = aur_location + '/pkgbase/' + pkgbase + '/'
-
user_uri = aur_location + '/account/' + user + '/'
pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/'
@@ -164,6 +178,7 @@ def comment(cur, uid, pkgbase_id, comment_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)
@@ -182,6 +197,7 @@ def flag(cur, uid, pkgbase_id):
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)]
@@ -194,6 +210,7 @@ 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)]
@@ -201,12 +218,13 @@ def comaintainer_remove(cur, pkgbase_id, uid):
pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/'
subject = 'AUR Co-Maintainer Notification for %s' % (pkgbase)
- body = 'You were removed from the co-maintainer list of %s [1].' % \
- (pkgbase)
+ body = ('You were removed from the co-maintainer list of %s [1].' %
+ (pkgbase))
refs = '[1] ' + pkgbase_uri + '\n'
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)
@@ -215,7 +233,7 @@ def delete(cur, uid, old_pkgbase_id, new_pkgbase_id=None):
to = get_recipients(cur, old_pkgbase_id, uid)
user_uri = aur_location + '/account/' + user + '/'
- pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/'
+ pkgbase_uri = aur_location + '/pkgbase/' + old_pkgbase + '/'
subject = 'AUR Package deleted: %s' % (old_pkgbase)
if new_pkgbase_id:
@@ -236,6 +254,7 @@ 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)
@@ -268,12 +287,13 @@ 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):
user = username_from_id(cur, uid)
pkgbase_id = pkgbase_from_pkgreq(cur, reqid)
to = [aur_request_ml]
cc = get_request_recipients(cur, pkgbase_id, uid)
- text = get_request_closure_comment(cur, reqid);
+ text = get_request_closure_comment(cur, reqid)
user_uri = aur_location + '/account/' + user + '/'