chiark / gitweb /
Add a -v option.
authorSimon Tatham <anakin@pobox.com>
Fri, 14 Mar 2014 22:58:47 +0000 (22:58 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 14 Mar 2014 22:59:39 +0000 (22:59 +0000)
partition.py

index d0c0dd6b66f4670f2683a389eef7caa47a17f390..c8c7db74d9dae4c188b00c193fd1a6a5bbd73bdc 100755 (executable)
@@ -1,11 +1,13 @@
 #!/usr/bin/env python
 
-import sys, subprocess, math
+import sys, subprocess, math, getopt
 from fractions import Fraction
 
+verbose = False
 def vprint(*args):
     # In verbose mode, print diagnostics.
-    pass # FIXME: implement verbose mode
+    if verbose:
+        sys.stdout.write(" ".join(map(str,args)) + "\n")
 
 def find_partitions(n, minfrag, maxfrag=None, prefix=(), ret=None):
     """Find all partitions of n into integer pieces at least minfrag.
@@ -145,7 +147,14 @@ def search_and_report(n, m):
         print "    %d x (%s)" % (count, " + ".join([str(Fraction(k,d)) for k in col]))
 
 def main():
-    m, n = sorted(map(int,sys.argv[1:3]))
+    global verbose
+    opts, args = getopt.gnu_getopt(sys.argv[1:], "v")
+    for opt, val in opts:
+        if opt == "-v":
+            verbose = True
+        else:
+            assert False, "unrecognised option '%s'" % opt
+    m, n = sorted(map(int,args[:2]))
     search_and_report(n, m)
 
 if __name__ == "__main__":