chiark / gitweb /
fdroid: python2 doesn't like print()
[fdroidserver.git] / fdroid
diff --git a/fdroid b/fdroid
index 91dc992925d647bec40b9702ce2d4a774bfd4db3..0774aeb85e49957aa895713612719e318e5a7f67 100755 (executable)
--- a/fdroid
+++ b/fdroid
@@ -22,7 +22,8 @@ import sys
 import logging
 
 import fdroidserver.common
-from optparse import OptionError
+import fdroidserver.metadata
+from argparse import ArgumentError
 
 commands = {
     "build": "Build a package from source",
@@ -45,12 +46,12 @@ 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():
@@ -91,19 +92,22 @@ 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")
@@ -118,13 +122,14 @@ def main():
     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:
             logging.critical(str(e))
         sys.exit(1)
-    except OptionError, e:
+    except ArgumentError as e:
         logging.critical(str(e))
         sys.exit(1)
     except KeyboardInterrupt:
@@ -132,7 +137,7 @@ def main():
         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)