Skip to content

Commit

Permalink
Merge pull request #527 from qiboteam/addtag
Browse files Browse the repository at this point in the history
adding tag option in qq upload
  • Loading branch information
scarrazza authored Sep 21, 2023
2 parents 6e5b3cf + 525444f commit 74f584d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
26 changes: 13 additions & 13 deletions serverscripts/qibocal-index-reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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'<a href="{url}">{title}</a>'
return (titlelink, date, platform, start_time, end_time)
return (titlelink, date, platform, start_time, end_time, tag)


def make_index():
Expand Down
1 change: 1 addition & 0 deletions serverscripts/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ <h2>Uploaded Reports</h2>
<th scope="col">Platform</th>
<th scope="col">Start-time (UTC)</th>
<th scope="col">End-time (UTC)</th>
<th scope="col">Tag</th>
</tr>
</thead>
</table>
Expand Down
10 changes: 8 additions & 2 deletions src/qibocal/cli/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 11 additions & 1 deletion src/qibocal/cli/upload.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
"""Upload report to server."""
import base64
import json
import pathlib
import shutil
import socket
import subprocess
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"
Expand All @@ -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(
Expand Down

0 comments on commit 74f584d

Please sign in to comment.