Commit 850d80cc authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

commands/info: provide an `info` command which outputs a global repository summary

parent 0a95305b6a93
......@@ -5,14 +5,14 @@ from sqlalchemy import create_engine
from tshistory.tsio import TimeSerie
FMT = """
REVFMT = """
revision: {rev}
author: {author}
date: {date}
""".strip()
def format_rev(rev):
fmt = FMT + '\n'
fmt = REVFMT + '\n'
if rev.get('diff'):
fmt += 'series: {names}\n\n'
lines = []
......@@ -25,7 +25,12 @@ def format_rev(rev):
return fmt.format(**rev)
@click.command()
@click.group()
def tsh():
pass
@tsh.command()
@click.argument('db-uri')
@click.option('--limit', '-l', default=None)
@click.option('--show-diff', is_flag=True, default=False)
......@@ -43,5 +48,22 @@ def log(db_uri, limit, show_diff, serie, from_rev, to_rev):
print()
INFOFMT = """
changeset count: {changeset count}
series count: {series count}
series names: {serie names}
""".strip()
@tsh.command()
@click.argument('db-uri')
def info(db_uri):
engine = create_engine(db_uri)
tsh = TimeSerie()
info = tsh.info(engine)
info['serie names'] = ', '.join(info['serie names'])
print(INFOFMT.format(**info))
if __name__ == '__main__':
log()
tsh()
......@@ -102,6 +102,13 @@ def test_changeset(engine):
log = tso.log(engine, torev=1)
assert len(log) == 1
info = tso.info(engine)
assert {
'changeset count': 2,
'serie names': ['ts_othervalues', 'ts_values'],
'series count': 2
} == info
def test_tstamp_roundtrip(engine):
tso = TimeSerie()
......
......@@ -187,6 +187,17 @@ class TimeSerie(object):
).where(tstable.c.csid == cset.c.id)
return cnx.execute(sql).scalar()
def info(self, cnx):
"""Gather global statistics on the current tshistory repository
"""
sql = 'select count(*) from registry'
stats = {'series count': cnx.execute(sql).scalar()}
sql = 'select max(id) from changeset'
stats['changeset count'] = cnx.execute(sql).scalar()
sql = 'select distinct name from registry order by name'
stats['serie names'] = [row for row, in cnx.execute(sql).fetchall()]
return stats
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.
......
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