# -*- coding: utf-8 -*-
#
# build.py - part of the FDroid server tools
-# Copyright (C) 2010-12, Ciaran Gultnieks, ciaran@ciarang.com
+# Copyright (C) 2010-13, Ciaran Gultnieks, ciaran@ciarang.com
# Copyright (C) 2013 Daniel Martà <mvdan@mvdan.cc>
#
# This program is free software: you can redistribute it and/or modify
print "Adapting build.gradle at %s" % path
subprocess.call(['sed', '-i',
- 's@buildToolsVersion[ ]*["\\\'][0-9\.]*["\\\']@buildToolsVersion "'+build_tools+'"@g', path])
+ 's@buildToolsVersion[ ]*["\\\'][0-9\.]*["\\\']@buildToolsVersion "'+ config['build_tools'] +'"@g', path])
subprocess.call(['sed', '-i',
- 's@com.android.tools.build:gradle:[0-9\.\+]*@com.android.tools.build:gradle:'+gradle_plugin+'@g', path])
+ 's@com.android.tools.build:gradle:[0-9\.\+]*@com.android.tools.build:gradle:'+ config['gradle_plugin'] +'@g', path])
def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_dir, tmp_dir, install, force, verbose, onserver):
# Prepare the source code...
root_dir, srclibpaths = common.prepare_source(vcs, app, thisbuild,
- build_dir, srclib_dir, extlib_dir, sdk_path, ndk_path,
- javacc_path, mvn3, verbose, onserver)
+ build_dir, srclib_dir, extlib_dir, config['sdk_path'], config['ndk_path'],
+ config['javacc_path'], config['mvn3'], verbose, onserver)
# We need to clean via the build tool in case the binary dirs are
# different from the default ones
p = None
if 'maven' in thisbuild:
print "Cleaning Maven project..."
- cmd = [mvn3, 'clean', '-Dandroid.sdk.path=' + sdk_path]
+ cmd = [config['mvn3'], 'clean', '-Dandroid.sdk.path=' + config['sdk_path']]
if '@' in thisbuild['maven']:
maven_dir = os.path.join(root_dir, thisbuild['maven'].split('@')[1])
p = FDroidPopen(cmd, cwd=maven_dir, verbose=verbose)
elif 'gradle' in thisbuild:
print "Cleaning Gradle project..."
- cmd = [gradle, 'clean']
+ cmd = [config['gradle'], 'clean']
if '@' in thisbuild['gradle']:
gradle_dir = os.path.join(root_dir, thisbuild['gradle'].split('@')[1])
for name, libpath in srclibpaths:
libpath = os.path.relpath(libpath, root_dir)
cmd = cmd.replace('$$' + name + '$$', libpath)
- cmd = cmd.replace('$$SDK$$', sdk_path)
- cmd = cmd.replace('$$NDK$$', ndk_path)
- cmd = cmd.replace('$$MVN3$$', mvn3)
+ cmd = cmd.replace('$$SDK$$', config['sdk_path'])
+ cmd = cmd.replace('$$NDK$$', config['ndk_path'])
+ cmd = cmd.replace('$$MVN3$$', config['mvn3'])
if verbose:
print "Running 'build' commands in %s" % root_dir
jni_components = ['']
else:
jni_components = [c.strip() for c in jni_components.split(';')]
- ndkbuild = os.path.join(ndk_path, "ndk-build")
+ ndkbuild = os.path.join(config['ndk_path'], "ndk-build")
for d in jni_components:
if options.verbose:
print "Running ndk-build in " + root_dir + '/' + d
else:
maven_dir = root_dir
- mvncmd = [mvn3, '-Dandroid.sdk.path=' + sdk_path]
+ mvncmd = [config['mvn3'], '-Dandroid.sdk.path=' + config['sdk_path']]
if install:
mvncmd += ['-Dandroid.sign.debug=true', 'package', 'android:deploy']
else:
if flavour in ['main', 'yes', '']:
flavour = ''
- commands = [gradle]
+ commands = [config['gradle']]
if 'preassemble' in thisbuild:
for task in thisbuild['preassemble'].split():
commands.append(task)
src = os.path.join(bindir, src)
# Make sure it's not debuggable...
- if common.isApkDebuggable(src):
+ if common.isApkDebuggable(src, config):
raise BuildException("APK is debuggable")
# By way of a sanity check, make sure the version and version
if not os.path.exists(src):
raise BuildException("Unsigned apk is not at expected location of " + src)
- p = subprocess.Popen([os.path.join(sdk_path, 'build-tools', build_tools, 'aapt'),
+ p = subprocess.Popen([os.path.join(config['sdk_path'],
+ 'build-tools', config['build_tools'], 'aapt'),
'dump', 'badging', src],
stdout=subprocess.PIPE)
output = p.communicate()[0]
# grabbing the source now.
vcs.gotorevision(thisbuild['commit'])
- build_server(app, thisbuild, vcs, build_dir, output_dir, sdk_path, force)
+ build_server(app, thisbuild, vcs, build_dir, output_dir, config['sdk_path'], force)
else:
build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_dir, tmp_dir, install, force, verbose, onserver)
return True
return options, args
options = None
+config = {}
def main():
global options
# Read configuration...
- globals()['build_server_always'] = False
- globals()['mvn3'] = "mvn3"
- globals()['archive_older'] = 0
- execfile('config.py', globals())
+ common.read_config(config)
options, args = parse_commandline()
- if build_server_always:
+ if config['build_server_always']:
options.server = True
if options.resetserver and not options.server:
print "Using --resetserver without --server makes no sense"
print "Creating output directory"
os.makedirs(output_dir)
- if archive_older != 0:
+ if config['archive_older'] != 0:
also_check_dir = 'archive'
else:
also_check_dir = None
if options.wiki:
import mwclient
- site = mwclient.Site((wiki_protocol, wiki_server), path=wiki_path)
- site.login(wiki_user, wiki_password)
+ site = mwclient.Site((config['wiki_protocol'], config['wiki_server']),
+ path=config['wiki_path'])
+ site.login(config['wiki_user'], config['wiki_password'])
# Build applications...
failed_apps = {}
if options.verbose:
print "Getting {0} vcs interface for {1}".format(
app['Repo Type'], app['Repo'])
- vcs = common.getvcs(app['Repo Type'], app['Repo'], build_dir, sdk_path)
+ vcs = common.getvcs(app['Repo Type'], app['Repo'], build_dir, config['sdk_path'])
first = False
return (version.strip(), None)
+config = {}
+
def main():
- #Read configuration...
- globals()['gradle'] = "gradle"
- execfile('config.py', globals())
+ # Read configuration...
+ common.read_config(config)
# Parse command line...
parser = OptionParser()
tag = None
mode = app['Update Check Mode']
if mode == 'Tags':
- (version, vercode, tag) = check_tags(app, sdk_path)
+ (version, vercode, tag) = check_tags(app, config['sdk_path'])
elif mode == 'RepoManifest':
- (version, vercode) = check_repomanifest(app, sdk_path)
+ (version, vercode) = check_repomanifest(app, config['sdk_path'])
elif mode.startswith('RepoManifest/'):
- (version, vercode) = check_repomanifest(app, sdk_path, mode[13:])
+ (version, vercode) = check_repomanifest(app, config['sdk_path'], mode[13:])
elif mode == 'RepoTrunk':
- (version, vercode) = check_repotrunk(app, sdk_path)
+ (version, vercode) = check_repotrunk(app, config['sdk_path'])
elif mode == 'HTTP':
(version, vercode) = check_http(app)
elif mode == 'Static':
else:
app_dir = os.path.join('build/', app['id'])
- vcs = common.getvcs(app["Repo Type"], app["Repo"], app_dir, sdk_path)
+ vcs = common.getvcs(app["Repo Type"], app["Repo"], app_dir,
+ config['sdk_path'])
vcs.gotorevision(tag)
flavour = None
import threading
import magic
+def read_config(config):
+ """Read the repository config
+
+ The config is read from config.py, which is in the current directory when
+ any of the repo management commands are used.
+ """
+ if not os.path.isfile('config.py'):
+ print "Missing config file - is this a repo directory?"
+ sys.exit(2)
+ config['build_server_always'] = False
+ config['mvn3'] = "mvn3"
+ config['archive_older'] = 0
+ config['gradle'] = 'gradle'
+ config['update_stats'] = False
+ config['archive_older'] = 0
+ config['max_icon_size'] = 72
+ config['stats_to_carbon'] = False
+ execfile('config.py', config)
+
+
def getvcs(vcstype, remote, local, sdk_path):
if vcstype == 'git':
return vcs_git(remote, local, sdk_path)
lst.reverse()
return lst
-def isApkDebuggable(apkfile):
+def isApkDebuggable(apkfile, config):
"""Returns True if the given apk file is debuggable
:param apkfile: full path to the apk to check"""
- execfile('config.py', globals())
-
- p = subprocess.Popen([os.path.join(sdk_path, 'build-tools', build_tools, 'aapt'),
- 'dump', 'xmltree', apkfile, 'AndroidManifest.xml'],
- stdout=subprocess.PIPE)
+ p = subprocess.Popen([os.path.join(config['sdk_path'],
+ 'build-tools', config['build_tools'], 'aapt'),
+ 'dump', 'xmltree', apkfile, 'AndroidManifest.xml'],
+ stdout=subprocess.PIPE)
output = p.communicate()[0]
if p.returncode != 0:
print "ERROR: Failed to get apk manifest information"
# -*- coding: utf-8 -*-
#
# import.py - part of the FDroid server tools
-# Copyright (C) 2010-12, Ciaran Gultnieks, ciaran@ciarang.com
+# Copyright (C) 2010-13, Ciaran Gultnieks, ciaran@ciarang.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
import shutil
import urllib
from optparse import OptionParser
-
+import common
# Get the repo type and address from the given web page. The page is scanned
# in a rather naive manner for 'git clone xxxx', 'hg clone xxxx', etc, and
return (None, "No information found." + page)
+config = {}
def main():
# Read configuration...
- execfile('config.py', globals())
+ common.read_config(config)
import common
src_dir = os.path.join(tmp_dir, 'importer')
if os.path.exists(src_dir):
shutil.rmtree(src_dir)
- vcs = common.getvcs(repotype, repo, src_dir, sdk_path)
+ vcs = common.getvcs(repotype, repo, src_dir, config['sdk_path'])
vcs.gotorevision(options.rev)
if options.subdir:
root_dir = os.path.join(src_dir, options.subdir)
# -*- coding: utf-8 -*-
#
# publish.py - part of the FDroid server tools
-# Copyright (C) 2010-12, Ciaran Gultnieks, ciaran@ciarang.com
+# Copyright (C) 2010-13, Ciaran Gultnieks, ciaran@ciarang.com
# Copyright (C) 2013 Daniel Martà <mvdan@mvdan.cc>
#
# This program is free software: you can redistribute it and/or modify
import glob
from optparse import OptionParser
+import common
from common import BuildException
+config = {}
+
def main():
- #Read configuration...
- execfile('config.py', globals())
+ # Read configuration...
+ common.read_config(config)
# Parse command line...
parser = OptionParser()
# 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 appid in keyaliases:
+ if appid in config['keyaliases']:
# For this particular app, the key alias is overridden...
- keyalias = keyaliases[appid]
+ keyalias = config['keyaliases'][appid]
if keyalias.startswith('@'):
m = md5.new()
m.update(keyalias[1:])
# See if we already have a key for this application, and
# if not generate one...
p = subprocess.Popen(['keytool', '-list',
- '-alias', keyalias, '-keystore', keystore,
- '-storepass', keystorepass], stdout=subprocess.PIPE)
+ '-alias', keyalias, '-keystore', config['keystore'],
+ '-storepass', config['keystorepass']], stdout=subprocess.PIPE)
output = p.communicate()[0]
if p.returncode !=0:
print "Key does not exist - generating..."
p = subprocess.Popen(['keytool', '-genkey',
- '-keystore', keystore, '-alias', keyalias,
+ '-keystore', config['keystore'], '-alias', keyalias,
'-keyalg', 'RSA', '-keysize', '2048',
'-validity', '10000',
- '-storepass', keystorepass, '-keypass', keypass,
- '-dname', keydname], stdout=subprocess.PIPE)
+ '-storepass', config['keystorepass'],
+ '-keypass', config['keypass'],
+ '-dname', config['keydname']], stdout=subprocess.PIPE)
output = p.communicate()[0]
print output
if p.returncode != 0:
raise BuildException("Failed to generate key")
# Sign the application...
- p = subprocess.Popen(['jarsigner', '-keystore', keystore,
- '-storepass', keystorepass, '-keypass', keypass, '-sigalg',
+ p = subprocess.Popen(['jarsigner', '-keystore', config['keystore'],
+ '-storepass', config['keystorepass'],
+ '-keypass', config['keypass'], '-sigalg',
'MD5withRSA', '-digestalg', 'SHA1',
apkfile, keyalias], stdout=subprocess.PIPE)
output = p.communicate()[0]
raise BuildException("Failed to sign application")
# Zipalign it...
- p = subprocess.Popen([os.path.join(sdk_path,'tools','zipalign'),
+ p = subprocess.Popen([os.path.join(config['sdk_path'],'tools','zipalign'),
'-v', '4', apkfile,
os.path.join(output_dir, apkfilename)],
stdout=subprocess.PIPE)
# -*- coding: utf-8 -*-
#
# scanner.py - part of the FDroid server tools
-# Copyright (C) 2010-12, Ciaran Gultnieks, ciaran@ciarang.com
+# Copyright (C) 2010-13, Ciaran Gultnieks, ciaran@ciarang.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
from common import BuildException
from common import VCSException
+config = {}
+
def main():
# Read configuration...
- global build_server_always, mvn3
- globals()['build_server_always'] = False
- globals()['mvn3'] = "mvn3"
- execfile('config.py', globals())
+ common.read_config(config)
# Parse command line...
build_dir = 'build/' + app['id']
# Set up vcs interface and make sure we have the latest code...
- vcs = common.getvcs(app['Repo Type'], app['Repo'], build_dir, sdk_path)
+ vcs = common.getvcs(app['Repo Type'], app['Repo'], build_dir,
+ config['sdk_path'])
for thisbuild in app['builds']:
# Prepare the source code...
root_dir, _ = common.prepare_source(vcs, app, thisbuild,
- build_dir, srclib_dir, extlib_dir, sdk_path, ndk_path,
- javacc_path, mvn3, options.verbose, False)
+ build_dir, srclib_dir, extlib_dir,
+ config['sdk_path'], config['ndk_path'],
+ config['javacc_path'], config['mvn3'],
+ options.verbose, False)
# Do the scan...
buildprobs = common.scan_source(build_dir, root_dir, thisbuild)
# -*- coding: utf-8 -*-
#
# server.py - part of the FDroid server tools
-# Copyright (C) 2010-12, Ciaran Gultnieks, ciaran@ciarang.com
+# Copyright (C) 2010-13, Ciaran Gultnieks, ciaran@ciarang.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
import os
import subprocess
from optparse import OptionParser
+import common
+
+config = {}
def main():
- #Read configuration...
- global archive_older
- archive_older = 0
- execfile('config.py', globals())
+ # Read configuration...
+ common.read_config(config)
# Parse command line...
parser = OptionParser()
sys.exit(1)
repodirs = ['repo']
- if archive_older != 0:
+ if config['archive_older'] != 0:
repodirs.append('archive')
for repodir in repodirs:
index = os.path.join(repodir, 'index.xml')
indexjar = os.path.join(repodir, 'index.jar')
if subprocess.call(['rsync', '-u', '-v', '-r', '--delete',
- '--exclude', index, '--exclude', indexjar, repodir, serverwebroot]) != 0:
+ '--exclude', index, '--exclude', indexjar, repodir, config['serverwebroot']]) != 0:
sys.exit(1)
if subprocess.call(['rsync', '-u', '-v', '-r', '--delete',
- index, serverwebroot + '/' + repodir]) != 0:
+ index, config['serverwebroot'] + '/' + repodir]) != 0:
sys.exit(1)
if subprocess.call(['rsync', '-u', '-v', '-r', '--delete',
- indexjar, serverwebroot + '/' + repodir]) != 0:
+ indexjar, config['serverwebroot'] + '/' + repodir]) != 0:
sys.exit(1)
sys.exit(0)
# -*- coding: utf-8 -*-
#
# stats.py - part of the FDroid server tools
-# Copyright (C) 2010-12, Ciaran Gultnieks, ciaran@ciarang.com
+# Copyright (C) 2010-13, Ciaran Gultnieks, ciaran@ciarang.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
def carbon_send(key, value):
s = socket.socket()
- s.connect((carbon_host, carbon_port))
+ s.connect((config['carbon_host'], config['carbon_port']))
msg = '%s %d %d\n' % (key, value, int(time.time()))
s.sendall(msg)
s.close()
+config = {}
+
def main():
# Read configuration...
- global update_stats, stats_to_carbon
- update_stats = False
- stats_to_carbon = False
- execfile('config.py', globals())
+ common.read_config(config)
- if not update_stats:
+ if not config['update_stats']:
print "Stats are disabled - check your configuration"
sys.exit(1)
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.connect('f-droid.org', username='fdroid', timeout=10,
- key_filename=webserver_keyfile)
+ key_filename=config['webserver_keyfile'])
ftp = ssh.open_sftp()
ftp.get_channel().settimeout(60)
print "...connected"
alldownloads = 0
for app, count in apps.iteritems():
lst.append(app + " " + str(count))
- if stats_to_carbon:
+ if config['stats_to_carbon']:
carbon_send('fdroid.download.' + app.replace('.', '_'), count)
alldownloads += count
lst.append("ALL " + str(alldownloads))
wikicat = 'Apps'
wikiredircat = 'App Redirects'
import mwclient
- site = mwclient.Site((wiki_protocol, wiki_server), path=wiki_path)
- site.login(wiki_user, wiki_password)
+ site = mwclient.Site((config['wiki_protocol'], config['wiki_server']),
+ path=config['wiki_path'])
+ site.login(config['wiki_user'], config['wiki_password'])
generated_pages = {}
generated_redirects = {}
for app in apps:
def resize_icon(iconpath):
try:
im = Image.open(iconpath)
- if any(length > max_icon_size for length in im.size):
+ if any(length > config['max_icon_size'] for length in im.size):
print iconpath, "is too large:", im.size
- im.thumbnail((max_icon_size, max_icon_size), Image.ANTIALIAS)
+ im.thumbnail((config['max_icon_size'], config['max_icon_size']),
+ Image.ANTIALIAS)
print iconpath, "new size:", im.size
im.save(iconpath, "PNG")
else:
thisinfo['size'] = os.path.getsize(apkfile)
thisinfo['permissions'] = []
thisinfo['features'] = []
- p = subprocess.Popen([os.path.join(sdk_path, 'build-tools', build_tools, 'aapt'),
+ p = subprocess.Popen([os.path.join(config['sdk_path'], 'build-tools', config['build_tools'], 'aapt'),
'dump', 'badging', apkfile],
stdout=subprocess.PIPE)
output = p.communicate()[0]
thisinfo['sdkversion'] = 0
# Check for debuggable apks...
- if common.isApkDebuggable(apkfile):
+ if common.isApkDebuggable(apkfile, config):
print "WARNING: {0} is debuggable... {1}".format(apkfile, line)
# Calculate the sha256...
repoel = doc.createElement("repo")
if archive:
- repoel.setAttribute("name", archive_name)
- repoel.setAttribute("icon", os.path.basename(archive_icon))
- repoel.setAttribute("url", archive_url)
- addElement('description', archive_description, doc, repoel)
+ repoel.setAttribute("name", config['archive_name'])
+ repoel.setAttribute("icon", os.path.basename(config['archive_icon']))
+ repoel.setAttribute("url", config['archive_url'])
+ addElement('description', config['archive_description'], doc, repoel)
else:
- repoel.setAttribute("name", repo_name)
- repoel.setAttribute("icon", os.path.basename(repo_icon))
- repoel.setAttribute("url", repo_url)
- addElement('description', repo_description, doc, repoel)
+ repoel.setAttribute("name", config['repo_name'])
+ repoel.setAttribute("icon", os.path.basename(config['repo_icon']))
+ repoel.setAttribute("url", config['repo_url'])
+ addElement('description', config['repo_description'], doc, repoel)
- if repo_keyalias is not None:
+ if config['repo_keyalias'] is not None:
# Generate a certificate fingerprint the same way keytool does it
# (but with slightly different formatting)
def extract_pubkey():
p = subprocess.Popen(['keytool', '-exportcert',
- '-alias', repo_keyalias,
- '-keystore', keystore,
- '-storepass', keystorepass],
+ '-alias', config['repo_keyalias'],
+ '-keystore', config['keystore'],
+ '-storepass', config['keystorepass']],
stdout=subprocess.PIPE)
cert = p.communicate()[0]
if p.returncode != 0:
of.write(output)
of.close()
- if repo_keyalias is not None:
+ if config['repo_keyalias'] is not None:
if not options.quiet:
print "Creating signed index."
- print "Key fingerprint:", repo_pubkey_fingerprint
+ print "Key fingerprint:", config['repo_pubkey_fingerprint']
#Create a jar of the index...
p = subprocess.Popen(['jar', 'cf', 'index.jar', 'index.xml'],
sys.exit(1)
# Sign the index...
- p = subprocess.Popen(['jarsigner', '-keystore', keystore,
- '-storepass', keystorepass, '-keypass', keypass,
+ p = subprocess.Popen(['jarsigner', '-keystore', config['keystore'],
+ '-storepass', config['keystorepass'], '-keypass', config['keypass'],
'-digestalg', 'SHA1', '-sigalg', 'MD5withRSA',
- os.path.join(repodir, 'index.jar') , repo_keyalias], stdout=subprocess.PIPE)
+ os.path.join(repodir, 'index.jar') , config['repo_keyalias']], stdout=subprocess.PIPE)
output = p.communicate()[0]
if p.returncode != 0:
print "Failed to sign index"
# Copy the repo icon into the repo directory...
icon_dir=os.path.join(repodir ,'icons')
- iconfilename = os.path.join(icon_dir, os.path.basename(repo_icon))
- shutil.copyfile(repo_icon, iconfilename)
+ iconfilename = os.path.join(icon_dir, os.path.basename(config['repo_icon']))
+ shutil.copyfile(config['repo_icon'], iconfilename)
# Write a category list in the repo to allow quick access...
catdata = ''
apks.remove(apk)
+config = {}
+options = None
+
def main():
# Read configuration...
- global update_stats, archive_older, max_icon_size
- update_stats = False
- archive_older = 0
- max_icon_size = 72
- execfile('config.py', globals())
+ common.read_config(config)
# Parse command line...
global options
(options, args) = parser.parse_args()
repodirs = ['repo']
- if archive_older != 0:
+ if config['archive_older'] != 0:
repodirs.append('archive')
if not os.path.exists('archive'):
os.mkdir('archive')
print " " + apk['name'] + " - " + apk['version']
if len(repodirs) > 1:
- archive_old_apks(apps, apks, repodirs[0], repodirs[1], archive_older)
+ archive_old_apks(apps, apks, repodirs[0], repodirs[1], config['archive_older'])
# Make the index for the main repo...
make_index(apps, apks, repodirs[0], False, categories)
cachechanged = True
make_index(apps, archapks, repodirs[1], True, categories)
- if update_stats:
+ if config['update_stats']:
# Update known apks info...
knownapks.writeifchanged()