Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh sticky plots #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions bin/debsources-suite-archive
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ import sys
from debsources import archiver
from debsources import debmirror
from debsources import mainlib
from debsources import updater


def main():
cmdline = argparse.ArgumentParser(description='Debsources suite '
'archive manager')
cmdline.add_argument('action', metavar='ACTION',
choices=['add', 'list', 'remove'],
choices=['add', 'list', 'remove', 'refresh'],
help='action to perform on the archive of '
'sticky suites')
cmdline.add_argument('suite', metavar='SUITE', nargs='?', default=None,
Expand All @@ -39,7 +40,8 @@ def main():
args = cmdline.parse_args()
if args.action in ['add', 'remove'] and args.suite is None:
cmdline.error('%s requires a suite name' % args.action)

if args.action == 'refresh' and args.stages is None:
cmdline.error('%s requires a stage' % args.action)
conf = mainlib.load_conf(args.conffile or mainlib.guess_conffile())
mainlib.override_conf(conf, args)
mainlib.init_logging(conf, mainlib.log_level_of_verbosity(args.verbose))
Expand All @@ -62,6 +64,9 @@ def main():
(suite, present['db'], present['archive']))
elif args.action == 'remove':
archiver.remove_suite(conf, session, args.suite)
elif args.action == 'refresh':
conf['refresh'] = True
updater.update(conf, session, stages=conf['stages'])
if conf['single_transaction']:
session.commit()
except SystemExit: # exit as requested
Expand Down
1 change: 1 addition & 0 deletions contrib/docker/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sources_dir: %(mirror_dir)s/pool
python_dir: %(root_dir)s/python
mirror_dir: %(root_dir)s/testdata/mirror
pool_dir: %(mirror_dir)s/pool
mirror_archive_dir: %(root_dir)s/testdata/archive
dry_run: false
# echoes or not the SQL requests to stdout (can be logged with Apache):
sqlalchemy_echo: false
Expand Down
4 changes: 3 additions & 1 deletion debsources/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ def suites(session, suites='release'):
return sorted(db_suites, cmp=by_release_date)


def sticky_suites(session):
def sticky_suites(session, order=None):
"""list sticky suites currently present in Debsources DB

"""
q = session.query(SuiteInfo.name) \
.filter(SuiteInfo.sticky == True) # NOQA,
# '== True' can be dropped starting with sqlalchemy >= 0.8
if order:
q = q.order_by("release_date")
return [row[0] for row in q]


Expand Down
17 changes: 12 additions & 5 deletions debsources/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,10 @@ def update_charts(status, conf, session, suites=None):
from debsources import charts
logging.info('update charts...')
ensure_stats_dir(conf)
suites = __target_suites(session, suites)
if 'refresh' in conf.keys():
suites = statistics.sticky_suites(session, True)
else:
suites = __target_suites(session, suites)

CHARTS = [ # <period, granularity> paris
('1 month', 'hourly'),
Expand Down Expand Up @@ -560,26 +563,30 @@ def update_charts(status, conf, session, suites=None):
charts.sloc_plot(mseries, chart_file)

# sloccount: current pie charts
sloc_per_suite = []
for suite in suites + ['ALL']:
sloc_suite = suite
if sloc_suite == 'ALL':
sloc_suite = None
slocs = statistics.sloccount_summary(session, suite=sloc_suite)
if suite not in ['ALL']:
sloc_per_suite.append(slocs)
chart_file = os.path.join(conf['cache_dir'], 'stats',
'%s-sloc_pie-current.png' % suite)
if not conf['dry_run']:
charts.sloc_pie(slocs, chart_file)

# sloccount: bar chart plot
all_suites = statistics.sticky_suites(session, True) \
+ __target_suites(session, None)
sloc_per_suite = []
for suite in all_suites:
slocs = statistics.sloccount_summary(session, suite=suite)
sloc_per_suite.append(slocs)

if 'charts_top_langs' in conf.keys():
top_langs = int(conf['charts_top_langs'])
else:
top_langs = 6
chart_file = os.path.join(conf['cache_dir'], 'stats', 'sloc_bar_plot.png')
charts.bar_chart(sloc_per_suite, suites, chart_file, top_langs)
charts.bar_chart(sloc_per_suite, all_suites, chart_file, top_langs)

# update stages
(STAGE_EXTRACT,
Expand Down
1 change: 1 addition & 0 deletions etc/config.travis.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sources_dir: %(mirror_dir)s/pool
python_dir: %(root_dir)s/python
mirror_dir: %(root_dir)s/testdata/mirror
pool_dir: %(mirror_dir)s/pool
mirror_archive_dir: %(root_dir)s/testdata/archive
dry_run: false
# echoes or not the SQL requests to stdout (can be logged with Apache):
sqlalchemy_echo: false
Expand Down