annotate workflow/__main__.py @ 75:d5e1d4ea2b7e draft default tip

planemo upload for repository https://github.com/rolfverberg/galaxytools commit 6afde341a94586fe3972bdbbfbf5dabd5e8dec69
author rv43
date Thu, 23 Mar 2023 13:39:14 +0000
parents 1cf15b61cd83
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
69
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
1 #!/usr/bin/env python3
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
2
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
3 import logging
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
4 logging.getLogger(__name__)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
5
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
6 import argparse
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
7 import pathlib
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
8 import sys
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
9
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
10 from .models import TomoWorkflow as Workflow
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
11 try:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
12 from deepdiff import DeepDiff
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
13 except:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
14 pass
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
15
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
16 parser = argparse.ArgumentParser(description='''Operate on representations of
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
17 Tomo data workflows saved to files.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
18 parser.add_argument('-l', '--log',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
19 # type=argparse.FileType('w'),
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
20 default=sys.stdout,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
21 help='Logging stream or filename')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
22 parser.add_argument('--log_level',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
23 choices=logging._nameToLevel.keys(),
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
24 default='INFO',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
25 help='''Specify a preferred logging level.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
26 subparsers = parser.add_subparsers(title='subcommands', required=True)#, dest='command')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
27
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
28
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
29 # CONSTRUCT
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
30 def construct(args:list) -> None:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
31 if args.template_file is not None:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
32 wf = Workflow.construct_from_file(args.template_file)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
33 wf.cli()
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
34 else:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
35 wf = Workflow.construct_from_cli()
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
36 wf.write_to_file(args.output_file, force_overwrite=args.force_overwrite)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
37
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
38 construct_parser = subparsers.add_parser('construct', help='''Construct a valid Tomo
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
39 workflow representation on the command line and save it to a file. Optionally use
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
40 an existing file as a template and/or preform the reconstruction or transfer to Galaxy.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
41 construct_parser.set_defaults(func=construct)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
42 construct_parser.add_argument('-t', '--template_file',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
43 type=pathlib.Path,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
44 required=False,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
45 help='''Full or relative template file path for the constructed workflow.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
46 construct_parser.add_argument('-f', '--force_overwrite',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
47 action='store_true',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
48 help='''Use this flag to overwrite the output file if it already exists.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
49 construct_parser.add_argument('-o', '--output_file',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
50 type=pathlib.Path,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
51 help='''Full or relative file path to which the constructed workflow will be written.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
52
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
53
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
54 # VALIDATE
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
55 def validate(args:list) -> bool:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
56 try:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
57 wf = Workflow.construct_from_file(args.input_file)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
58 logger.info(f'Success: {args.input_file} represents a valid Tomo workflow configuration.')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
59 return(True)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
60 except BaseException as e:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
61 logger.error(f'{e.__class__.__name__}: {str(e)}')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
62 logger.info(f'''Failure: {args.input_file} does not represent a valid Tomo workflow
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
63 configuration.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
64 return(False)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
65
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
66 validate_parser = subparsers.add_parser('validate',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
67 help='''Validate a file as a representation of a Tomo workflow (this is most useful
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
68 after a .yaml file has been manually edited).''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
69 validate_parser.set_defaults(func=validate)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
70 validate_parser.add_argument('input_file',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
71 type=pathlib.Path,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
72 help='''Full or relative file path to validate as a Tomo workflow.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
73
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
74
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
75 # CONVERT
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
76 def convert(args:list) -> None:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
77 wf = Workflow.construct_from_file(args.input_file)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
78 wf.write_to_file(args.output_file, force_overwrite=args.force_overwrite)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
79
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
80 convert_parser = subparsers.add_parser('convert', help='''Convert one Tomo workflow
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
81 representation to another. File format of both input and output files will be
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
82 automatically determined from the files' extensions.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
83 convert_parser.set_defaults(func=convert)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
84 convert_parser.add_argument('-f', '--force_overwrite',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
85 action='store_true',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
86 help='''Use this flag to overwrite the output file if it already exists.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
87 convert_parser.add_argument('-i', '--input_file',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
88 type=pathlib.Path,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
89 required=True,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
90 help='''Full or relative input file path to be converted.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
91 convert_parser.add_argument('-o', '--output_file',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
92 type=pathlib.Path,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
93 required=True,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
94 help='''Full or relative file path to which the converted input will be written.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
95
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
96
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
97 # DIFF / COMPARE
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
98 def diff(args:list) -> bool:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
99 raise ValueError('diff not tested')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
100 # wf1 = Workflow.construct_from_file(args.file1).dict_for_yaml()
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
101 # wf2 = Workflow.construct_from_file(args.file2).dict_for_yaml()
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
102 # diff = DeepDiff(wf1,wf2,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
103 # ignore_order_func=lambda level:'independent_dimensions' not in level.path(),
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
104 # report_repetition=True,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
105 # ignore_string_type_changes=True,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
106 # ignore_numeric_type_changes=True)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
107 diff_report = diff.pretty()
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
108 if len(diff_report) > 0:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
109 logger.info(f'The configurations in {args.file1} and {args.file2} are not identical.')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
110 print(diff_report)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
111 return(True)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
112 else:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
113 logger.info(f'The configurations in {args.file1} and {args.file2} are identical.')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
114 return(False)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
115
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
116 diff_parser = subparsers.add_parser('diff', aliases=['compare'], help='''Print a comparison of
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
117 two Tomo workflow representations stored in files. The files may have different formats.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
118 diff_parser.set_defaults(func=diff)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
119 diff_parser.add_argument('file1',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
120 type=pathlib.Path,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
121 help='''Full or relative path to the first file for comparison.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
122 diff_parser.add_argument('file2',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
123 type=pathlib.Path,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
124 help='''Full or relative path to the second file for comparison.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
125
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
126
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
127 # LINK TO GALAXY
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
128 def link_to_galaxy(args:list) -> None:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
129 from .link_to_galaxy import link_to_galaxy
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
130 link_to_galaxy(args.input_file, galaxy=args.galaxy, user=args.user,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
131 password=args.password, api_key=args.api_key)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
132
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
133 link_parser = subparsers.add_parser('link_to_galaxy', help='''Construct a Galaxy history and link
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
134 to an existing Tomo workflow representations in a NeXus file.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
135 link_parser.set_defaults(func=link_to_galaxy)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
136 link_parser.add_argument('-i', '--input_file',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
137 type=pathlib.Path,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
138 required=True,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
139 help='''Full or relative input file path to the existing Tomo workflow representations as
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
140 a NeXus file.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
141 link_parser.add_argument('-g', '--galaxy',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
142 required=True,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
143 help='Target Galaxy instance URL/IP address')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
144 link_parser.add_argument('-u', '--user',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
145 default=None,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
146 help='Galaxy user email address')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
147 link_parser.add_argument('-p', '--password',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
148 default=None,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
149 help='Password for the Galaxy user')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
150 link_parser.add_argument('-a', '--api_key',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
151 default=None,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
152 help='Galaxy admin user API key (required if not defined in the tools list file)')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
153
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
154
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
155 # RUN THE RECONSTRUCTION
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
156 def run_tomo(args:list) -> None:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
157 from .run_tomo import run_tomo
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
158 run_tomo(args.input_file, args.output_file, args.modes, center_file=args.center_file,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
159 num_core=args.num_core, output_folder=args.output_folder, save_figs=args.save_figs)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
160
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
161 tomo_parser = subparsers.add_parser('run_tomo', help='''Construct and add reconstructed tomography
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
162 data to an existing Tomo workflow representations in a NeXus file.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
163 tomo_parser.set_defaults(func=run_tomo)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
164 tomo_parser.add_argument('-i', '--input_file',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
165 required=True,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
166 type=pathlib.Path,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
167 help='''Full or relative input file path containing raw and/or reduced data.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
168 tomo_parser.add_argument('-o', '--output_file',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
169 required=True,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
170 type=pathlib.Path,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
171 help='''Full or relative input file path containing raw and/or reduced data.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
172 tomo_parser.add_argument('-c', '--center_file',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
173 type=pathlib.Path,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
174 help='''Full or relative input file path containing the rotation axis centers info.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
175 #tomo_parser.add_argument('-f', '--force_overwrite',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
176 # action='store_true',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
177 # help='''Use this flag to overwrite any existing reduced data.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
178 tomo_parser.add_argument('-n', '--num_core',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
179 type=int,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
180 default=-1,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
181 help='''Specify the number of processors to use.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
182 tomo_parser.add_argument('--output_folder',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
183 type=pathlib.Path,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
184 default='.',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
185 help='Full or relative path to an output folder')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
186 tomo_parser.add_argument('-s', '--save_figs',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
187 choices=['yes', 'no', 'only'],
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
188 default='no',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
189 help='''Specify weather to display ('yes' or 'no'), save ('yes'), or only save ('only').''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
190 tomo_parser.add_argument('--reduce_data',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
191 dest='modes',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
192 const='reduce_data',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
193 action='append_const',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
194 help='''Use this flag to create and add reduced data to the input file.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
195 tomo_parser.add_argument('--find_center',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
196 dest='modes',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
197 const='find_center',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
198 action='append_const',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
199 help='''Use this flag to find and add the calibrated center axis info to the input file.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
200 tomo_parser.add_argument('--reconstruct_data',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
201 dest='modes',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
202 const='reconstruct_data',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
203 action='append_const',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
204 help='''Use this flag to create and add reconstructed data data to the input file.''')
71
1cf15b61cd83 planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents: 69
diff changeset
205 tomo_parser.add_argument('--combine_data',
69
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
206 dest='modes',
71
1cf15b61cd83 planemo upload for repository https://github.com/rolfverberg/galaxytools commit 366e516aef0735af2998c6ff3af037181c8d5213
rv43
parents: 69
diff changeset
207 const='combine_data',
69
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
208 action='append_const',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
209 help='''Use this flag to combine reconstructed data data and add to the input file.''')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
210
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
211
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
212 if __name__ == '__main__':
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
213 args = parser.parse_args(sys.argv[1:])
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
214
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
215 # Set log configuration
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
216 # When logging to file, the stdout log level defaults to WARNING
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
217 logging_format = '%(asctime)s : %(levelname)s - %(module)s : %(funcName)s - %(message)s'
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
218 level = logging.getLevelName(args.log_level)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
219 if args.log is sys.stdout:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
220 logging.basicConfig(format=logging_format, level=level, force=True,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
221 handlers=[logging.StreamHandler()])
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
222 else:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
223 if isinstance(args.log, str):
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
224 logging.basicConfig(filename=f'{args.log}', filemode='w',
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
225 format=logging_format, level=level, force=True)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
226 elif isinstance(args.log, io.TextIOWrapper):
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
227 logging.basicConfig(filemode='w', format=logging_format, level=level,
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
228 stream=args.log, force=True)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
229 else:
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
230 raise ValueError(f'Invalid argument --log: {args.log}')
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
231 stream_handler = logging.StreamHandler()
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
232 logging.getLogger().addHandler(stream_handler)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
233 stream_handler.setLevel(logging.WARNING)
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
234 stream_handler.setFormatter(logging.Formatter(logging_format))
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
235
fba792d5f83b planemo upload for repository https://github.com/rolfverberg/galaxytools commit ab9f412c362a4ab986d00e21d5185cfcf82485c1
rv43
parents:
diff changeset
236 args.func(args)