Change update to use remove with context and run with new

This commit is contained in:
Dmitry Shulyak 2015-06-01 16:37:45 +02:00
parent 253e3e5c21
commit 66dae0f267
3 changed files with 32 additions and 5 deletions

5
cli.py
View File

@ -168,10 +168,13 @@ def init_changes():
@click.command()
@click.option('--last', is_flag=True, default=False)
@click.option('--all', is_flag=True, default=False)
@click.option('--uid', default=None)
def rollback(last, uid):
def rollback(last, all, uid):
if last:
print operations.rollback_last()
elif all:
print operations.rollback_all()
elif uid:
print operations.rollback_uid(uid)

View File

@ -21,7 +21,7 @@ def guess_action(from_, to):
return 'remove'
else:
# it should be update
return 'run'
return 'update'
def connections(res, graph):
@ -68,6 +68,7 @@ def stage_changes():
df = list(diff(commited_data, staged_data))
if df:
log_item = state.LogItem(
utils.generate_uuid(),
res_uid,
@ -88,9 +89,20 @@ def commit_changes():
l = staged.popleft()
wrapper = resources[l.res]
actions.resource_action(wrapper, l.action)
staged_data = patch(l.diff, commited.get(l.res, {}))
commited[l.res] = patch(l.diff, commited.get(l.res, {}))
# TODO(dshulyak) think about this hack for update
if l.action == 'update':
commited_args = commited[l.res]['args']
wrapper.update(commited_args)
actions.resource_action(wrapper, 'remove')
wrapper.update(staged_data.get('args', {}))
actions.resource_action(wrapper, 'run')
else:
actions.resource_action(wrapper, l.action)
commited[l.res] = staged_data
l.state = state.STATES.success
history.add(l)
@ -103,7 +115,7 @@ def rollback(log_item):
staged = revert(log_item.diff, commited)
for e, r, mapping in commited['connections']:
for e, r, mapping in commited.get('connections', ()):
signals.disconnect(resources[e], resources[r])
for e, r, mapping in staged.get('connections', ()):
@ -133,3 +145,10 @@ def rollback_last():
return rollback(l)
def rollback_all():
cl = state.CL()
while cl:
rollback(cl.pop())

View File

@ -88,6 +88,11 @@ class Log(object):
self.sync()
return item
def pop(self):
item = self.items.pop()
self.sync()
return item
def show(self, verbose=False):
return ['L(uuid={0}, res={1}, aciton={2})'.format(
l.uid, l.res, l.action) for l in self.items]