tahoe-lafs/pyfec/bin/unfec

50 lines
1.7 KiB
Python

#!/usr/bin/env python
# import bindann
# import bindann.monkeypatch.all
import os, sys
from fec.util import argparse
import fec
from fec import filefec
from fec.util.version import Version
__version__ = Version("1.0.0a1-0-STABLE")
if '-V' in sys.argv or '--version' in sys.argv:
print "pyfec library version: ", fec.__version__
print "fec command-line tool version: ", __version__
sys.exit(0)
parser = argparse.ArgumentParser(description="Decode data from share files.")
parser.add_argument('-o', '--outputfile', required=True, help='file to write the resulting data to, or "-" for stdout', type=str, metavar='OUTF')
parser.add_argument('sharefiles', nargs='*', help='shares file to read the encoded data from', type=argparse.FileType('rb'), metavar='SHAREFILE')
parser.add_argument('-v', '--verbose', help='print out messages about progress', action='store_true')
parser.add_argument('-f', '--force', help='overwrite any file which already in place of the output file', action='store_true')
parser.add_argument('-V', '--version', help='print out version number and exit', action='store_true')
args = parser.parse_args()
if len(args.sharefiles) < 2:
print "At least two sharefiles are required."
sys.exit(1)
if args.force:
outf = open(args.outputfile, 'wb')
else:
try:
outfd = os.open(args.outputfile, os.O_WRONLY|os.O_CREAT|os.O_EXCL)
except OSError:
print "There is already a file named %r -- aborting. Use --force to overwrite." % (args.outputfile,)
sys.exit(2)
outf = os.fdopen(outfd, "wb")
try:
ret = filefec.decode_from_files(outf, args.sharefiles, args.verbose)
except filefec.InsufficientShareFilesError, e:
print str(e)
sys.exit(3)
sys.exit(ret)