Improve ordering for stage/commit log

This commit is contained in:
Dmitry Shulyak 2015-07-15 10:40:19 +03:00
parent 9a83dbf2d1
commit c36bdf5f5b
4 changed files with 23 additions and 4 deletions

View File

@ -108,6 +108,7 @@ def dg(uid):
nx.write_dot(plan, 'graph.dot')
subprocess.call(['dot', '-Tpng', 'graph.dot', '-o', 'graph.png'])
@orchestration.command()
@click.argument('uid')
def show(uid):

View File

@ -27,7 +27,10 @@ def validate():
@changes.command()
def stage():
log = change.stage_changes()
click.echo(list(log.collection()))
staged = list(log.reverse())
if not staged:
click.echo('No changes')
click.echo(staged)
@changes.command()
@ -44,7 +47,12 @@ def commit(uid):
@changes.command()
@click.option('-n', default=5)
def history(n):
click.echo(list(data.CL().collection(n)))
commited = list(data.CL().collection(n))
if not commited:
click.echo('No history.')
return
commited.reverse()
click.echo(commited)
@changes.command()

View File

@ -124,12 +124,18 @@ class OrderedSet(object):
def rem_left(self, n=1):
self.rem(r.zrevrange(self.order, 0, n-1))
def get_left(self, n=1):
def reverse(self, n=1):
result = []
for key in self.r.zrevrange(self.order, 0, n-1):
result.append(self.get(key))
return result
def list(self, n=0):
result = []
for key in self.r.zrange(self.order, 0, n-1):
result.append(self.get(key))
return result
class FakeRedisDB(RedisDB):

View File

@ -88,7 +88,11 @@ class Log(object):
return None
def collection(self, n=0):
for item in self.ordered_log.get_left(n):
for item in self.ordered_log.reverse(n=n):
yield LogItem.from_dict(**item)
def reverse(self, n=0):
for item in self.ordered_log.list(n=n):
yield LogItem.from_dict(**item)
def __iter__(self):