Commit ae2907a5 authored by Johannes Löthberg's avatar Johannes Löthberg Committed by Lukas Fleischer
Browse files

git: Use .format everywhere instead of %



% formatting is deprecated, and .format should be used instead.

Signed-off-by: Johannes Löthberg's avatarJohannes Löthberg <johannes@kyriasis.com>
Signed-off-by: Lukas Fleischer's avatarLukas Fleischer <lfleischer@archlinux.org>
parent 226376fc
...@@ -84,7 +84,7 @@ class AurInfo(object): ...@@ -84,7 +84,7 @@ class AurInfo(object):
class StderrECatcher(object): class StderrECatcher(object):
def Catch(self, lineno, error): def Catch(self, lineno, error):
print('ERROR[%d]: %s' % (lineno, error), file=sys.stderr) print('ERROR[{:d}]: {:s}'.format(lineno, error), file=sys.stderr)
class CollectionECatcher(object): class CollectionECatcher(object):
...@@ -126,8 +126,8 @@ def ParseAurinfoFromIterable(iterable, ecatcher=None): ...@@ -126,8 +126,8 @@ def ParseAurinfoFromIterable(iterable, ecatcher=None):
try: try:
key, value = map(str.strip, line.split('=', 1)) key, value = map(str.strip, line.split('=', 1))
except ValueError: except ValueError:
ecatcher.Catch(lineno, 'unexpected header format in section=%s' % ecatcher.Catch(lineno, 'unexpected header format in section={:s}'.format(
current_package['pkgname']) current_package['pkgname']))
continue continue
if key == 'pkgbase': if key == 'pkgbase':
...@@ -149,7 +149,7 @@ def ParseAurinfoFromIterable(iterable, ecatcher=None): ...@@ -149,7 +149,7 @@ def ParseAurinfoFromIterable(iterable, ecatcher=None):
key, value = map(str.strip, line.split('=', 1)) key, value = map(str.strip, line.split('=', 1))
except ValueError: except ValueError:
ecatcher.Catch(lineno, 'unexpected attribute format in ' ecatcher.Catch(lineno, 'unexpected attribute format in '
'section=%s' % current_package['pkgname']) 'section={:s}'.format(current_package['pkgname']))
if IsMultiValued(key): if IsMultiValued(key):
if not current_package.get(key): if not current_package.get(key):
...@@ -161,8 +161,8 @@ def ParseAurinfoFromIterable(iterable, ecatcher=None): ...@@ -161,8 +161,8 @@ def ParseAurinfoFromIterable(iterable, ecatcher=None):
current_package[key] = value current_package[key] = value
else: else:
ecatcher.Catch(lineno, 'overwriting attribute ' ecatcher.Catch(lineno, 'overwriting attribute '
'%s: %s -> %s' % (key, current_package[key], '{:s}: {:s} -> {:s}'.format(key,
value)) current_package[key], value))
return aurinfo return aurinfo
...@@ -177,7 +177,7 @@ def ValidateAurinfo(filename='.AURINFO'): ...@@ -177,7 +177,7 @@ def ValidateAurinfo(filename='.AURINFO'):
ParseAurinfo(filename, ecatcher) ParseAurinfo(filename, ecatcher)
errors = ecatcher.Errors() errors = ecatcher.Errors()
for error in errors: for error in errors:
print('error on line %d: %s' % error, file=sys.stderr) print('error on line {:d}: {:s}'.format(error), file=sys.stderr)
return not errors return not errors
...@@ -196,13 +196,13 @@ if __name__ == '__main__': ...@@ -196,13 +196,13 @@ if __name__ == '__main__':
if action == 'parse': if action == 'parse':
aurinfo = ParseAurinfo() aurinfo = ParseAurinfo()
for pkgname in aurinfo.GetPackageNames(): for pkgname in aurinfo.GetPackageNames():
print(">>> merged package: %s" % pkgname) print(">>> merged package: {:s}".format(pkgname))
pp.pprint(aurinfo.GetMergedPackage(pkgname)) pp.pprint(aurinfo.GetMergedPackage(pkgname))
print() print()
elif action == 'validate': elif action == 'validate':
sys.exit(not ValidateAurinfo(filename)) sys.exit(not ValidateAurinfo(filename))
else: else:
print('unknown action: %s' % action) print('unknown action: {:s}'.format(action))
sys.exit(1) sys.exit(1)
# vim: set et ts=4 sw=4: # vim: set et ts=4 sw=4:
...@@ -45,7 +45,7 @@ def list_repos(user): ...@@ -45,7 +45,7 @@ def list_repos(user):
cur.execute("SELECT ID FROM Users WHERE Username = %s ", [user]) cur.execute("SELECT ID FROM Users WHERE Username = %s ", [user])
userid = cur.fetchone()[0] userid = cur.fetchone()[0]
if userid == 0: if userid == 0:
die('%s: unknown user: %s' % (action, user)) die('{:s}: unknown user: {:s}'.format(action, user))
cur.execute("SELECT Name, PackagerUID FROM PackageBases " + cur.execute("SELECT Name, PackagerUID FROM PackageBases " +
"WHERE MaintainerUID = %s ", [userid]) "WHERE MaintainerUID = %s ", [userid])
...@@ -55,9 +55,9 @@ def list_repos(user): ...@@ -55,9 +55,9 @@ def list_repos(user):
def create_pkgbase(pkgbase, user): def create_pkgbase(pkgbase, user):
if not re.match(repo_regex, pkgbase): if not re.match(repo_regex, pkgbase):
die('%s: invalid repository name: %s' % (action, pkgbase)) die('{:s}: invalid repository name: {:s}'.format(action, pkgbase))
if pkgbase_exists(pkgbase): if pkgbase_exists(pkgbase):
die('%s: package base already exists: %s' % (action, pkgbase)) die('{:s}: package base already exists: {:s}'.format(action, pkgbase))
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, passwd=aur_db_pass, db=aur_db_name,
...@@ -67,7 +67,7 @@ def create_pkgbase(pkgbase, user): ...@@ -67,7 +67,7 @@ def create_pkgbase(pkgbase, user):
cur.execute("SELECT ID FROM Users WHERE Username = %s ", [user]) cur.execute("SELECT ID FROM Users WHERE Username = %s ", [user])
userid = cur.fetchone()[0] userid = cur.fetchone()[0]
if userid == 0: if userid == 0:
die('%s: unknown user: %s' % (action, user)) die('{:s}: unknown user: {:s}'.format(action, user))
cur.execute("INSERT INTO PackageBases (Name, SubmittedTS, ModifiedTS, " + cur.execute("INSERT INTO PackageBases (Name, SubmittedTS, ModifiedTS, " +
"SubmitterUID, MaintainerUID) VALUES (%s, UNIX_TIMESTAMP(), " + "SubmitterUID, MaintainerUID) VALUES (%s, UNIX_TIMESTAMP(), " +
...@@ -100,11 +100,11 @@ def check_permissions(pkgbase, user): ...@@ -100,11 +100,11 @@ def check_permissions(pkgbase, user):
return cur.fetchone()[0] > 0 return cur.fetchone()[0] > 0
def die(msg): def die(msg):
sys.stderr.write("%s\n" % (msg)) sys.stderr.write("{:s}\n".format(msg))
exit(1) exit(1)
def die_with_help(msg): def die_with_help(msg):
die(msg + "\nTry `%s help` for a list of commands." % (ssh_cmdline)) die(msg + "\nTry `{:s} help` for a list of commands.".format(ssh_cmdline))
user = sys.argv[1] user = sys.argv[1]
cmd = os.environ.get("SSH_ORIGINAL_COMMAND") cmd = os.environ.get("SSH_ORIGINAL_COMMAND")
...@@ -120,7 +120,7 @@ if enable_maintenance: ...@@ -120,7 +120,7 @@ if enable_maintenance:
if action == 'git-upload-pack' or action == 'git-receive-pack': if action == 'git-upload-pack' or action == 'git-receive-pack':
if len(cmdargv) < 2: if len(cmdargv) < 2:
die_with_help("%s: missing path" % (action)) die_with_help("{:s}: missing path".format(action))
path = cmdargv[1].rstrip('/') path = cmdargv[1].rstrip('/')
if not path.startswith('/'): if not path.startswith('/'):
...@@ -129,14 +129,14 @@ if action == 'git-upload-pack' or action == 'git-receive-pack': ...@@ -129,14 +129,14 @@ if action == 'git-upload-pack' or action == 'git-receive-pack':
path = path + '.git' path = path + '.git'
pkgbase = path[1:-4] pkgbase = path[1:-4]
if not re.match(repo_regex, pkgbase): if not re.match(repo_regex, pkgbase):
die('%s: invalid repository name: %s' % (action, pkgbase)) die('{:s}: invalid repository name: {:s}'.format(action, pkgbase))
if not pkgbase_exists(pkgbase): if not pkgbase_exists(pkgbase):
create_pkgbase(pkgbase, user) create_pkgbase(pkgbase, user)
if action == 'git-receive-pack': if action == 'git-receive-pack':
if not check_permissions(pkgbase, user): if not check_permissions(pkgbase, user):
die('%s: permission denied: %s' % (action, user)) die('{:s}: permission denied: {:s}'.format(action, user))
os.environ["AUR_USER"] = user os.environ["AUR_USER"] = user
os.environ["AUR_PKGBASE"] = pkgbase os.environ["AUR_PKGBASE"] = pkgbase
...@@ -145,13 +145,13 @@ if action == 'git-upload-pack' or action == 'git-receive-pack': ...@@ -145,13 +145,13 @@ if action == 'git-upload-pack' or action == 'git-receive-pack':
os.execl(git_shell_cmd, git_shell_cmd, '-c', cmd) os.execl(git_shell_cmd, git_shell_cmd, '-c', cmd)
elif action == 'list-repos': elif action == 'list-repos':
if len(cmdargv) > 1: if len(cmdargv) > 1:
die_with_help("%s: too many arguments" % (action)) die_with_help("{:s}: too many arguments".format(action))
list_repos(user) list_repos(user)
elif action == 'setup-repo': elif action == 'setup-repo':
if len(cmdargv) < 2: if len(cmdargv) < 2:
die_with_help("%s: missing repository name" % (action)) die_with_help("{:s}: missing repository name".format(action))
if len(cmdargv) > 2: if len(cmdargv) > 2:
die_with_help("%s: too many arguments" % (action)) die_with_help("{:s}: too many arguments".format(action))
create_pkgbase(cmdargv[1], user) create_pkgbase(cmdargv[1], user)
elif action == 'help': elif action == 'help':
die("Commands:\n" + die("Commands:\n" +
...@@ -161,4 +161,4 @@ elif action == 'help': ...@@ -161,4 +161,4 @@ elif action == 'help':
" git-receive-pack Internal command used with Git.\n" + " git-receive-pack Internal command used with Git.\n" +
" git-upload-pack Internal command used with Git.") " git-upload-pack Internal command used with Git.")
else: else:
die_with_help("invalid command: %s" % (action)) die_with_help("invalid command: {:s}".format(action))
...@@ -72,10 +72,10 @@ def save_srcinfo(srcinfo, db, cur, user): ...@@ -72,10 +72,10 @@ def save_srcinfo(srcinfo, db, cur, user):
pkginfo = srcinfo.GetMergedPackage(pkgname) pkginfo = srcinfo.GetMergedPackage(pkgname)
if 'epoch' in pkginfo and int(pkginfo['epoch']) > 0: if 'epoch' in pkginfo and int(pkginfo['epoch']) > 0:
ver = '%d:%s-%s' % (int(pkginfo['epoch']), pkginfo['pkgver'], ver = '{:d}:{:s}-{:s}'.format(int(pkginfo['epoch']), pkginfo['pkgver'],
pkginfo['pkgrel']) pkginfo['pkgrel'])
else: else:
ver = '%s-%s' % (pkginfo['pkgver'], pkginfo['pkgrel']) ver = '{:s}-{:s}'.format(pkginfo['pkgver'], pkginfo['pkgrel'])
for field in ('pkgdesc', 'url'): for field in ('pkgdesc', 'url'):
if not field in pkginfo: if not field in pkginfo:
...@@ -166,14 +166,14 @@ def save_srcinfo(srcinfo, db, cur, user): ...@@ -166,14 +166,14 @@ def save_srcinfo(srcinfo, db, cur, user):
db.commit() db.commit()
def die(msg): def die(msg):
sys.stderr.write("error: %s\n" % (msg)) sys.stderr.write("error: {:s}\n".format(msg))
exit(1) exit(1)
def die_commit(msg, commit): def die_commit(msg, commit):
sys.stderr.write("error: The following error " + sys.stderr.write("error: The following error " +
"occurred when parsing commit\n") "occurred when parsing commit\n")
sys.stderr.write("error: %s:\n" % (commit)) sys.stderr.write("error: {:s}:\n".format(commit))
sys.stderr.write("error: %s\n" % (msg)) sys.stderr.write("error: {:s}\n".format(msg))
exit(1) exit(1)
if len(sys.argv) != 4: if len(sys.argv) != 4:
...@@ -216,20 +216,20 @@ blacklist = [row[0] for row in cur.fetchall()] ...@@ -216,20 +216,20 @@ blacklist = [row[0] for row in cur.fetchall()]
for commit in walker: for commit in walker:
if not '.SRCINFO' in commit.tree: if not '.SRCINFO' in commit.tree:
die_commit("missing .SRCINFO", commit.id) die_commit("missing .SRCINFO", str(commit.id))
for treeobj in commit.tree: for treeobj in commit.tree:
blob = repo[treeobj.id] blob = repo[treeobj.id]
if isinstance(blob, pygit2.Tree): if isinstance(blob, pygit2.Tree):
die_commit("the repository must not contain subdirectories", die_commit("the repository must not contain subdirectories",
commit.id) str(commit.id))
if not isinstance(blob, pygit2.Blob): if not isinstance(blob, pygit2.Blob):
die_commit("not a blob object: %s" % (treeobj), commit.id) die_commit("not a blob object: {:s}".format(treeobj), str(commit.id))
if blob.size > 250000: if blob.size > 250000:
die_commit("maximum blob size (250kB) exceeded", commit.id) die_commit("maximum blob size (250kB) exceeded", str(commit.id))
srcinfo_raw = repo[commit.tree['.SRCINFO'].id].data.decode() srcinfo_raw = repo[commit.tree['.SRCINFO'].id].data.decode()
srcinfo_raw = srcinfo_raw.split('\n') srcinfo_raw = srcinfo_raw.split('\n')
...@@ -239,45 +239,45 @@ for commit in walker: ...@@ -239,45 +239,45 @@ for commit in walker:
if errors: if errors:
sys.stderr.write("error: The following errors occurred " sys.stderr.write("error: The following errors occurred "
"when parsing .SRCINFO in commit\n") "when parsing .SRCINFO in commit\n")
sys.stderr.write("error: %s:\n" % (commit.id)) sys.stderr.write("error: {:s}:\n".format(str(commit.id)))
for error in errors: for error in errors:
sys.stderr.write("error: line %d: %s\n" % error) sys.stderr.write("error: line {:d}: {:s}\n".format(error))
exit(1) exit(1)
srcinfo_pkgbase = srcinfo._pkgbase['pkgname'] srcinfo_pkgbase = srcinfo._pkgbase['pkgname']
if not re.match(repo_regex, srcinfo_pkgbase): if not re.match(repo_regex, srcinfo_pkgbase):
die_commit('invalid pkgbase: %s' % (srcinfo_pkgbase), commit.id) die_commit('invalid pkgbase: {:s}'.format(srcinfo_pkgbase), str(commit.id))
for pkgname in srcinfo.GetPackageNames(): for pkgname in srcinfo.GetPackageNames():
pkginfo = srcinfo.GetMergedPackage(pkgname) pkginfo = srcinfo.GetMergedPackage(pkgname)
for field in ('pkgver', 'pkgrel', 'pkgname'): for field in ('pkgver', 'pkgrel', 'pkgname'):
if not field in pkginfo: if not field in pkginfo:
die_commit('missing mandatory field: %s' % (field), commit.id) die_commit('missing mandatory field: {:s}'.format(field), str(commit.id))
if 'epoch' in pkginfo and not pkginfo['epoch'].isdigit(): if 'epoch' in pkginfo and not pkginfo['epoch'].isdigit():
die_commit('invalid epoch: %s' % (pkginfo['epoch']), 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']): if not re.match(r'[a-z0-9][a-z0-9\.+_-]*$', pkginfo['pkgname']):
die_commit('invalid package name: %s' % (pkginfo['pkgname']), die_commit('invalid package name: {:s}'.format(pkginfo['pkgname']),
commit.id) str(commit.id))
for field in ('pkgname', 'pkgdesc', 'url'): for field in ('pkgname', 'pkgdesc', 'url'):
if field in pkginfo and len(pkginfo[field]) > 255: if field in pkginfo and len(pkginfo[field]) > 255:
die_commit('%s field too long: %s' % (field, pkginfo[field]), die_commit('{:s} field too long: {:s}'.format(field, pkginfo[field]),
commit.id) str(commit.id))
for field in ('install', 'changelog'): for field in ('install', 'changelog'):
if field in pkginfo and not pkginfo[field] in commit.tree: if field in pkginfo and not pkginfo[field] in commit.tree:
die_commit('missing %s file: %s' % (field, pkginfo[field]), die_commit('missing {:s} file: {:s}'.format(field, pkginfo[field]),
commit.id) str(commit.id))
for field in extract_arch_fields(pkginfo, 'source'): for field in extract_arch_fields(pkginfo, 'source'):
fname = field['value'] fname = field['value']
if "://" in fname or "lp:" in fname: if "://" in fname or "lp:" in fname:
continue continue
if not fname in commit.tree: if not fname in commit.tree:
die_commit('missing source file: %s' % (fname), commit.id) die_commit('missing source file: {:s}'.format(fname), str(commit.id))
srcinfo_raw = repo[repo[sha1_new].tree['.SRCINFO'].id].data.decode() srcinfo_raw = repo[repo[sha1_new].tree['.SRCINFO'].id].data.decode()
srcinfo_raw = srcinfo_raw.split('\n') srcinfo_raw = srcinfo_raw.split('\n')
...@@ -285,7 +285,7 @@ srcinfo = aurinfo.ParseAurinfoFromIterable(srcinfo_raw) ...@@ -285,7 +285,7 @@ srcinfo = aurinfo.ParseAurinfoFromIterable(srcinfo_raw)
srcinfo_pkgbase = srcinfo._pkgbase['pkgname'] srcinfo_pkgbase = srcinfo._pkgbase['pkgname']
if srcinfo_pkgbase != pkgbase: if srcinfo_pkgbase != pkgbase:
die('invalid pkgbase: %s' % (srcinfo_pkgbase)) die('invalid pkgbase: {:s}'.format(srcinfo_pkgbase))
pkgbase = srcinfo._pkgbase['pkgname'] pkgbase = srcinfo._pkgbase['pkgname']
cur.execute("SELECT ID FROM PackageBases WHERE Name = %s", [pkgbase]) cur.execute("SELECT ID FROM PackageBases WHERE Name = %s", [pkgbase])
...@@ -296,12 +296,12 @@ for pkgname in srcinfo.GetPackageNames(): ...@@ -296,12 +296,12 @@ for pkgname in srcinfo.GetPackageNames():
pkgname = pkginfo['pkgname'] pkgname = pkginfo['pkgname']
if pkgname in blacklist: if pkgname in blacklist:
die('package is blacklisted: %s' % (pkginfo['pkgname'])) die('package is blacklisted: {:s}'.format(pkginfo['pkgname']))
cur.execute("SELECT COUNT(*) FROM Packages WHERE Name = %s AND " + cur.execute("SELECT COUNT(*) FROM Packages WHERE Name = %s AND " +
"PackageBaseID <> %s", [pkgname, pkgbase_id]) "PackageBaseID <> %s", [pkgname, pkgbase_id])
if cur.fetchone()[0] > 0: if cur.fetchone()[0] > 0:
die('cannot overwrite package: %s' % (pkgname)) die('cannot overwrite package: {:s}'.format(pkgname))
save_srcinfo(srcinfo, db, cur, user) save_srcinfo(srcinfo, db, cur, user)
......
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