forked from wtsi-npg/npg-irods-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
642 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ setuptools-git-versioning==2.0.0 | |
setuptools==69.5.1 | ||
sqlalchemy==2.0.29 | ||
structlog==24.1.0 | ||
yattag==1.14.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright © 2024 Genome Research Ltd. All rights reserved. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# @author Keith James <kdj@sanger.ac.uk> | ||
|
||
import argparse | ||
import sys | ||
|
||
import structlog | ||
from partisan.exception import RodsError | ||
from yattag import indent | ||
|
||
from npg_irods.cli.util import add_logging_arguments, configure_logging | ||
from npg_irods.html_reports import ont_runs_html_report_this_year | ||
from npg_irods.version import version | ||
|
||
description = """Writes an HTML report summarising data in iRODS. | ||
The reports include HTTP links to data objects and collections in iRODS. The links | ||
are only accessible if the report is rendered by a web server that can access the | ||
relevant iRODS zone. | ||
Available reports are: | ||
- ont: Oxford Nanopore sequencing data objects and collections. | ||
A summary of ONT runs for the calendar year to date. | ||
""" | ||
|
||
parser = argparse.ArgumentParser( | ||
description=description, | ||
formatter_class=argparse.RawDescriptionHelpFormatter, | ||
) | ||
add_logging_arguments(parser) | ||
parser.add_argument( | ||
"-o", | ||
"--output", | ||
help="Output filename.", | ||
type=argparse.FileType("w", encoding="UTF-8"), | ||
default=sys.stdout, | ||
) | ||
parser.add_argument( | ||
"report", | ||
help="Report type.", | ||
type=str, | ||
choices=["ont"], | ||
nargs=1, | ||
) | ||
parser.add_argument( | ||
"--zone", | ||
help="Specify a federated iRODS zone in which to find data objects and/or " | ||
"collections. This is not required if the target paths are on the local zone.", | ||
type=str, | ||
) | ||
parser.add_argument( | ||
"--version", help="Print the version and exit.", action="store_true" | ||
) | ||
|
||
args = parser.parse_args() | ||
configure_logging( | ||
config_file=args.log_config, | ||
debug=args.debug, | ||
verbose=args.verbose, | ||
colour=args.colour, | ||
json=args.json, | ||
) | ||
log = structlog.get_logger("main") | ||
|
||
|
||
def main(): | ||
if args.version: | ||
print(version()) | ||
sys.exit(0) | ||
|
||
report = args.report[0] | ||
|
||
try: | ||
match report: | ||
case "ont": | ||
doc = ont_runs_html_report_this_year(zone=args.zone) | ||
case _: | ||
raise ValueError(f"Invalid HTML report type '{report}'") | ||
|
||
print(indent(doc.getvalue()), file=args.output) | ||
except RodsError as re: | ||
log.error(re.message, code=re.code) | ||
sys.exit(1) | ||
except Exception as e: | ||
log.error(e) | ||
sys.exit(1) |
Oops, something went wrong.