Mercurial > hrm
changeset 2:05cece4371a4
Added an undo option, though it's not implemented yet.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 08 Dec 2008 13:37:34 -0800 |
parents | cb08fb8f0e87 |
children | 4734efec5732 |
files | kharon.py |
diffstat | 1 files changed, 24 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- 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)