jenkins-bot has submitted this change and it was merged. Change subject: Add pretty symlink for WikimetricsBot ......................................................................
Add pretty symlink for WikimetricsBot Bug: 66087 Change-Id: I2a270845c13ce1f5c69486ec52d411626e92cc61 --- M scripts/admin 1 file changed, 59 insertions(+), 4 deletions(-) Approvals: Nuria: Looks good to me, approved jenkins-bot: Verified diff --git a/scripts/admin b/scripts/admin index 8d50183..906e966 100755 --- a/scripts/admin +++ b/scripts/admin @@ -5,6 +5,9 @@ from datetime import datetime +WIKIMETRICS_BOT_NAME = 'WikimetricsBot' + + def run_cohorts(args): print('... validating list of projects') projects = db.get_project_host_map() @@ -62,6 +65,43 @@ from wikimetrics.models.report_nodes.run_report import RunReport from wikimetrics.utils import today + + if args.user.username == WIKIMETRICS_BOT_NAME: + import os + from wikimetrics.configurables import app + from wikimetrics.api.file_manager import ( + PublicReportFileManager, COALESCED_REPORT_FILE + ) + file_manager = PublicReportFileManager( + app.logger, + app.absolute_path_to_app_root, + ) + print('... will make pretty symlink for {}'.format(WIKIMETRICS_BOT_NAME)) + public_folder = os.path.join( + app.absolute_path_to_app_root, + 'static', + 'public', + ) + public_stat = os.stat(public_folder) + + datafiles_folder = os.path.join( + public_folder, + 'datafiles', + ) + if not os.path.exists(datafiles_folder): + os.makedirs(datafiles_folder) + # keep ownership in the public subdirectory uniform + os.chown(datafiles_folder, public_stat.st_uid, public_stat.st_gid) + + symlink_folder = os.path.join( + datafiles_folder, + args.metric, + ) + if not os.path.exists(symlink_folder): + os.makedirs(symlink_folder) + # keep ownership in the public subdirectory uniform + os.chown(symlink_folder, public_stat.st_uid, public_stat.st_gid) + start = args.start or today() for cohort in valid: parameters = dict( @@ -77,8 +117,23 @@ .filter(ReportStore.user_id == args.user.id)\ .count() if existing == 0: - RunReport(parameters, user_id=args.user.id, created=start) - print('... queueing "{}"'.format(parameters['name'])) + report = RunReport(parameters, user_id=args.user.id, created=start) + if args.user.username == WIKIMETRICS_BOT_NAME: + path = os.path.join(file_manager.get_public_report_path( + report.persistent_id, + recurrent=True + ), COALESCED_REPORT_FILE) + pretty_path = os.path.join( + symlink_folder, + '{}.json'.format(cohort.name), + ) + try: + os.symlink(path, pretty_path) + os.lchown(pretty_path, public_stat.st_uid, public_stat.st_gid) + except OSError, err: + print('... ERROR creating pretty link: {}'.format(err)) + + print('... queued "{}"'.format(parameters['name'])) else: print('... already exists: "{}"'.format(parameters['name'])) finally: @@ -88,12 +143,12 @@ def get_user(args): try: s = db.get_session() - print('... looking up user') + print('... looking up user (defaulting to {})'.format(WIKIMETRICS_BOT_NAME)) q = s.query(UserStore) if args.user: u = q.get(args.user) else: - u = q.filter(UserStore.username == 'WikimetricsBot').one() + u = q.filter(UserStore.username == WIKIMETRICS_BOT_NAME).one() print('... found user "{}", id: "{}"'.format(u.username or u.email, u.id)) args.user = u -- To view, visit https://gerrit.wikimedia.org/r/143040 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I2a270845c13ce1f5c69486ec52d411626e92cc61 Gerrit-PatchSet: 4 Gerrit-Project: analytics/wikimetrics Gerrit-Branch: master Gerrit-Owner: Milimetric <dandree...@wikimedia.org> Gerrit-Reviewer: Milimetric <dandree...@wikimedia.org> Gerrit-Reviewer: Nuria <nu...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits