-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
64 lines (49 loc) · 1.76 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from pathlib import PurePath
import sys
import click
from common import FMS_SUBMISSION_TEMPLATE_PATH
from convertor import MOHSampleManifestConversion
# Command line interface
#
# -m : sample manifest file path
# -o : output file path (optional)
# Path to the empty fms template
fms_template_file_path = PurePath(FMS_SUBMISSION_TEMPLATE_PATH)
@click.group()
def cli():
pass
@click.command()
@click.argument('manifest_file_path', type=click.Path(exists=True, dir_okay=False, readable=True, resolve_path=True))
@click.option('--output_path', type=click.Path(dir_okay=False, writable=True, resolve_path=True), help="The path to the output file to create")
def convert(manifest_file_path, output_path):
manifest = PurePath(manifest_file_path)
if output_path is None:
manifest_name = manifest.stem
output_file_name = manifest_name + ".fms.xlsx"
output = manifest.with_name(output_file_name)
else:
output = PurePath(output_path)
log_path = output.with_name(output.stem + ".log")
print(manifest)
print(output)
print(log_path)
conversion = MOHSampleManifestConversion(
manifest, fms_template_file_path, output
)
try:
conversion.do_conversion()
except Exception as e:
# Capture any exception so that we can still write the log file
sys.stderr.write('Conversion failed\n')
sys.stderr.write(str(e))
finally:
# Write log no matter what happens, since we capture exception
# messages in the log
conversion.log.output_messages()
# Write log file
with open(log_path, "w", encoding="utf-8") as log_file:
conversion.log.write_log(log_file)
print("DONE")
cli.add_command(convert)
if __name__ == '__main__':
cli()