Commit 9a2cf8d4 authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

command/log: provide --from-rev and --to-rev filters

These use changeset ids.
We also might want to filter on individual serie id.
parent 22ccc31c992a
......@@ -30,11 +30,14 @@ def format_rev(rev):
@click.option('--limit', '-l', default=None)
@click.option('--show-diff', is_flag=True, default=False)
@click.option('--serie', '-s', multiple=True)
def log(db_uri, limit, show_diff, serie):
@click.option('--from-rev')
@click.option('--to-rev')
def log(db_uri, limit, show_diff, serie, from_rev, to_rev):
engine = create_engine(db_uri)
tsh = TimeSerie()
for rev in tsh.log(engine, limit=limit, diff=show_diff, names=serie):
for rev in tsh.log(engine, limit=limit, diff=show_diff, names=serie,
fromrev=from_rev, torev=to_rev):
rev['names'] = ','.join(rev['names'])
print(format_rev(rev))
print()
......
......@@ -96,6 +96,12 @@ def test_changeset(engine):
assert log[0]['rev'] == 1
assert log[0]['names'] == ['ts_values', 'ts_othervalues']
log = tso.log(engine, fromrev=2)
assert len(log) == 1
log = tso.log(engine, torev=1)
assert len(log) == 1
def test_tstamp_roundtrip(engine):
tso = TimeSerie()
......
......@@ -187,7 +187,7 @@ class TimeSerie(object):
).where(tstable.c.csid == cset.c.id)
return cnx.execute(sql).scalar()
def log(self, cnx, limit=0, diff=False, names=None):
def log(self, cnx, limit=0, diff=False, names=None, fromrev=None, torev=None):
"""Build a structure showing the history of all the series in the db,
per changeset, in chronological order.
"""
......@@ -203,6 +203,12 @@ class TimeSerie(object):
if names:
sql = sql.where(reg.c.name.in_(names))
if fromrev:
sql = sql.where(cset.c.id >= fromrev)
if torev:
sql = sql.where(cset.c.id <= torev)
sql = sql.where(cset.c.id == cset_series.c.csid
).where(cset_series.c.serie == reg.c.name)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment