All callable scripts now implement main()

This commit is contained in:
Ciaran Gultnieks 2012-02-26 14:18:58 +00:00
parent 4e5b4fa77c
commit 00abc9527d
7 changed files with 970 additions and 936 deletions

View file

@ -27,9 +27,6 @@ from optparse import OptionParser
import HTMLParser
import common
#Read configuration...
execfile('config.py')
# Check for a new version by looking at the Google market.
# Returns (None, "a message") if this didn't work, or (version, vercode) for
@ -66,21 +63,25 @@ def check_market(app):
def main():
# Parse command line...
parser = OptionParser()
parser.add_option("-v", "--verbose", action="store_true", default=False,
#Read configuration...
execfile('config.py')
# Parse command line...
parser = OptionParser()
parser.add_option("-v", "--verbose", action="store_true", default=False,
help="Spew out even more information than normal")
parser.add_option("-p", "--package", default=None,
parser.add_option("-p", "--package", default=None,
help="Build only the specified package")
(options, args) = parser.parse_args()
(options, args) = parser.parse_args()
# Get all apps...
apps = common.read_metadata(options.verbose)
# Get all apps...
apps = common.read_metadata(options.verbose)
html_parser = HTMLParser.HTMLParser()
html_parser = HTMLParser.HTMLParser()
for app in apps:
for app in apps:
if options.package and options.package != app['id']:
# Silent skip...
@ -109,5 +110,8 @@ for app in apps:
metafile = os.path.join('metadata', app['id'] + '.txt')
common.write_metadata(metafile, app)
print "Finished."
print "Finished."
if __name__ == "__main__":
main()

146
import.py
View file

@ -25,46 +25,48 @@ import re
import urllib
from optparse import OptionParser
#Read configuration...
repo_name = None
repo_description = None
repo_icon = None
repo_url = None
execfile('config.py')
def main():
import common
# Read configuration...
repo_name = None
repo_description = None
repo_icon = None
repo_url = None
execfile('config.py')
# Parse command line...
parser = OptionParser()
parser.add_option("-u", "--url", default=None,
import common
# Parse command line...
parser = OptionParser()
parser.add_option("-u", "--url", default=None,
help="Project URL to import from.")
parser.add_option("-s", "--subdir", default=None,
parser.add_option("-s", "--subdir", default=None,
help="Path to main android project subdirectory, if not in root.")
(options, args) = parser.parse_args()
(options, args) = parser.parse_args()
if not options.url:
if not options.url:
print "Specify project url."
sys.exit(1)
url = options.url
url = options.url
tmp_dir = 'tmp'
if not os.path.isdir(tmp_dir):
tmp_dir = 'tmp'
if not os.path.isdir(tmp_dir):
print "Creating temporary directory"
os.makedirs(tmp_dir)
# Get all apps...
apps = common.read_metadata()
# Get all apps...
apps = common.read_metadata()
# Figure out what kind of project it is...
projecttype = None
issuetracker = None
license = None
if url.startswith('https://github.com'):
# Figure out what kind of project it is...
projecttype = None
issuetracker = None
license = None
if url.startswith('https://github.com'):
projecttype = 'github'
repo = url + '.git'
repotype = 'git'
sourcecode = url
elif url.startswith('http://code.google.com/p/'):
elif url.startswith('http://code.google.com/p/'):
if not url.endswith('/'):
print "Expected format for googlecode url is http://code.google.com/p/PROJECT/"
sys.exit(1)
@ -154,36 +156,36 @@ elif url.startswith('http://code.google.com/p/'):
print "License " + ltext + " is not recognised"
sys.exit(1)
if not projecttype:
if not projecttype:
print "Unable to determine the project type."
sys.exit(1)
# Get a copy of the source so we can extract some info...
print 'Getting source from ' + repotype + ' repo at ' + repo
src_dir = os.path.join(tmp_dir, 'importer')
if os.path.exists(tmp_dir):
# Get a copy of the source so we can extract some info...
print 'Getting source from ' + repotype + ' repo at ' + repo
src_dir = os.path.join(tmp_dir, 'importer')
if os.path.exists(tmp_dir):
shutil.rmtree(tmp_dir)
vcs = common.getvcs(repotype, repo, src_dir)
vcs.gotorevision(None)
if options.subdir:
vcs = common.getvcs(repotype, repo, src_dir)
vcs.gotorevision(None)
if options.subdir:
root_dir = os.path.join(src_dir, options.subdir)
else:
else:
root_dir = src_dir
# Check AndroidManiifest.xml exists...
manifest = os.path.join(root_dir, 'AndroidManifest.xml')
if not os.path.exists(manifest):
# Check AndroidManiifest.xml exists...
manifest = os.path.join(root_dir, 'AndroidManifest.xml')
if not os.path.exists(manifest):
print "AndroidManifest.xml did not exist in the expected location. Specify --subdir?"
sys.exit(1)
# Extract some information...
vcsearch = re.compile(r'.*android:versionCode="([^"]+)".*').search
vnsearch = re.compile(r'.*android:versionName="([^"]+)".*').search
psearch = re.compile(r'.*package="([^"]+)".*').search
version = None
vercode = None
package = None
for line in file(manifest):
# Extract some information...
vcsearch = re.compile(r'.*android:versionCode="([^"]+)".*').search
vnsearch = re.compile(r'.*android:versionName="([^"]+)".*').search
psearch = re.compile(r'.*package="([^"]+)".*').search
version = None
vercode = None
package = None
for line in file(manifest):
if not package:
matches = psearch(line)
if matches:
@ -196,48 +198,52 @@ for line in file(manifest):
matches = vcsearch(line)
if matches:
vercode = matches.group(1)
if not package:
if not package:
print "Couldn't find package ID"
sys.exit(1)
if not version:
if not version:
print "Couldn't find latest version name"
sys.exit(1)
if not vercode:
if not vercode:
print "Couldn't find latest version code"
sys.exit(1)
# Make sure it's actually new...
for app in apps:
# Make sure it's actually new...
for app in apps:
if app['id'] == package:
print "Package " + package + " already exists"
sys.exit(1)
# Construct the metadata...
app = common.parse_metadata(None)
app['id'] = package
app['Web Site'] = url
app['Source Code'] = sourcecode
if issuetracker:
# Construct the metadata...
app = common.parse_metadata(None)
app['id'] = package
app['Web Site'] = url
app['Source Code'] = sourcecode
if issuetracker:
app['Issue Tracker'] = issuetracker
if license:
if license:
app['License'] = license
app['Repo Type'] = repotype
app['Repo'] = repo
app['Repo Type'] = repotype
app['Repo'] = repo
# Create a build line...
build = {}
build['version'] = version
build['vercode'] = vercode
build['commit'] = '?'
if options.subdir:
# Create a build line...
build = {}
build['version'] = version
build['vercode'] = vercode
build['commit'] = '?'
if options.subdir:
build['subdir'] = options.subdir
if os.path.exists(os.path.join(root_dir, 'jni')):
if os.path.exists(os.path.join(root_dir, 'jni')):
build['buildjni'] = 'yes'
app['builds'].append(build)
app['comments'].append(('build:' + version,
app['builds'].append(build)
app['comments'].append(('build:' + version,
"#Generated by import.py - check this is the right version, and find the right commit!"))
metafile = os.path.join('metadata', package + '.txt')
common.write_metadata(metafile, app)
print "Wrote " + metafile
metafile = os.path.join('metadata', package + '.txt')
common.write_metadata(metafile, app)
print "Wrote " + metafile
if __name__ == "__main__":
main()

View file

@ -31,38 +31,40 @@ from optparse import OptionParser
import common
from common import BuildException
#Read configuration...
execfile('config.py')
def main():
# Parse command line...
parser = OptionParser()
parser.add_option("-v", "--verbose", action="store_true", default=False,
#Read configuration...
execfile('config.py')
# Parse command line...
parser = OptionParser()
parser.add_option("-v", "--verbose", action="store_true", default=False,
help="Spew out even more information than normal")
parser.add_option("-p", "--package", default=None,
parser.add_option("-p", "--package", default=None,
help="Publish only the specified package")
(options, args) = parser.parse_args()
(options, args) = parser.parse_args()
log_dir = 'logs'
if not os.path.isdir(log_dir):
log_dir = 'logs'
if not os.path.isdir(log_dir):
print "Creating log directory"
os.makedirs(log_dir)
tmp_dir = 'tmp'
if not os.path.isdir(tmp_dir):
tmp_dir = 'tmp'
if not os.path.isdir(tmp_dir):
print "Creating temporary directory"
os.makedirs(tmp_dir)
output_dir = 'repo'
if not os.path.isdir(output_dir):
output_dir = 'repo'
if not os.path.isdir(output_dir):
print "Creating output directory"
os.makedirs(output_dir)
unsigned_dir = 'unsigned'
if not os.path.isdir(unsigned_dir):
unsigned_dir = 'unsigned'
if not os.path.isdir(unsigned_dir):
print "No unsigned directory - nothing to do"
sys.exit(0)
for apkfile in sorted(glob.glob(os.path.join(unsigned_dir, '*.apk'))):
for apkfile in sorted(glob.glob(os.path.join(unsigned_dir, '*.apk'))):
apkfilename = os.path.basename(apkfile)
i = apkfilename.rfind('_')
@ -134,3 +136,7 @@ for apkfile in sorted(glob.glob(os.path.join(unsigned_dir, '*.apk'))):
print 'Published ' + apkfilename
if __name__ == "__main__":
main()

View file

@ -27,22 +27,26 @@ from optparse import OptionParser
import HTMLParser
import common
#Read configuration...
execfile('config.py')
def main():
#Read configuration...
execfile('config.py')
# Parse command line...
parser = OptionParser()
parser.add_option("-v", "--verbose", action="store_true", default=False,
# Parse command line...
parser = OptionParser()
parser.add_option("-v", "--verbose", action="store_true", default=False,
help="Spew out even more information than normal")
(options, args) = parser.parse_args()
(options, args) = parser.parse_args()
# Get all apps...
apps = common.read_metadata(options.verbose)
# Get all apps...
apps = common.read_metadata(options.verbose)
for app in apps:
for app in apps:
print "Writing " + app['id']
common.write_metadata(os.path.join('metadata', app['id']) + '.txt', app)
print "Finished."
print "Finished."
if __name__ == "__main__":
main()

View file

@ -31,28 +31,30 @@ import common
from common import BuildException
from common import VCSException
#Read configuration...
execfile('config.py')
def main():
# Read configuration...
execfile('config.py')
# Parse command line...
parser = OptionParser()
parser.add_option("-v", "--verbose", action="store_true", default=False,
# Parse command line...
parser = OptionParser()
parser.add_option("-v", "--verbose", action="store_true", default=False,
help="Spew out even more information than normal")
parser.add_option("-p", "--package", default=None,
parser.add_option("-p", "--package", default=None,
help="Scan only the specified package")
(options, args) = parser.parse_args()
(options, args) = parser.parse_args()
# Get all apps...
apps = common.read_metadata(options.verbose)
# Get all apps...
apps = common.read_metadata(options.verbose)
html_parser = HTMLParser.HTMLParser()
html_parser = HTMLParser.HTMLParser()
problems = []
problems = []
extlib_dir = os.path.join('build', 'extlib')
extlib_dir = os.path.join('build', 'extlib')
for app in apps:
for app in apps:
skip = False
if options.package and app['id'] != options.package:
@ -103,8 +105,11 @@ for app in apps:
msg = "Could not scan app %s due to unknown error: %s" % (app['id'], traceback.format_exc())
problems.append(msg)
print "Finished:"
for problem in problems:
print "Finished:"
for problem in problems:
print problem
print str(len(problems)) + ' problems.'
print str(len(problems)) + ' problems.'
if __name__ == "__main__":
main()

177
update.py
View file

@ -29,63 +29,65 @@ from xml.dom.minidom import Document
from optparse import OptionParser
import time
#Read configuration...
repo_name = None
repo_description = None
repo_icon = None
repo_url = None
execfile('config.py')
def main():
import common
# Read configuration...
repo_name = None
repo_description = None
repo_icon = None
repo_url = None
execfile('config.py')
# Parse command line...
parser = OptionParser()
parser.add_option("-c", "--createmeta", action="store_true", default=False,
import common
# Parse command line...
parser = OptionParser()
parser.add_option("-c", "--createmeta", action="store_true", default=False,
help="Create skeleton metadata files that are missing")
parser.add_option("-v", "--verbose", action="store_true", default=False,
parser.add_option("-v", "--verbose", action="store_true", default=False,
help="Spew out even more information than normal")
parser.add_option("-q", "--quiet", action="store_true", default=False,
parser.add_option("-q", "--quiet", action="store_true", default=False,
help="No output, except for warnings and errors")
parser.add_option("-b", "--buildreport", action="store_true", default=False,
parser.add_option("-b", "--buildreport", action="store_true", default=False,
help="Report on build data status")
parser.add_option("-i", "--interactive", default=False, action="store_true",
parser.add_option("-i", "--interactive", default=False, action="store_true",
help="Interactively ask about things that need updating.")
parser.add_option("-e", "--editor", default="/etc/alternatives/editor",
parser.add_option("-e", "--editor", default="/etc/alternatives/editor",
help="Specify editor to use in interactive mode. Default "+
"is /etc/alternatives/editor")
parser.add_option("", "--pretty", action="store_true", default=False,
parser.add_option("", "--pretty", action="store_true", default=False,
help="Produce human-readable index.xml")
(options, args) = parser.parse_args()
(options, args) = parser.parse_args()
icon_dir=os.path.join('repo','icons')
icon_dir=os.path.join('repo','icons')
# Delete and re-create the icon directory...
if os.path.exists(icon_dir):
# Delete and re-create the icon directory...
if os.path.exists(icon_dir):
shutil.rmtree(icon_dir)
os.mkdir(icon_dir)
os.mkdir(icon_dir)
warnings = 0
warnings = 0
#Make sure we have the repository description...
if (repo_url is None or repo_name is None or
# Make sure we have the repository description...
if (repo_url is None or repo_name is None or
repo_icon is None or repo_description is None):
print "Repository description fields are required in config.py"
print "See config.sample.py for details"
sys.exit(1)
# Get all apps...
apps = common.read_metadata(verbose=options.verbose)
# Get all apps...
apps = common.read_metadata(verbose=options.verbose)
# Generate a list of categories...
categories = []
for app in apps:
# Generate a list of categories...
categories = []
for app in apps:
if app['Category'] not in categories:
categories.append(app['Category'])
# Gather information about all the apk files in the repo directory...
apks = []
for apkfile in glob.glob(os.path.join('repo','*.apk')):
# Gather information about all the apk files in the repo directory...
apks = []
for apkfile in glob.glob(os.path.join('repo','*.apk')):
apkfilename = apkfile[5:]
if apkfilename.find(' ') != -1:
@ -194,9 +196,9 @@ for apkfile in glob.glob(os.path.join('repo','*.apk')):
apks.append(thisinfo)
# Some information from the apks needs to be applied up to the application
# level. When doing this, we use the info from the most recent version's apk.
for app in apps:
# Some information from the apks needs to be applied up to the application
# level. When doing this, we use the info from the most recent version's apk.
for app in apps:
bestver = 0
for apk in apks:
if apk['id'] == app['id']:
@ -215,9 +217,9 @@ for app in apps:
app['Name'] = bestapk['name']
app['icon'] = bestapk['icon']
# Generate warnings for apk's with no metadata (or create skeleton
# metadata files, if requested on the command line)
for apk in apks:
# Generate warnings for apk's with no metadata (or create skeleton
# metadata files, if requested on the command line)
for apk in apks:
found = False
for app in apps:
if app['id'] == apk['id']:
@ -240,26 +242,26 @@ for apk in apks:
print "WARNING: " + apk['apkname'] + " (" + apk['id'] + ") has no metadata"
print " " + apk['name'] + " - " + apk['version']
#Sort the app list by name, then the web site doesn't have to by default:
apps = sorted(apps, key=lambda app: app['Name'].upper())
#Sort the app list by name, then the web site doesn't have to by default:
apps = sorted(apps, key=lambda app: app['Name'].upper())
# Create the index
doc = Document()
# Create the index
doc = Document()
def addElement(name, value, doc, parent):
def addElement(name, value, doc, parent):
el = doc.createElement(name)
el.appendChild(doc.createTextNode(value))
parent.appendChild(el)
root = doc.createElement("fdroid")
doc.appendChild(root)
root = doc.createElement("fdroid")
doc.appendChild(root)
repoel = doc.createElement("repo")
repoel.setAttribute("name", repo_name)
repoel.setAttribute("icon", os.path.basename(repo_icon))
repoel.setAttribute("url", repo_url)
repoel = doc.createElement("repo")
repoel.setAttribute("name", repo_name)
repoel.setAttribute("icon", os.path.basename(repo_icon))
repoel.setAttribute("url", repo_url)
if repo_keyalias != None:
if repo_keyalias != None:
# Generate a certificate fingerprint the same way keytool does it
# (but with slightly different formatting)
@ -286,14 +288,14 @@ if repo_keyalias != None:
repoel.setAttribute("pubkey", extract_pubkey())
addElement('description', repo_description, doc, repoel)
root.appendChild(repoel)
addElement('description', repo_description, doc, repoel)
root.appendChild(repoel)
apps_inrepo = 0
apps_disabled = 0
apps_nopkg = 0
apps_inrepo = 0
apps_disabled = 0
apps_nopkg = 0
for app in apps:
for app in apps:
if app['Disabled'] is None:
@ -440,15 +442,15 @@ for app in apps:
else:
apps_disabled += 1
of = open(os.path.join('repo','index.xml'), 'wb')
if options.pretty:
of = open(os.path.join('repo','index.xml'), 'wb')
if options.pretty:
output = doc.toprettyxml()
else:
else:
output = doc.toxml()
of.write(output)
of.close()
of.write(output)
of.close()
if repo_keyalias != None:
if repo_keyalias != None:
if not options.quiet:
print "Creating signed index."
@ -476,27 +478,27 @@ if repo_keyalias != None:
if options.verbose:
print output
# Copy the repo icon into the repo directory...
iconfilename = os.path.join(icon_dir, os.path.basename(repo_icon))
shutil.copyfile(repo_icon, iconfilename)
# Copy the repo icon into the repo directory...
iconfilename = os.path.join(icon_dir, os.path.basename(repo_icon))
shutil.copyfile(repo_icon, iconfilename)
# Write a category list in the repo to allow quick access...
catdata = ''
for cat in categories:
# Write a category list in the repo to allow quick access...
catdata = ''
for cat in categories:
catdata += cat + '\n'
f = open('repo/categories.txt', 'w')
f.write(catdata)
f.close()
f = open('repo/categories.txt', 'w')
f.write(catdata)
f.close()
# Update known apks info...
knownapks = common.KnownApks()
for apk in apks:
# Update known apks info...
knownapks = common.KnownApks()
for apk in apks:
knownapks.recordapk(apk['apkname'], apk['id'])
knownapks.writeifchanged()
knownapks.writeifchanged()
# Generate latest apps data for widget
data = ''
for line in file(os.path.join('stats', 'latestapps.txt')):
# Generate latest apps data for widget
data = ''
for line in file(os.path.join('stats', 'latestapps.txt')):
appid = line.rstrip()
data += appid + "\t"
for app in apps:
@ -505,15 +507,18 @@ for line in file(os.path.join('stats', 'latestapps.txt')):
data += app['icon'] + "\t"
data += app['License'] + "\n"
break
f = open('repo/latestapps.dat', 'w')
f.write(data)
f.close()
f = open('repo/latestapps.dat', 'w')
f.write(data)
f.close()
print "Finished."
print str(apps_inrepo) + " apps in repo"
print str(apps_disabled) + " disabled"
print str(apps_nopkg) + " with no packages"
print str(warnings) + " warnings"
print "Finished."
print str(apps_inrepo) + " apps in repo"
print str(apps_disabled) + " disabled"
print str(apps_nopkg) + " with no packages"
print str(warnings) + " warnings"
if __name__ == "__main__":
main()

View file

@ -30,31 +30,32 @@ import HTMLParser
import paramiko
import common
#Read configuration...
execfile('config.py')
def main():
# Read configuration...
execfile('config.py')
# Parse command line...
parser = OptionParser()
parser.add_option("-v", "--verbose", action="store_true", default=False,
# Parse command line...
parser = OptionParser()
parser.add_option("-v", "--verbose", action="store_true", default=False,
help="Spew out even more information than normal")
parser.add_option("-d", "--download", action="store_true", default=False,
parser.add_option("-d", "--download", action="store_true", default=False,
help="Download logs we don't have")
(options, args) = parser.parse_args()
(options, args) = parser.parse_args()
statsdir = 'stats'
logsdir = os.path.join(statsdir, 'logs')
logsarchivedir = os.path.join(logsdir, 'archive')
datadir = os.path.join(statsdir, 'data')
if not os.path.exists(statsdir):
statsdir = 'stats'
logsdir = os.path.join(statsdir, 'logs')
logsarchivedir = os.path.join(logsdir, 'archive')
datadir = os.path.join(statsdir, 'data')
if not os.path.exists(statsdir):
os.mkdir(statsdir)
if not os.path.exists(logsdir):
if not os.path.exists(logsdir):
os.mkdir(logsdir)
if not os.path.exists(datadir):
if not os.path.exists(datadir):
os.mkdir(datadir)
if options.download:
if options.download:
# Get any access logs we don't have...
ssh = None
ftp = None
@ -96,13 +97,13 @@ if options.download:
if ssh != None:
ssh.close()
# Process logs
logexpr = '(?P<ip>[.:0-9a-fA-F]+) - - \[(?P<time>.*?)\] "GET (?P<uri>.*?) HTTP/1.\d" (?P<statuscode>\d+) \d+ "(?P<referral>.*?)" "(?P<useragent>.*?)"'
logsearch = re.compile(logexpr).search
apps = {}
unknownapks = []
knownapks = common.KnownApks()
for logfile in glob.glob(os.path.join(logsdir,'access-*.log')):
# Process logs
logexpr = '(?P<ip>[.:0-9a-fA-F]+) - - \[(?P<time>.*?)\] "GET (?P<uri>.*?) HTTP/1.\d" (?P<statuscode>\d+) \d+ "(?P<referral>.*?)" "(?P<useragent>.*?)"'
logsearch = re.compile(logexpr).search
apps = {}
unknownapks = []
knownapks = common.KnownApks()
for logfile in glob.glob(os.path.join(logsdir,'access-*.log')):
logdate = logfile[len(logsdir) + 1 + len('access-'):-4]
matches = (logsearch(line) for line in file(logfile))
for match in matches:
@ -121,30 +122,33 @@ for logfile in glob.glob(os.path.join(logsdir,'access-*.log')):
if not apkname in unknownapks:
unknownapks.append(apkname)
# Calculate and write stats for total downloads...
f = open('stats/total_downloads_app.txt', 'w')
lst = []
alldownloads = 0
for app, count in apps.iteritems():
# Calculate and write stats for total downloads...
f = open('stats/total_downloads_app.txt', 'w')
lst = []
alldownloads = 0
for app, count in apps.iteritems():
lst.append(app + " " + str(count))
alldownloads += count
lst.append("ALL " + str(alldownloads))
f.write('# Total downloads by application, since October 2011\n')
for line in sorted(lst):
lst.append("ALL " + str(alldownloads))
f.write('# Total downloads by application, since October 2011\n')
for line in sorted(lst):
f.write(line + '\n')
f.close()
f.close()
# Write list of latest apps added to the repo...
latest = knownapks.getlatest(10)
f = open('stats/latestapps.txt', 'w')
for app in latest:
# Write list of latest apps added to the repo...
latest = knownapks.getlatest(10)
f = open('stats/latestapps.txt', 'w')
for app in latest:
f.write(app + '\n')
f.close()
f.close()
if len(unknownapks) > 0:
if len(unknownapks) > 0:
print '\nUnknown apks:'
for apk in unknownapks:
print apk
print "Finished."
print "Finished."
if __name__ == "__main__":
main()