import logging
import fdroidserver.common
+import fdroidserver.metadata
from argparse import ArgumentError
commands = {
def print_help():
- print "usage: fdroid [-h|--help|--version] <command> [<args>]"
- print
- print "Valid commands are:"
+ print("usage: fdroid [-h|--help|--version] <command> [<args>]")
+ print("")
+ print("Valid commands are:")
for cmd, summary in commands.items():
- print " " + cmd + ' ' * (15 - len(cmd)) + summary
- print
+ print(" " + cmd + ' ' * (15 - len(cmd)) + summary)
+ print()
def main():
print(output),
sys.exit(0)
else:
- print "Command '%s' not recognised.\n" % command
+ print("Command '%s' not recognised.\n" % command)
print_help()
sys.exit(1)
verbose = any(s in sys.argv for s in ['-v', '--verbose'])
quiet = any(s in sys.argv for s in ['-q', '--quiet'])
+ # Helpful to differentiate warnings from errors even when on quiet
+ logformat = '%(levelname)s: %(message)s'
+ loglevel = logging.INFO
if verbose:
- logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
+ loglevel = logging.DEBUG
elif quiet:
- logging.basicConfig(format='%(message)s', level=logging.WARN)
- else:
- logging.basicConfig(format='%(message)s', level=logging.INFO)
+ loglevel = logging.WARN
+
+ logging.basicConfig(format=logformat, level=loglevel)
if verbose and quiet:
logging.critical("Specifying --verbose and --quiet and the same time is silly")
try:
mod.main()
# These are ours, contain a proper message and are "expected"
- except fdroidserver.common.FDroidException, e:
+ except (fdroidserver.common.FDroidException,
+ fdroidserver.metadata.MetaDataException) as e:
if verbose:
raise
else:
sys.exit(1)
# These should only be unexpected crashes due to bugs in the code
# str(e) often doesn't contain a reason, so just show the backtrace
- except Exception, e:
+ except Exception as e:
logging.critical("Unknown exception found!")
raise
sys.exit(0)