Skip to content

Commit 747c31a

Browse files
use logging from stdlib
1 parent 20356e3 commit 747c31a

5 files changed

Lines changed: 57 additions & 81 deletions

File tree

ctdconverter/common/logger.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

ctdconverter/common/utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22
import json
3+
import logging
34
import ntpath
45
import operator
56
import os
@@ -16,7 +17,6 @@
1617
)
1718
from lxml import etree
1819

19-
from ..common import logger
2020
from ..common.exceptions import ApplicationException
2121

2222

@@ -109,7 +109,7 @@ def validate_path_exists(path):
109109

110110
def validate_argument_is_directory(args, argument_name):
111111
file_name = getattr(args, argument_name)
112-
logger.info("REALPATH %s" % os.path.realpath(file_name))
112+
logging.info("REALPATH %s" % os.path.realpath(file_name))
113113
if file_name is not None and os.path.isdir(os.path.realpath(file_name)):
114114
raise ApplicationException("The provided output file name (%s) points to a directory." % file_name)
115115

@@ -150,12 +150,12 @@ def parse_input_ctds(xsd_location, input_ctds, output_destination, output_file_e
150150
schema = None
151151
if xsd_location is not None:
152152
try:
153-
logger.info("Loading validation schema from %s" % xsd_location, 0)
153+
logging.info("Loading validation schema from %s" % xsd_location)
154154
schema = etree.XMLSchema(etree.parse(xsd_location))
155155
except Exception as e:
156-
logger.error("Could not load validation schema {}. Reason: {}".format(xsd_location, str(e)), 0)
156+
logging.error("Could not load validation schema {}. Reason: {}".format(xsd_location, str(e)))
157157
else:
158-
logger.warning("Validation against a schema has not been enabled.", 0)
158+
logging.warning("Validation against a schema has not been enabled.")
159159

160160
for input_ctd in input_ctds:
161161
if schema is not None:
@@ -165,7 +165,7 @@ def parse_input_ctds(xsd_location, input_ctds, output_destination, output_file_e
165165
# if multiple inputs are being converted, we need to generate a different output_file for each input
166166
if is_converting_multiple_ctds:
167167
output_file = os.path.join(output_file, get_filename_without_suffix(input_ctd) + "." + output_file_extension)
168-
logger.info("Parsing %s" % input_ctd)
168+
logging.info("Parsing %s" % input_ctd)
169169

170170
model = None
171171
try:
@@ -386,8 +386,8 @@ def resolve_param_mapping(param, ctd_model, fix_underscore=False):
386386
for mapping_element in cli_element.mappings:
387387
if mapping_element.reference_name == param.name:
388388
if param_mapping is not None:
389-
logger.warning("The parameter %s has more than one mapping in the <cli> section. "
390-
"The first found mapping, %s, will be used." % (param.name, param_mapping), 1)
389+
logging.warning("The parameter %s has more than one mapping in the <cli> section. "
390+
"The first found mapping, %s, will be used." % (param.name, param_mapping))
391391
else:
392392
param_mapping = cli_element.option_identifier
393393
if param_mapping is not None:
@@ -404,7 +404,7 @@ def _extract_param_cli_name(param, ctd_model, fix_underscore=False):
404404
# we generate parameters with colons for subgroups, but not for the two topmost parents (OpenMS legacy)
405405
if type(param.parent) == ParameterGroup:
406406
if hasattr(ctd_model, "cli") and ctd_model.cli:
407-
logger.warning("Using nested parameter sections (NODE elements) is not compatible with <cli>", 1)
407+
logging.warning("Using nested parameter sections (NODE elements) is not compatible with <cli>")
408408
return ":".join(extract_param_path(param, fix_underscore)[:-1]) + ":" + resolve_param_mapping(param, ctd_model, fix_underscore)
409409
else:
410410
return resolve_param_mapping(param, ctd_model, fix_underscore)

ctdconverter/convert.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import os
23
import sys
34
import traceback
@@ -75,7 +76,7 @@ def main(argv=None):
7576
# at this point we cannot parse the arguments, because each converter takes different arguments, meaning each
7677
# converter will register its own parameters after we've registered the basic ones... we have to do it old school
7778
if len(argv) < 2:
78-
utils.logger.error("Not enough arguments provided")
79+
logging.error("Not enough arguments provided")
7980
print("\nUsage: $ CTDConverter [TARGET] [ARGUMENTS]\n\n"
8081
"Where:\n"
8182
" target: one of 'cwl' or 'galaxy'\n\n"
@@ -94,10 +95,10 @@ def main(argv=None):
9495
# print(program_license)
9596
# return 0
9697
else:
97-
utils.logger.error("Unrecognized target engine. Supported targets are 'cwl' and 'galaxy'.")
98+
logging.error("Unrecognized target engine. Supported targets are 'cwl' and 'galaxy'.")
9899
return 1
99100

100-
utils.logger.info("Using %s converter" % target)
101+
logging.info("Using %s converter" % target)
101102

102103
try:
103104
# Setup argument parser
@@ -126,20 +127,20 @@ def main(argv=None):
126127

127128
except ApplicationException as e:
128129
traceback.print_exc()
129-
utils.logger.error("CTDConverter could not complete the requested operation.", 0)
130-
utils.logger.error("Reason: " + e.msg, 0)
130+
logging.error("CTDConverter could not complete the requested operation.")
131+
logging.error("Reason: " + e.msg)
131132
return 1
132133

133134
except ModelError as e:
134135
traceback.print_exc()
135-
utils.logger.error("There seems to be a problem with one of your input CTDs.", 0)
136-
utils.logger.error("Reason: " + e.msg, 0)
136+
logging.error("There seems to be a problem with one of your input CTDs.")
137+
logging.error("Reason: " + e.msg)
137138
return 1
138139

139140
except Exception as e:
140141
traceback.print_exc()
141-
utils.logger.error("CTDConverter could not complete the requested operation.", 0)
142-
utils.logger.error("Reason: " + e.msg, 0)
142+
logging.error("CTDConverter could not complete the requested operation.")
143+
logging.error("Reason: " + e.msg)
143144
return 2
144145

145146

ctdconverter/cwl/converter.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# which kind of sucks, because this seems to be the way to state that a parameter is truly optional and has no default
88
# since cwlgen is just "fancy classes" around the yaml.dump() method, we implemented our own generation of yaml
99

10-
10+
import logging
1111
import ruamel.yaml as yaml
1212
from CTDopts.CTDopts import (
1313
_Choices,
@@ -17,10 +17,7 @@
1717
)
1818

1919
from .. import __version__ as version
20-
from ..common import (
21-
logger,
22-
utils
23-
)
20+
from ..common import utils
2421

2522
# all cwl-related properties are defined here
2623

@@ -75,10 +72,10 @@ def convert_models(args, parsed_ctds):
7572
origin_file = parsed_ctd.input_file
7673
output_file = parsed_ctd.suggested_output_file
7774

78-
logger.info("Converting {} (source {})".format(model.name, utils.get_filename(origin_file)))
75+
logging.info("Converting {} (source {})".format(model.name, utils.get_filename(origin_file)))
7976
cwl_tool = convert_to_cwl(model, args)
8077

81-
logger.info("Writing to %s" % utils.get_filename(output_file), 1)
78+
logging.info("Writing to %s" % utils.get_filename(output_file))
8279

8380
stream = open(output_file, 'w')
8481
stream.write(CWL_SHEBANG + '\n\n')

0 commit comments

Comments
 (0)