diff options
author | Lukas Fleischer <lfleischer@archlinux.org> | 2016-02-06 16:23:01 +0100 |
---|---|---|
committer | Lukas Fleischer <lfleischer@archlinux.org> | 2016-02-06 16:23:01 +0100 |
commit | f8b3cb97e54f9de73c6c2fca0cfade7e1657f1e4 (patch) | |
tree | 6fd3b1e9fd15d54e5fb0f2855000655231920dce /git-interface | |
parent | aaa138cd38d919072fd56d58b1eb32d5e3bc1e80 (diff) | |
download | aurweb-f8b3cb97e54f9de73c6c2fca0cfade7e1657f1e4.tar.xz |
Fix issues reported by pyflakes
Fix several style issues and remove unneeded imports/assignments.
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'git-interface')
-rwxr-xr-x | git-interface/git-auth.py | 2 | ||||
-rwxr-xr-x | git-interface/git-serve.py | 11 | ||||
-rwxr-xr-x | git-interface/git-update.py | 37 |
3 files changed, 36 insertions, 14 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): |