1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-09 17:00:12 +01: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): if os.path.exists(build_dir):
send_dir(build_dir) send_dir(build_dir)
# Copy any extlibs that are required... # Copy any extlibs that are required...
if thisbuild.has_key('extlibs'): if 'extlibs' in thisbuild:
ftp.chdir('/home/vagrant/build/extlib') ftp.chdir('/home/vagrant/build/extlib')
for lib in thisbuild['extlibs'].split(';'): for lib in thisbuild['extlibs'].split(';'):
lp = lib.split('/') lp = lib.split('/')
@ -200,7 +200,7 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, sdk_path, force):
ftp.chdir('..') ftp.chdir('..')
# Copy any srclibs that are required... # Copy any srclibs that are required...
srclibpaths = [] srclibpaths = []
if thisbuild.has_key('srclibs'): if 'srclibs' in thisbuild:
for lib in thisbuild['srclibs'].split(';'): for lib in thisbuild['srclibs'].split(';'):
name, _ = lib.split('@') name, _ = lib.split('@')
srclibpaths.append((name, common.getsrclib(lib, 'build/extlib', sdk_path, basepath=True))) 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'])) raise BuildException("NDK build failed for %s:%s" % (app['id'], thisbuild['version']))
# Build the release... # Build the release...
if thisbuild.has_key('maven'): if 'maven' in thisbuild:
p = subprocess.Popen([mvn3, 'clean', 'package', p = subprocess.Popen([mvn3, 'clean', 'package',
'-Dandroid.sdk.path=' + sdk_path, '-Dandroid.sdk.path=' + sdk_path,
'-Dandroid.sign.debug=false'], '-Dandroid.sign.debug=false'],
@ -318,7 +318,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, extlib_dir, tmp_dir,
else: else:
if install: if install:
antcommands = ['debug','install'] antcommands = ['debug','install']
elif thisbuild.has_key('antcommand'): elif 'antcommand' in thisbuild:
antcommands = [thisbuild['antcommand']] antcommands = [thisbuild['antcommand']]
else: else:
antcommands = ['release'] antcommands = ['release']
@ -334,7 +334,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, extlib_dir, tmp_dir,
print "Build successful" print "Build successful"
# Find the apk name in the output... # Find the apk name in the output...
if thisbuild.has_key('bindir'): if 'bindir' in thisbuild:
bindir = os.path.join(build_dir, thisbuild['bindir']) bindir = os.path.join(build_dir, thisbuild['bindir'])
else: else:
bindir = os.path.join(root_dir, 'bin') 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-" + src = ("funambol-android-sync-client-" +
thisbuild['version'] + "-unsigned.apk") thisbuild['version'] + "-unsigned.apk")
src = os.path.join(bindir, src) src = os.path.join(bindir, src)
elif thisbuild.has_key('maven'): elif 'maven' in thisbuild:
m = re.match(r".*^\[INFO\] .*apkbuilder.*/([^/]*)\.apk", m = re.match(r".*^\[INFO\] .*apkbuilder.*/([^/]*)\.apk",
output, re.S|re.M) output, re.S|re.M)
if not 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") return (None, "Can't use Tags with no builds defined")
manifest = build_dir 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, app['builds'][-1]['subdir'])
manifest = os.path.join(manifest, 'AndroidManifest.xml') 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") return (None, "Can't use RepoManifest with no builds defined")
manifest = build_dir 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, app['builds'][-1]['subdir'])
manifest = os.path.join(manifest, 'AndroidManifest.xml') manifest = os.path.join(manifest, 'AndroidManifest.xml')

View File

@ -583,7 +583,7 @@ def write_metadata(dest, app):
for build in app['builds']: for build in app['builds']:
writecomments('build:' + build['version']) writecomments('build:' + build['version'])
mf.write('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... # Keeping the original formatting if we loaded it from a file...
mf.write('\\\n'.join(build['origlines']) + '\n') mf.write('\\\n'.join(build['origlines']) + '\n')
else: 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): 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... # 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']) root_dir = os.path.join(build_dir, build['subdir'])
else: else:
root_dir = build_dir 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() vcs.initsubmodules()
# Run an init command if one is required... # Run an init command if one is required...
if build.has_key('init'): if 'init' in build:
init = build['init'] init = build['init']
init = init.replace('$$SDK$$', sdk_path) init = init.replace('$$SDK$$', sdk_path)
init = init.replace('$$NDK$$', ndk_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... # Generate (or update) the ant build file, build.xml...
updatemode = build.get('update', '.') updatemode = build.get('update', '.')
if (updatemode != 'no' and if (updatemode != 'no' and
not build.has_key('maven')): 'maven' not in build):
parms = [os.path.join(sdk_path, 'tools', 'android'), parms = [os.path.join(sdk_path, 'tools', 'android'),
'update', 'project', '-p', '.'] 'update', 'project', '-p', '.']
parms.append('--subprojects') parms.append('--subprojects')
if build.has_key('target'): if 'target' in build:
parms.append('-t') parms.append('-t')
parms.append(build['target']) parms.append(build['target'])
update_dirs = updatemode.split(';') update_dirs = updatemode.split(';')
# Force build.xml update if necessary... # Force build.xml update if necessary...
if updatemode == 'force' or build.has_key('target'): if updatemode == 'force' or 'target' in build:
if updatemode == 'force': if updatemode == 'force':
update_dirs = ['.'] update_dirs = ['.']
buildxml = os.path.join(root_dir, 'build.xml') 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... # Add ndk location...
props+= "\nndk.dir=" + ndk_path + "\n" props+= "\nndk.dir=" + ndk_path + "\n"
# Add java.encoding if necessary... # Add java.encoding if necessary...
if build.has_key('encoding'): if 'encoding' in build:
props += "\njava.encoding=" + build['encoding'] + "\n" props += "\njava.encoding=" + build['encoding'] + "\n"
f = open(locprops, 'w') f = open(locprops, 'w')
f.write(props) f.write(props)
f.close() f.close()
# Insert version code and number into the manifest if necessary... # 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', if subprocess.call(['sed','-r','-i',
's/android:versionName="[^"]+"/android:versionName="' + build['version'] + '"/g', 's/android:versionName="[^"]+"/android:versionName="' + build['version'] + '"/g',
'AndroidManifest.xml'], cwd=root_dir) !=0: 'AndroidManifest.xml'], cwd=root_dir) !=0:
raise BuildException("Failed to amend manifest") raise BuildException("Failed to amend manifest")
if build.has_key('forcevercode'): if 'forcevercode' in build:
if subprocess.call(['sed','-r','-i', if subprocess.call(['sed','-r','-i',
's/android:versionCode="[^"]+"/android:versionCode="' + build['vercode'] + '"/g', 's/android:versionCode="[^"]+"/android:versionCode="' + build['vercode'] + '"/g',
'AndroidManifest.xml'], cwd=root_dir) !=0: 'AndroidManifest.xml'], cwd=root_dir) !=0:
raise BuildException("Failed to amend manifest") raise BuildException("Failed to amend manifest")
# Delete unwanted file... # Delete unwanted file...
if build.has_key('rm'): if 'rm' in build:
dest = os.path.join(build_dir, build['rm']) dest = os.path.join(build_dir, build['rm'])
if os.path.exists(dest): if os.path.exists(dest):
os.remove(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() f.close()
# Add required external libraries... # Add required external libraries...
if build.has_key('extlibs'): if 'extlibs' in build:
libsdir = os.path.join(root_dir, 'libs') libsdir = os.path.join(root_dir, 'libs')
if not os.path.exists(libsdir): if not os.path.exists(libsdir):
os.mkdir(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... # Get required source libraries...
srclibpaths = [] srclibpaths = []
if build.has_key('srclibs'): if 'srclibs' in build:
for lib in build['srclibs'].split(';'): for lib in build['srclibs'].split(';'):
name, _ = lib.split('@') name, _ = lib.split('@')
srclibpaths.append((name, getsrclib(lib, extlib_dir, sdk_path))) 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) raise BuildException("Failed to apply patch %s" % patch_path)
# Run a pre-build command if one is required... # Run a pre-build command if one is required...
if build.has_key('prebuild'): if 'prebuild' in build:
prebuild = build['prebuild'] prebuild = build['prebuild']
# Substitute source library paths into prebuild commands... # Substitute source library paths into prebuild commands...
for name, libpath in srclibpaths: 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 # If a collision does occur later, we're going to have to
# come up with a new alogrithm, AND rename all existing keys # come up with a new alogrithm, AND rename all existing keys
# in the keystore! # in the keystore!
if keyaliases.has_key(appid): if appid in keyaliases:
# For this particular app, the key alias is overridden... # For this particular app, the key alias is overridden...
keyalias = keyaliases[appid] keyalias = keyaliases[appid]
else: else:

View File

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