# HG changeset patch # User Atul Varma # Date 1228772254 28800 # Node ID 05cece4371a40ed9110cf6d7ab56242cb0b66a93 # Parent cb08fb8f0e875c96ce102eb1759605fe8c3a7a55 Added an undo option, though it's not implemented yet. diff -r cb08fb8f0e87 -r 05cece4371a4 kharon.py --- a/kharon.py Mon Dec 08 13:27:07 2008 -0800 +++ b/kharon.py Mon Dec 08 13:37:34 2008 -0800 @@ -42,6 +42,9 @@ shell('mkdir', HADES_DIR) parser = OptionParser() + parser.add_option('-u', '--undo', + dest='undo', action='store_true', default=False, + help='undo a transaction (default is latest).') (options, args) = parser.parse_args() if not args: @@ -49,23 +52,27 @@ sys.exit(-1) config = Config(STATE_FILENAME) - files = [] - for arg in args: - filename = os.path.abspath(os.path.expanduser(arg)) - if not os.path.exists(filename): - print('File does not exist: %s' % arg) - sys.exit(-1) - files.append(filename) + + if options.undo: + raise NotImplementedError('Undo not implemented yet.') + else: + files = [] + for arg in args: + filename = os.path.abspath(os.path.expanduser(arg)) + if not os.path.exists(filename): + print('File does not exist: %s' % arg) + sys.exit(-1) + files.append(filename) - thisid = config.nextid - basedir = os.path.join(HADES_DIR, '%.9d' % thisid) - shell('mkdir', basedir) - config.nextid = thisid + 1 - config.save() + thisid = config.nextid + basedir = os.path.join(HADES_DIR, '%.9d' % thisid) + shell('mkdir', basedir) + config.nextid = thisid + 1 + config.save() - print("Creating transaction %d." % thisid) + print("Creating transaction %d." % thisid) - for source in files: - dest = os.path.join(basedir, filename[1:]) - distutils.dir_util.mkpath(os.path.dirname(dest)) - shell('mv', source, dest) + for source in files: + dest = os.path.join(basedir, filename[1:]) + distutils.dir_util.mkpath(os.path.dirname(dest)) + shell('mv', source, dest)