Mercurial > hrm
changeset 4:702b55be9030
Added more of an implementation for undo, although it's still unimplemented.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 08 Dec 2008 14:32:06 -0800 |
parents | 4734efec5732 |
children | ce037f485614 |
files | kharon.py |
diffstat | 1 files changed, 26 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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()