1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-09-17 10:40:12 +02:00

has_key() is uglier and slower than "if key in..."

This commit is contained in:
Daniel Martí 2013-03-13 17:56:17 +01:00
parent f73857fe71
commit 7bb4d5865b
5 changed files with 27 additions and 27 deletions

View File

@ -187,7 +187,7 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, sdk_path, force):
if os.path.exists(build_dir):
send_dir(build_dir)
# Copy any extlibs that are required...
if thisbuild.has_key('extlibs'):
if 'extlibs' in thisbuild:
ftp.chdir('/home/vagrant/build/extlib')
for lib in thisbuild['extlibs'].split(';'):
lp = lib.split('/')
@ -200,7 +200,7 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, sdk_path, force):
ftp.chdir('..')
# Copy any srclibs that are required...
srclibpaths = []
if thisbuild.has_key('srclibs'):
if 'srclibs' in thisbuild:
for lib in thisbuild['srclibs'].split(';'):
name, _ = lib.split('@')
srclibpaths.append((name, common.getsrclib(lib, 'build/extlib', sdk_path, basepath=True)))
@ -310,7 +310,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, extlib_dir, tmp_dir,
raise BuildException("NDK build failed for %s:%s" % (app['id'], thisbuild['version']))
# Build the release...
if thisbuild.has_key('maven'):
if 'maven' in thisbuild:
p = subprocess.Popen([mvn3, 'clean', 'package',
'-Dandroid.sdk.path=' + sdk_path,
'-Dandroid.sign.debug=false'],
@ -318,7 +318,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, extlib_dir, tmp_dir,
else:
if install:
antcommands = ['debug','install']
elif thisbuild.has_key('antcommand'):
elif 'antcommand' in thisbuild:
antcommands = [thisbuild['antcommand']]
else:
antcommands = ['release']
@ -334,7 +334,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, extlib_dir, tmp_dir,
print "Build successful"
# Find the apk name in the output...
if thisbuild.has_key('bindir'):
if 'bindir' in thisbuild:
bindir = os.path.join(build_dir, thisbuild['bindir'])
else:
bindir = os.path.join(root_dir, 'bin')
@ -343,7 +343,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, extlib_dir, tmp_dir,
src = ("funambol-android-sync-client-" +
thisbuild['version'] + "-unsigned.apk")
src = os.path.join(bindir, src)
elif thisbuild.has_key('maven'):
elif 'maven' in thisbuild:
m = re.match(r".*^\[INFO\] .*apkbuilder.*/([^/]*)\.apk",
output, re.S|re.M)
if not m:

View File

@ -56,7 +56,7 @@ def check_tags(app, sdk_path):
return (None, "Can't use Tags with no builds defined")
manifest = build_dir
if app['builds'][-1].has_key('subdir'):
if 'subdir' in app['builds'][-1]:
manifest = os.path.join(manifest, app['builds'][-1]['subdir'])
manifest = os.path.join(manifest, 'AndroidManifest.xml')
@ -109,7 +109,7 @@ def check_repomanifest(app, sdk_path):
return (None, "Can't use RepoManifest with no builds defined")
manifest = build_dir
if app['builds'][-1].has_key('subdir'):
if 'subdir' in app['builds'][-1]:
manifest = os.path.join(manifest, app['builds'][-1]['subdir'])
manifest = os.path.join(manifest, 'AndroidManifest.xml')

View File

@ -583,7 +583,7 @@ def write_metadata(dest, app):
for build in app['builds']:
writecomments('build:' + build['version'])
mf.write('Build Version:')
if build.has_key('origlines'):
if 'origlines' in build:
# Keeping the original formatting if we loaded it from a file...
mf.write('\\\n'.join(build['origlines']) + '\n')
else:
@ -1607,7 +1607,7 @@ def getsrclib(spec, extlib_dir, sdk_path, basepath=False):
def prepare_source(vcs, app, build, build_dir, extlib_dir, sdk_path, ndk_path, javacc_path, mvn3, verbose=False):
# Optionally, the actual app source can be in a subdirectory...
if build.has_key('subdir'):
if 'subdir' in build:
root_dir = os.path.join(build_dir, build['subdir'])
else:
root_dir = build_dir
@ -1627,7 +1627,7 @@ def prepare_source(vcs, app, build, build_dir, extlib_dir, sdk_path, ndk_path, j
vcs.initsubmodules()
# Run an init command if one is required...
if build.has_key('init'):
if 'init' in build:
init = build['init']
init = init.replace('$$SDK$$', sdk_path)
init = init.replace('$$NDK$$', ndk_path)
@ -1639,16 +1639,16 @@ def prepare_source(vcs, app, build, build_dir, extlib_dir, sdk_path, ndk_path, j
# Generate (or update) the ant build file, build.xml...
updatemode = build.get('update', '.')
if (updatemode != 'no' and
not build.has_key('maven')):
'maven' not in build):
parms = [os.path.join(sdk_path, 'tools', 'android'),
'update', 'project', '-p', '.']
parms.append('--subprojects')
if build.has_key('target'):
if 'target' in build:
parms.append('-t')
parms.append(build['target'])
update_dirs = updatemode.split(';')
# Force build.xml update if necessary...
if updatemode == 'force' or build.has_key('target'):
if updatemode == 'force' or 'target' in build:
if updatemode == 'force':
update_dirs = ['.']
buildxml = os.path.join(root_dir, 'build.xml')
@ -1691,26 +1691,26 @@ def prepare_source(vcs, app, build, build_dir, extlib_dir, sdk_path, ndk_path, j
# Add ndk location...
props+= "\nndk.dir=" + ndk_path + "\n"
# Add java.encoding if necessary...
if build.has_key('encoding'):
if 'encoding' in build:
props += "\njava.encoding=" + build['encoding'] + "\n"
f = open(locprops, 'w')
f.write(props)
f.close()
# Insert version code and number into the manifest if necessary...
if build.has_key('forceversion'):
if 'forceversion' in build:
if subprocess.call(['sed','-r','-i',
's/android:versionName="[^"]+"/android:versionName="' + build['version'] + '"/g',
'AndroidManifest.xml'], cwd=root_dir) !=0:
raise BuildException("Failed to amend manifest")
if build.has_key('forcevercode'):
if 'forcevercode' in build:
if subprocess.call(['sed','-r','-i',
's/android:versionCode="[^"]+"/android:versionCode="' + build['vercode'] + '"/g',
'AndroidManifest.xml'], cwd=root_dir) !=0:
raise BuildException("Failed to amend manifest")
# Delete unwanted file...
if build.has_key('rm'):
if 'rm' in build:
dest = os.path.join(build_dir, build['rm'])
if os.path.exists(dest):
os.remove(dest)
@ -1766,7 +1766,7 @@ def prepare_source(vcs, app, build, build_dir, extlib_dir, sdk_path, ndk_path, j
f.close()
# Add required external libraries...
if build.has_key('extlibs'):
if 'extlibs' in build:
libsdir = os.path.join(root_dir, 'libs')
if not os.path.exists(libsdir):
os.mkdir(libsdir)
@ -1777,7 +1777,7 @@ def prepare_source(vcs, app, build, build_dir, extlib_dir, sdk_path, ndk_path, j
# Get required source libraries...
srclibpaths = []
if build.has_key('srclibs'):
if 'srclibs' in build:
for lib in build['srclibs'].split(';'):
name, _ = lib.split('@')
srclibpaths.append((name, getsrclib(lib, extlib_dir, sdk_path)))
@ -1803,7 +1803,7 @@ def prepare_source(vcs, app, build, build_dir, extlib_dir, sdk_path, ndk_path, j
raise BuildException("Failed to apply patch %s" % patch_path)
# Run a pre-build command if one is required...
if build.has_key('prebuild'):
if 'prebuild' in build:
prebuild = build['prebuild']
# Substitute source library paths into prebuild commands...
for name, libpath in srclibpaths:

View File

@ -81,7 +81,7 @@ def main():
# If a collision does occur later, we're going to have to
# come up with a new alogrithm, AND rename all existing keys
# in the keystore!
if keyaliases.has_key(appid):
if appid in keyaliases:
# For this particular app, the key alias is overridden...
keyalias = keyaliases[appid]
else:

View File

@ -111,7 +111,7 @@ def update_wiki(apps, apks, verbose=False):
else:
validapks += 1
wikidata += "This version is built and signed by "
if apk.has_key('srcname'):
if 'srcname' in apk:
wikidata += "F-Droid, and guaranteed to correspond to the source tarball published with it.\n\n"
else:
wikidata += "the original developer.\n\n"
@ -252,7 +252,7 @@ def main():
if os.path.exists(name):
print "Deleting disabled build output " + apkfilename
os.remove(name)
if apkcache.has_key(apkfilename):
if apkfilename in apkcache:
del apkcache[apkfilename]
apks = []
@ -264,7 +264,7 @@ def main():
sys.exit(1)
srcfilename = apkfilename[:-4] + "_src.tar.gz"
if apkcache.has_key(apkfilename):
if apkfilename in apkcache:
if options.verbose:
print "Reading " + apkfilename + " from cache"
thisinfo = apkcache[apkfilename]
@ -325,7 +325,7 @@ def main():
perm = perm[16:]
thisinfo['features'].append(perm)
if not thisinfo.has_key('sdkversion'):
if not 'sdkversion' in thisinfo:
print " WARNING: no SDK version information found"
thisinfo['sdkversion'] = 0
@ -587,7 +587,7 @@ def main():
addElement('version', apk['version'], doc, apkel)
addElement('versioncode', str(apk['versioncode']), doc, apkel)
addElement('apkname', apk['apkname'], doc, apkel)
if apk.has_key('srcname'):
if 'srcname' in apk:
addElement('srcname', apk['srcname'], doc, apkel)
for hash_type in ('sha256', 'md5'):
if not hash_type in apk: