mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
git: Use .format everywhere instead of %
% formatting is deprecated, and .format should be used instead. Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
parent
226376fc62
commit
ae2907a57e
3 changed files with 47 additions and 47 deletions
|
@ -84,7 +84,7 @@ class AurInfo(object):
|
|||
|
||||
class StderrECatcher(object):
|
||||
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):
|
||||
|
@ -126,8 +126,8 @@ def ParseAurinfoFromIterable(iterable, ecatcher=None):
|
|||
try:
|
||||
key, value = map(str.strip, line.split('=', 1))
|
||||
except ValueError:
|
||||
ecatcher.Catch(lineno, 'unexpected header format in section=%s' %
|
||||
current_package['pkgname'])
|
||||
ecatcher.Catch(lineno, 'unexpected header format in section={:s}'.format(
|
||||
current_package['pkgname']))
|
||||
continue
|
||||
|
||||
if key == 'pkgbase':
|
||||
|
@ -149,7 +149,7 @@ def ParseAurinfoFromIterable(iterable, ecatcher=None):
|
|||
key, value = map(str.strip, line.split('=', 1))
|
||||
except ValueError:
|
||||
ecatcher.Catch(lineno, 'unexpected attribute format in '
|
||||
'section=%s' % current_package['pkgname'])
|
||||
'section={:s}'.format(current_package['pkgname']))
|
||||
|
||||
if IsMultiValued(key):
|
||||
if not current_package.get(key):
|
||||
|
@ -161,8 +161,8 @@ def ParseAurinfoFromIterable(iterable, ecatcher=None):
|
|||
current_package[key] = value
|
||||
else:
|
||||
ecatcher.Catch(lineno, 'overwriting attribute '
|
||||
'%s: %s -> %s' % (key, current_package[key],
|
||||
value))
|
||||
'{:s}: {:s} -> {:s}'.format(key,
|
||||
current_package[key], value))
|
||||
|
||||
return aurinfo
|
||||
|
||||
|
@ -177,7 +177,7 @@ def ValidateAurinfo(filename='.AURINFO'):
|
|||
ParseAurinfo(filename, ecatcher)
|
||||
errors = ecatcher.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
|
||||
|
||||
|
||||
|
@ -196,13 +196,13 @@ if __name__ == '__main__':
|
|||
if action == 'parse':
|
||||
aurinfo = ParseAurinfo()
|
||||
for pkgname in aurinfo.GetPackageNames():
|
||||
print(">>> merged package: %s" % pkgname)
|
||||
print(">>> merged package: {:s}".format(pkgname))
|
||||
pp.pprint(aurinfo.GetMergedPackage(pkgname))
|
||||
print()
|
||||
elif action == 'validate':
|
||||
sys.exit(not ValidateAurinfo(filename))
|
||||
else:
|
||||
print('unknown action: %s' % action)
|
||||
print('unknown action: {:s}'.format(action))
|
||||
sys.exit(1)
|
||||
|
||||
# vim: set et ts=4 sw=4:
|
||||
|
|
|
@ -45,7 +45,7 @@ def list_repos(user):
|
|||
cur.execute("SELECT ID FROM Users WHERE Username = %s ", [user])
|
||||
userid = cur.fetchone()[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 " +
|
||||
"WHERE MaintainerUID = %s ", [userid])
|
||||
|
@ -55,9 +55,9 @@ def list_repos(user):
|
|||
|
||||
def create_pkgbase(pkgbase, user):
|
||||
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):
|
||||
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,
|
||||
passwd=aur_db_pass, db=aur_db_name,
|
||||
|
@ -67,7 +67,7 @@ def create_pkgbase(pkgbase, user):
|
|||
cur.execute("SELECT ID FROM Users WHERE Username = %s ", [user])
|
||||
userid = cur.fetchone()[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, " +
|
||||
"SubmitterUID, MaintainerUID) VALUES (%s, UNIX_TIMESTAMP(), " +
|
||||
|
@ -100,11 +100,11 @@ def check_permissions(pkgbase, user):
|
|||
return cur.fetchone()[0] > 0
|
||||
|
||||
def die(msg):
|
||||
sys.stderr.write("%s\n" % (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." % (ssh_cmdline))
|
||||
die(msg + "\nTry `{:s} help` for a list of commands.".format(ssh_cmdline))
|
||||
|
||||
user = sys.argv[1]
|
||||
cmd = os.environ.get("SSH_ORIGINAL_COMMAND")
|
||||
|
@ -120,7 +120,7 @@ if enable_maintenance:
|
|||
|
||||
if action == 'git-upload-pack' or action == 'git-receive-pack':
|
||||
if len(cmdargv) < 2:
|
||||
die_with_help("%s: missing path" % (action))
|
||||
die_with_help("{:s}: missing path".format(action))
|
||||
|
||||
path = cmdargv[1].rstrip('/')
|
||||
if not path.startswith('/'):
|
||||
|
@ -129,14 +129,14 @@ if action == 'git-upload-pack' or action == 'git-receive-pack':
|
|||
path = path + '.git'
|
||||
pkgbase = path[1:-4]
|
||||
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):
|
||||
create_pkgbase(pkgbase, user)
|
||||
|
||||
if action == 'git-receive-pack':
|
||||
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_PKGBASE"] = pkgbase
|
||||
|
@ -145,13 +145,13 @@ if action == 'git-upload-pack' or action == 'git-receive-pack':
|
|||
os.execl(git_shell_cmd, git_shell_cmd, '-c', cmd)
|
||||
elif action == 'list-repos':
|
||||
if len(cmdargv) > 1:
|
||||
die_with_help("%s: too many arguments" % (action))
|
||||
die_with_help("{:s}: too many arguments".format(action))
|
||||
list_repos(user)
|
||||
elif action == 'setup-repo':
|
||||
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:
|
||||
die_with_help("%s: too many arguments" % (action))
|
||||
die_with_help("{:s}: too many arguments".format(action))
|
||||
create_pkgbase(cmdargv[1], user)
|
||||
elif action == 'help':
|
||||
die("Commands:\n" +
|
||||
|
@ -161,4 +161,4 @@ elif action == 'help':
|
|||
" git-receive-pack Internal command used with Git.\n" +
|
||||
" git-upload-pack Internal command used with Git.")
|
||||
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):
|
|||
pkginfo = srcinfo.GetMergedPackage(pkgname)
|
||||
|
||||
if 'epoch' in pkginfo and int(pkginfo['epoch']) > 0:
|
||||
ver = '%d:%s-%s' % (int(pkginfo['epoch']), pkginfo['pkgver'],
|
||||
pkginfo['pkgrel'])
|
||||
ver = '{:d}:{:s}-{:s}'.format(int(pkginfo['epoch']), pkginfo['pkgver'],
|
||||
pkginfo['pkgrel'])
|
||||
else:
|
||||
ver = '%s-%s' % (pkginfo['pkgver'], pkginfo['pkgrel'])
|
||||
ver = '{:s}-{:s}'.format(pkginfo['pkgver'], pkginfo['pkgrel'])
|
||||
|
||||
for field in ('pkgdesc', 'url'):
|
||||
if not field in pkginfo:
|
||||
|
@ -166,14 +166,14 @@ def save_srcinfo(srcinfo, db, cur, user):
|
|||
db.commit()
|
||||
|
||||
def die(msg):
|
||||
sys.stderr.write("error: %s\n" % (msg))
|
||||
sys.stderr.write("error: {:s}\n".format(msg))
|
||||
exit(1)
|
||||
|
||||
def die_commit(msg, commit):
|
||||
sys.stderr.write("error: The following error " +
|
||||
"occurred when parsing commit\n")
|
||||
sys.stderr.write("error: %s:\n" % (commit))
|
||||
sys.stderr.write("error: %s\n" % (msg))
|
||||
sys.stderr.write("error: {:s}:\n".format(commit))
|
||||
sys.stderr.write("error: {:s}\n".format(msg))
|
||||
exit(1)
|
||||
|
||||
if len(sys.argv) != 4:
|
||||
|
@ -216,20 +216,20 @@ blacklist = [row[0] for row in cur.fetchall()]
|
|||
|
||||
for commit in walker:
|
||||
if not '.SRCINFO' in commit.tree:
|
||||
die_commit("missing .SRCINFO", commit.id)
|
||||
die_commit("missing .SRCINFO", str(commit.id))
|
||||
|
||||
for treeobj in commit.tree:
|
||||
blob = repo[treeobj.id]
|
||||
|
||||
if isinstance(blob, pygit2.Tree):
|
||||
die_commit("the repository must not contain subdirectories",
|
||||
commit.id)
|
||||
str(commit.id))
|
||||
|
||||
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:
|
||||
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 = srcinfo_raw.split('\n')
|
||||
|
@ -239,45 +239,45 @@ for commit in walker:
|
|||
if errors:
|
||||
sys.stderr.write("error: The following errors occurred "
|
||||
"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:
|
||||
sys.stderr.write("error: line %d: %s\n" % error)
|
||||
sys.stderr.write("error: line {:d}: {:s}\n".format(error))
|
||||
exit(1)
|
||||
|
||||
srcinfo_pkgbase = srcinfo._pkgbase['pkgname']
|
||||
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():
|
||||
pkginfo = srcinfo.GetMergedPackage(pkgname)
|
||||
|
||||
for field in ('pkgver', 'pkgrel', 'pkgname'):
|
||||
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():
|
||||
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']):
|
||||
die_commit('invalid package name: %s' % (pkginfo['pkgname']),
|
||||
commit.id)
|
||||
die_commit('invalid package name: {:s}'.format(pkginfo['pkgname']),
|
||||
str(commit.id))
|
||||
|
||||
for field in ('pkgname', 'pkgdesc', 'url'):
|
||||
if field in pkginfo and len(pkginfo[field]) > 255:
|
||||
die_commit('%s field too long: %s' % (field, pkginfo[field]),
|
||||
commit.id)
|
||||
die_commit('{:s} field too long: {:s}'.format(field, pkginfo[field]),
|
||||
str(commit.id))
|
||||
|
||||
for field in ('install', 'changelog'):
|
||||
if field in pkginfo and not pkginfo[field] in commit.tree:
|
||||
die_commit('missing %s file: %s' % (field, pkginfo[field]),
|
||||
commit.id)
|
||||
die_commit('missing {:s} file: {:s}'.format(field, pkginfo[field]),
|
||||
str(commit.id))
|
||||
|
||||
for field in extract_arch_fields(pkginfo, 'source'):
|
||||
fname = field['value']
|
||||
if "://" in fname or "lp:" in fname:
|
||||
continue
|
||||
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 = srcinfo_raw.split('\n')
|
||||
|
@ -285,7 +285,7 @@ srcinfo = aurinfo.ParseAurinfoFromIterable(srcinfo_raw)
|
|||
|
||||
srcinfo_pkgbase = srcinfo._pkgbase['pkgname']
|
||||
if srcinfo_pkgbase != pkgbase:
|
||||
die('invalid pkgbase: %s' % (srcinfo_pkgbase))
|
||||
die('invalid pkgbase: {:s}'.format(srcinfo_pkgbase))
|
||||
|
||||
pkgbase = srcinfo._pkgbase['pkgname']
|
||||
cur.execute("SELECT ID FROM PackageBases WHERE Name = %s", [pkgbase])
|
||||
|
@ -296,12 +296,12 @@ for pkgname in srcinfo.GetPackageNames():
|
|||
pkgname = pkginfo['pkgname']
|
||||
|
||||
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 " +
|
||||
"PackageBaseID <> %s", [pkgname, pkgbase_id])
|
||||
if cur.fetchone()[0] > 0:
|
||||
die('cannot overwrite package: %s' % (pkgname))
|
||||
die('cannot overwrite package: {:s}'.format(pkgname))
|
||||
|
||||
save_srcinfo(srcinfo, db, cur, user)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue