# HG changeset patch # User Atul Varma # Date 1228775526 28800 # Node ID 702b55be90305d1c0e316642b2ed03072e6d7556 # Parent 4734efec5732ad0c3871457cb21d40a90ae5f1e4 Added more of an implementation for undo, although it's still unimplemented. diff -r 4734efec5732 -r 702b55be9030 kharon.py --- a/kharon.py Mon Dec 08 13:50:08 2008 -0800 +++ b/kharon.py Mon Dec 08 14:32:06 2008 -0800 @@ -37,6 +37,9 @@ if popen.returncode: raise Exception('Process failed: %s' % repr(params)) +def dir_for_trans(transid): + return os.path.join(HADES_DIR, '%.9d' % transid) + if __name__ == '__main__': if not (os.path.exists(HADES_DIR) and os.path.isdir(HADES_DIR)): shell('mkdir', HADES_DIR) @@ -54,7 +57,28 @@ config = Config(STATE_FILENAME) if options.undo: - raise NotImplementedError('Undo not implemented yet.') + transactions = [] + for arg in args: + try: + transid = int(arg) + except ValueError: + print('Unknown transaction: %s' % arg) + sys.exit(-1) + transactions.append(transid) + if not transactions and config.nextid: + transactions.append(config.nextid - 1) + for transid in transactions: + dirname = dir_for_trans(transid) + if not os.path.exists(dirname): + print('Transaction %d does not exist.' % transid) + sys.exit(-1) + + print('Sorry, undo is not implemented yet.' + 'But you can find what you need in the following ' + 'directory/directories:\n') + print('\n'.join([dir_for_trans(transid) + for transid in transactions])) + sys.exit(-1) else: files = [] for arg in args: @@ -70,7 +94,7 @@ files.append(filename) thisid = config.nextid - basedir = os.path.join(HADES_DIR, '%.9d' % thisid) + basedir = dir_for_trans(thisid) shell('mkdir', basedir) config.nextid = thisid + 1 config.save()