text
stringlengths
0
828
:param logger: the logger to use during parsing (optional: None is supported)
:param options:
:return:
""""""
in_root_call = False
if logger is not None:
# log only for the root object, not for the children that will be created by the code below
if not hasattr(_BaseParsingPlan.thrd_locals, 'flag_exec') \
or _BaseParsingPlan.thrd_locals.flag_exec == 0:
# print('Executing Parsing Plan for ' + str(self))
logger.debug('Executing Parsing Plan for [{location}]'
''.format(location=self.obj_on_fs_to_parse.get_pretty_location(append_file_ext=False)))
_BaseParsingPlan.thrd_locals.flag_exec = 1
in_root_call = True
# Common log message
logger.debug('(P) ' + get_parsing_plan_log_str(self.obj_on_fs_to_parse, self.obj_type,
log_only_last=not in_root_call, parser=self.parser))
try:
res = super(_BaseParsingPlan, self).execute(logger, options)
if logger.isEnabledFor(DEBUG):
logger.info('(P) {loc} -> {type} SUCCESS !'
''.format(loc=self.obj_on_fs_to_parse.get_pretty_location(
blank_parent_part=not GLOBAL_CONFIG.full_paths_in_logs,
compact_file_ext=True),
type=get_pretty_type_str(self.obj_type)))
else:
logger.info('SUCCESS parsed [{loc}] as a [{type}] successfully. Parser used was [{parser}]'
''.format(loc=self.obj_on_fs_to_parse.get_pretty_location(compact_file_ext=True),
type=get_pretty_type_str(self.obj_type),
parser=str(self.parser)))
if in_root_call:
# print('Completed parsing successfully')
logger.debug('Completed parsing successfully')
return res
finally:
# remove threadlocal flag if needed
if in_root_call:
_BaseParsingPlan.thrd_locals.flag_exec = 0"
1221,"def _execute(self, logger: Logger, options: Dict[str, Dict[str, Any]]) -> T:
""""""
Implementation of the parent class method.
Checks that self.parser is a _BaseParser, and calls the appropriate parsing method.
:param logger:
:param options:
:return:
""""""
if isinstance(self.parser, _BaseParser):
if (not self.is_singlefile) and self.parser.supports_multifile():
return self.parser._parse_multifile(self.obj_type, self.obj_on_fs_to_parse,
self._get_children_parsing_plan(), logger, options)
elif self.is_singlefile and self.parser.supports_singlefile():
return self.parser._parse_singlefile(self.obj_type, self.get_singlefile_path(),
self.get_singlefile_encoding(), logger, options)
else:
raise _InvalidParserException.create(self.parser, self.obj_on_fs_to_parse)
else:
raise TypeError('Parser attached to this _BaseParsingPlan is not a ' + str(_BaseParser))"
1222,"def create_parsing_plan(self, desired_type: Type[T], filesystem_object: PersistedObject, logger: Logger,
_main_call: bool = True):
""""""
Implements the abstract parent method by using the recursive parsing plan impl. Subclasses wishing to produce
their own parsing plans should rather override _create_parsing_plan in order to benefit from this same log msg.
:param desired_type:
:param filesystem_object:
:param logger:
:param _main_call: internal parameter for recursive calls. Should not be changed by the user.
:return:
""""""
in_root_call = False
# -- log msg only for the root call, not for the children that will be created by the code below
if _main_call and (not hasattr(AnyParser.thrd_locals, 'flag_init') or AnyParser.thrd_locals.flag_init == 0):
# print('Building a parsing plan to parse ' + str(filesystem_object) + ' into a ' +
# get_pretty_type_str(desired_type))
logger.debug('Building a parsing plan to parse [{location}] into a {type}'
''.format(location=filesystem_object.get_pretty_location(append_file_ext=False),
type=get_pretty_type_str(desired_type)))
AnyParser.thrd_locals.flag_init = 1
in_root_call = True
# -- create the parsing plan
try:
pp = self._create_parsing_plan(desired_type, filesystem_object, logger, log_only_last=(not _main_call))
finally:
# remove threadlocal flag if needed
if in_root_call:
AnyParser.thrd_locals.flag_init = 0
# -- log success only if in root call
if in_root_call:
# print('Parsing Plan created successfully')
logger.debug('Parsing Plan created successfully')
# -- finally return