From 1e3c2eee25bd2b117d92779f89a8c827486e83d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 27 Jan 2014 17:08:54 +0100 Subject: [PATCH] More logging switching --- fdroidserver/install.py | 23 +++++++++++++---------- fdroidserver/lint.py | 5 +++-- fdroidserver/publish.py | 22 +++++++++++----------- fdroidserver/server.py | 5 +++-- fdroidserver/verify.py | 4 ++-- 5 files changed, 32 insertions(+), 27 deletions(-) diff --git a/fdroidserver/install.py b/fdroidserver/install.py index 66be0663..fccc5c2c 100644 --- a/fdroidserver/install.py +++ b/fdroidserver/install.py @@ -22,6 +22,7 @@ import sys import os import glob from optparse import OptionParser, OptionError +import logging import common from common import FDroidPopen @@ -61,7 +62,7 @@ def main(): output_dir = 'repo' if not os.path.isdir(output_dir): - print "No signed output directory - nothing to do" + logging.info("No signed output directory - nothing to do") sys.exit(0) if args: @@ -93,22 +94,24 @@ def main(): devs = devices() if not devs: raise Exception("No attached devices found") - print "Installing %s..." % apk + logging.info("Installing %s..." % apk) for dev in devs: - print "Installing %s on %s..." % (apk, dev) + logging.info("Installing %s on %s..." % (apk, dev)) p = FDroidPopen(["adb", "-s", dev, "install", apk ]) fail= "" for line in p.stdout.splitlines(): if line.startswith("Failure"): fail = line[9:-1] - if fail: - if fail == "INSTALL_FAILED_ALREADY_EXISTS": - print "%s is already installed on %s." % (apk, dev) - else: - raise Exception("Failed to install %s on %s: %s" % ( - apk, dev, fail)) + if not fail: + continue - print "\nFinished" + if fail == "INSTALL_FAILED_ALREADY_EXISTS": + logging.warn("%s is already installed on %s." % (apk, dev)) + else: + raise Exception("Failed to install %s on %s: %s" % ( + apk, dev, fail)) + + logging.info("\nFinished") if __name__ == "__main__": main() diff --git a/fdroidserver/lint.py b/fdroidserver/lint.py index df8104ba..da6a5234 100644 --- a/fdroidserver/lint.py +++ b/fdroidserver/lint.py @@ -19,6 +19,7 @@ from optparse import OptionParser import re +import logging import common, metadata config = None @@ -31,7 +32,7 @@ def warn(message): if appid: print "%s:" % appid appid = None - print(' %s' % message) + print ' %s' % message def main(): @@ -136,7 +137,7 @@ def main(): if not appid: print - print "Finished." + logging.info("Finished.") if __name__ == "__main__": main() diff --git a/fdroidserver/publish.py b/fdroidserver/publish.py index 35c6c9c1..1d8d8dba 100644 --- a/fdroidserver/publish.py +++ b/fdroidserver/publish.py @@ -24,6 +24,7 @@ import shutil import md5 import glob from optparse import OptionParser +import logging import common, metadata from common import FDroidPopen, BuildException @@ -45,22 +46,22 @@ def main(): log_dir = 'logs' if not os.path.isdir(log_dir): - print "Creating log directory" + logging.info("Creating log directory") os.makedirs(log_dir) tmp_dir = 'tmp' if not os.path.isdir(tmp_dir): - print "Creating temporary directory" + logging.info("Creating temporary directory") os.makedirs(tmp_dir) output_dir = 'repo' if not os.path.isdir(output_dir): - print "Creating output directory" + logging.info("Creating output directory") os.makedirs(output_dir) unsigned_dir = 'unsigned' if not os.path.isdir(unsigned_dir): - print "No unsigned directory - nothing to do" + logging.info("No unsigned directory - nothing to do") sys.exit(0) # It was suggested at https://dev.guardianproject.info/projects/bazaar/wiki/FDroid_Audit @@ -79,11 +80,10 @@ def main(): m.update(app['id']) keyalias = m.hexdigest()[:8] if keyalias in allaliases: - print "There is a keyalias collision - publishing halted" + logging.info("There is a keyalias collision - publishing halted") sys.exit(1) allaliases.append(keyalias) - if options.verbose: - print "{0} apps, {0} key aliases".format(len(allapps), len(allaliases)) + logging.info("{0} apps, {0} key aliases".format(len(allapps), len(allaliases))) # Process any apks that are waiting to be signed... for apkfile in sorted(glob.glob(os.path.join(unsigned_dir, '*.apk'))): @@ -95,7 +95,7 @@ def main(): if appid in vercodes and vercodes[appid]: if vercode not in vercodes[appid]: continue - print "Processing " + apkfile + logging.info("Processing " + apkfile) # Figure out the key alias name we'll use. Only the first 8 # characters are significant, so we'll use the first 8 from @@ -114,7 +114,7 @@ def main(): m = md5.new() m.update(appid) keyalias = m.hexdigest()[:8] - print "Key alias: " + keyalias + logging.info("Key alias: " + keyalias) # See if we already have a key for this application, and # if not generate one... @@ -122,7 +122,7 @@ def main(): '-alias', keyalias, '-keystore', config['keystore'], '-storepass', config['keystorepass']]) if p.returncode !=0: - print "Key does not exist - generating..." + logging.info("Key does not exist - generating...") p = FDroidPopen(['keytool', '-genkey', '-keystore', config['keystore'], '-alias', keyalias, '-keyalg', 'RSA', '-keysize', '2048', @@ -155,7 +155,7 @@ def main(): shutil.move(os.path.join(unsigned_dir, tarfilename), os.path.join(output_dir, tarfilename)) - print 'Published ' + apkfilename + logging.info('Published ' + apkfilename) if __name__ == "__main__": diff --git a/fdroidserver/server.py b/fdroidserver/server.py index 43ea05fd..f04dc264 100644 --- a/fdroidserver/server.py +++ b/fdroidserver/server.py @@ -21,6 +21,7 @@ import sys import os import subprocess from optparse import OptionParser +import logging import common config = None @@ -40,11 +41,11 @@ def main(): config = common.read_config(options) if len(args) != 1: - print "Specify a single command" + logging.critical("Specify a single command") sys.exit(1) if args[0] != 'init' and args[0] != 'update': - print "The only commands currently supported are 'init' and 'update'" + logging.critical("The only commands currently supported are 'init' and 'update'") sys.exit(1) serverwebroot = config['serverwebroot'].rstrip('/').replace('//', '/') diff --git a/fdroidserver/verify.py b/fdroidserver/verify.py index 0192f713..4c99f4ad 100644 --- a/fdroidserver/verify.py +++ b/fdroidserver/verify.py @@ -109,8 +109,8 @@ def main(): notverified += 1 logging.info("Finished") - print "{0} successfully verified".format(verified) - print "{0} NOT verified".format(notverified) + logging.info("{0} successfully verified".format(verified)) + logging.info("{0} NOT verified".format(notverified)) if __name__ == "__main__": main()