]> git.rkrishnan.org Git - tahoe-lafs/zfec.git/blobdiff - zfec/zfec/cmdline_zfec.py
M-x whitespace-cleanup
[tahoe-lafs/zfec.git] / zfec / zfec / cmdline_zfec.py
index ec5ec17d1ec5a24979720c4682d3f43afcde493a..c1389be63bb3378f1c8cb4d58b0e9a0cf581830c 100755 (executable)
@@ -3,16 +3,16 @@
 # zfec -- a fast C implementation of Reed-Solomon erasure coding with
 # command-line, C, and Python interfaces
 
-# The zfec and zunfec command-line tools require Python 2.5 for relative imports.
-
 import sys
 
-from util import argparse
+import argparse
 import filefec
 
 from zfec import __version__ as libversion
-from util.version import Version
-__version__ = Version("1.0.0a1-0-STABLE")
+__version__ = libversion
+
+DEFAULT_K=3
+DEFAULT_M=8
 
 def main():
 
@@ -27,10 +27,11 @@ def main():
     parser.add_argument('-d', '--output-dir', help='directory in which share file names will be created (default ".")', default='.', metavar='D')
     parser.add_argument('-p', '--prefix', help='prefix for share file names; If omitted, the name of the input file will be used.', metavar='P')
     parser.add_argument('-s', '--suffix', help='suffix for share file names (default ".fec")', default='.fec', metavar='S')
-    parser.add_argument('-m', '--totalshares', help='the total number of share files created (default 16)', default=16, type=int, metavar='M')
-    parser.add_argument('-k', '--requiredshares', help='the number of share files required to reconstruct (default 4)', default=4, type=int, metavar='K')
+    parser.add_argument('-m', '--totalshares', help='the total number of share files created (default %d)' % DEFAULT_M, default=DEFAULT_M, type=int, metavar='M')
+    parser.add_argument('-k', '--requiredshares', help='the number of share files required to reconstruct (default %d)' % DEFAULT_K, default=DEFAULT_K, type=int, metavar='K')
     parser.add_argument('-f', '--force', help='overwrite any file which already in place an output file (share file)', action='store_true')
     parser.add_argument('-v', '--verbose', help='print out messages about progress', action='store_true')
+    parser.add_argument('-q', '--quiet', help='quiet progress indications and warnings about silly choices of K and M', action='store_true')
     parser.add_argument('-V', '--version', help='print out version number and exit', action='store_true')
     args = parser.parse_args()
 
@@ -39,39 +40,33 @@ def main():
         if args.prefix == "<stdin>":
             args.prefix = ""
 
-    if args.totalshares < 3:
-        print "Invalid parameters, totalshares is required to be >= 3\nPlease see the accompanying documentation."
+    if args.verbose and args.quiet:
+        print "Please choose only one of --verbose and --quiet."
         sys.exit(1)
-    if args.totalshares > 256:
-        print "Invalid parameters, totalshares is required to be <= 256\nPlease see the accompanying documentation."
-        sys.exit(1)
-    if args.requiredshares < 2:
-        print "Invalid parameters, requiredshares is required to be >= 2\nPlease see the accompanying documentation."
+
+    if args.totalshares > 256 or args.totalshares < 1:
+        print "Invalid parameters, totalshares is required to be <= 256 and >= 1\nPlease see the accompanying documentation."
         sys.exit(1)
-    if args.requiredshares >= args.totalshares:
-        print "Invalid parameters, requiredshares is required to be < totalshares\nPlease see the accompanying documentation."
+    if args.requiredshares > args.totalshares or args.requiredshares < 1:
+        print "Invalid parameters, requiredshares is required to be <= totalshares and >= 1\nPlease see the accompanying documentation."
         sys.exit(1)
 
+    if not args.quiet:
+        if args.requiredshares == 1:
+            print "warning: silly parameters: requiredshares == 1, which means that every share will be a complete copy of the file.  You could use \"cp\" for the same effect.  But proceeding to do it anyway..."
+        if args.requiredshares == args.totalshares:
+            print "warning: silly parameters: requiredshares == totalshares, which means that all shares will be required in order to reconstruct the file.  You could use \"split\" for the same effect.  But proceeding to do it anyway..."
+
     args.inputfile.seek(0, 2)
     fsize = args.inputfile.tell()
     args.inputfile.seek(0, 0)
     return filefec.encode_to_files(args.inputfile, fsize, args.output_dir, args.prefix, args.requiredshares, args.totalshares, args.suffix, args.force, args.verbose)
 
 # zfec -- fast forward error correction library with Python interface
-# 
+#
 # Copyright (C) 2007 Allmydata, Inc.
 # Author: Zooko Wilcox-O'Hearn
-# 
+#
 # This file is part of zfec.
-# 
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the Free
-# Software Foundation; either version 2 of the License, or (at your option)
-# any later version, with the added permission that, if you become obligated
-# to release a derived work under this licence (as per section 2.b), you may
-# delay the fulfillment of this obligation for up to 12 months.  See the file
-# COPYING for details.
 #
-# If you would like to inquire about a commercial relationship with Allmydata,
-# Inc., please contact partnerships@allmydata.com and visit
-# http://allmydata.com/.
+# See README.txt for licensing information.