diff --git a/serverscripts/qibocal-index-reports.py b/serverscripts/qibocal-index-reports.py index a70381902..8f5064080 100644 --- a/serverscripts/qibocal-index-reports.py +++ b/serverscripts/qibocal-index-reports.py @@ -6,8 +6,6 @@ import sys from collections import ChainMap -import yaml - ROOT = "/home/users/qibocal/qibocal-reports" ROOT_URL = "http://login.qrccluster.com:9000/" OUT = "/home/users/qibocal/qibocal-reports/index.json" @@ -17,36 +15,38 @@ "platform": "-", "start-time": "-", "end-time": "-", + "tag": "-", } -REQUIRED_FILE_METADATA = {"title", "date", "platform", "start-time" "end-time"} +REQUIRED_FILE_METADATA = {"title", "date", "platform", "start-time" "end-time", "tag"} def meta_from_path(p): meta = ChainMap(DEFAULTS) - yaml_meta = p / "meta.yml" - yaml_res = {} - if yaml_meta.exists(): - with yaml_meta.open() as f: + json_meta = p / "meta.json" + json_res = {} + if json_meta.exists(): + with json_meta.open() as f: try: - yaml_res = yaml.safe_load(f) - except yaml.YAMLError as e: - print(f"Error processing {yaml_meta}: {e}", file=sys.stderr) - meta = meta.new_child(yaml_res) + json_res = json.load(f) + except json.decoder.JSONDecodeError as e: + print(f"Error processing {json_meta}: {e}", file=sys.stderr) + meta = meta.new_child(json_res) return meta def register(p): path_meta = meta_from_path(p) - title, date, platform, start_time, end_time = ( + title, date, platform, start_time, end_time, tag = ( path_meta["title"], path_meta["date"], path_meta["platform"], path_meta["start-time"], path_meta["end-time"], + path_meta["tag"], ) url = ROOT_URL + p.name titlelink = f'{title}' - return (titlelink, date, platform, start_time, end_time) + return (titlelink, date, platform, start_time, end_time, tag) def make_index(): diff --git a/serverscripts/web/index.html b/serverscripts/web/index.html index 74df4be72..316835e15 100644 --- a/serverscripts/web/index.html +++ b/serverscripts/web/index.html @@ -54,6 +54,7 @@

Uploaded Reports

Platform Start-time (UTC) End-time (UTC) + Tag diff --git a/src/qibocal/cli/_base.py b/src/qibocal/cli/_base.py index b692d7be2..49fb67693 100644 --- a/src/qibocal/cli/_base.py +++ b/src/qibocal/cli/_base.py @@ -120,11 +120,17 @@ def fit(folder: pathlib.Path, update): @click.argument( "path", metavar="FOLDER", type=click.Path(exists=True, path_type=pathlib.Path) ) -def upload(path): +@click.option( + "--tag", + default=None, + type=str, + help="Optional tag.", +) +def upload(path, tag): """Uploads output folder to server Arguments: - FOLDER: input folder. """ - upload_report(path) + upload_report(path, tag) diff --git a/src/qibocal/cli/upload.py b/src/qibocal/cli/upload.py index 06bdbe99f..0d53ed6db 100644 --- a/src/qibocal/cli/upload.py +++ b/src/qibocal/cli/upload.py @@ -1,5 +1,6 @@ """Upload report to server.""" import base64 +import json import pathlib import shutil import socket @@ -7,8 +8,11 @@ import uuid from urllib.parse import urljoin +import yaml from qibo.config import log, raise_error +from .utils import META + # options for report upload UPLOAD_HOST = ( "qibocal@localhost" @@ -19,7 +23,13 @@ ROOT_URL = "http://login.qrccluster.com:9000/" -def upload_report(path: pathlib.Path): +def upload_report(path: pathlib.Path, tag: str): + # load meta and update tag + if tag is not None: + meta = yaml.safe_load((path / META).read_text()) + meta["tag"] = tag + (path / META).write_text(json.dumps(meta, indent=4)) + # check the rsync command exists. if not shutil.which("rsync"): raise_error(