def disable(self, systems): """ Disable logging of specified `systems`. """ for system in parse_string_list(systems): try: self.debug(D_LOGGER, 'disable %s' % system) self.systems.remove(system.upper()) except KeyError: pass
def parse_output_list(output_list=None, input_list=None): """ Return an :func:`~weaver.util.iterable` object of output files. If `output_list` is ``None``, then return ``[]``. If `output_list` is a string template, then use it to generate a list of :class:`File` objects. If `output_list` is already an :func:`~weaver.util.iterable`, then map :class:`File` to `output_list` and return it. This means that `output_list` must be one of the following: 1. ``None`` to leave it to the caller to generate an output file object. 2. A string object to be used as a template. 3. An :func:`~weaver.util.iterable` object (ex. list, iterator, etc.). If `output_list` is a string template, then it may have the following fields: - `{fullpath}`, `{FULL}` -- Full input file path. - `{basename}`, `{BASE}` -- Base input file name. - `{fullpath_woext}`, `{FULLWE}` -- Full input file path without extension - `{basename_woext}`, `{BASEWE}` -- Base input file name without extension """ debug(D_DATA, 'Parsing output list') if output_list is None: return [] if isinstance(output_list, str) or isinstance(output_list, File): # If input list is empty or output list is not a format string, then # return list of single output file. # TODO: support single {stash} if not input_list or not '{' in str(output_list): return [MakeFile(output_list)] nest = CurrentNest() return [ MakeFile( str(output_list).format( fullpath=input, FULL=input, i='{0:05X}'.format(i), NUMBER='{0:05X}'.format(i), stash=next(nest.stash) if '{stash}' in output_list else '', fullpath_woext=os.path.splitext(input)[0], FULL_WOEXT=os.path.splitext(input)[0], basename=os.path.basename(input), BASE=os.path.basename(input), basename_woext=os.path.splitext( os.path.basename(input))[0], BASE_WOEXT=os.path.splitext(os.path.basename(input))[0])) for i, input in enumerate(parse_string_list(input_list)) ] if iterable(output_list): return [MakeFile(o) for o in parse_object_list(output_list)] raise WeaverError( D_DATA, 'Could not parse output argument: {0}'.format(output_list))
def parse_output_list(output_list=None, input_list=None): """ Return an :func:`~weaver.util.iterable` object of output files. If `output_list` is ``None``, then return ``[]``. If `output_list` is a string template, then use it to generate a list of :class:`File` objects. If `output_list` is already an :func:`~weaver.util.iterable`, then map :class:`File` to `output_list` and return it. This means that `output_list` must be one of the following: 1. ``None`` to leave it to the caller to generate an output file object. 2. A string object to be used as a template. 3. An :func:`~weaver.util.iterable` object (ex. list, iterator, etc.). If `output_list` is a string template, then it may have the following fields: - `{fullpath}`, `{FULL}` -- Full input file path. - `{basename}`, `{BASE}` -- Base input file name. - `{fullpath_woext}`, `{FULLWE}` -- Full input file path without extension - `{basename_woext}`, `{BASEWE}` -- Base input file name without extension """ debug(D_DATA, 'Parsing output list') if output_list is None: return [] if isinstance(output_list, str) or isinstance(output_list, File): # If input list is empty or output list is not a format string, then # return list of single output file. # TODO: support single {stash} if not input_list or not '{' in str(output_list): return [MakeFile(output_list)] nest = CurrentNest() return [MakeFile(str(output_list).format( fullpath = input, FULL = input, i = '{0:05X}'.format(i), NUMBER = '{0:05X}'.format(i), stash = next(nest.stash) if '{stash}' in output_list else '', fullpath_woext = os.path.splitext(input)[0], FULL_WOEXT = os.path.splitext(input)[0], basename = os.path.basename(input), BASE = os.path.basename(input), basename_woext = os.path.splitext(os.path.basename(input))[0] if os.path.splitext(os.path.basename(input))[1] != ".gz" else os.path.splitext(os.path.splitext(os.path.basename(input))[0])[0], BASE_WOEXT = os.path.splitext(os.path.basename(input))[0] if os.path.splitext(os.path.basename(input))[1] != ".gz" else os.path.splitext(os.path.splitext(os.path.basename(input))[0])[0])) for i, input in enumerate(parse_string_list(input_list))] if iterable(output_list): return [MakeFile(o) for o in parse_object_list(output_list)] raise WeaverError(D_DATA, 'Could not parse output argument: {0}'.format(output_list)) # vim: set sts=4 sw=4 ts=8 expandtab ft=python:
def command_format(self, inputs=None, outputs=None, arguments=None): """ Returns command string by formatting function template with `inputs` and `outputs` arguments. This method requires the user to **explicitly** specify the `inputs` and `outputs` to be used in the command string. """ inputs = ' '.join(parse_string_list(inputs)) outputs = ' '.join(parse_string_list(outputs)) arguments = ' '.join(parse_string_list(arguments)) return self.cmd_format.format(executable=self.path, EXE=self.path, inputs=inputs, IN=inputs, outputs=outputs, OUT=outputs, arguments=arguments, ARG=arguments)
def get_outputs(self, output_list=None, input_list=None): """ If `output_list` is a string template, then it may have the following fields: - `{fullpath}`, `{FULL}` -- Full input file path. - `{basename}`, `{BASE}` -- Base input file name. - `{fullpath_woext}`, `{FULLWE}` -- Full input file path without extension - `{basename_woext}`, `{BASEWE}` -- Base input file name without extension """ if output_list is None: return [] if isinstance(output_list, str): ilist = [] if not input_list or not '{' in str(output_list): if input_list is not None and len(input_list) == 0: return [] else: return [output_list] # if multiple list of inputs is used elif isinstance(input_list[0], list): for i, val in enumerate(input_list[0]): iter_values = [] for j, ingroup in enumerate(input_list): iter_values.append(os.path.basename(input_list[j][i])) ilist.append(self._longestCommonSubstr(iter_values)) else: ilist = parse_string_list(input_list) return [ os.path.join( self.output_directory, str(output_list).format( fullpath=input, FULL=input, i='{0:05X}'.format(i), NUMBER='{0:05X}'.format(i), fullpath_woext=os.path.splitext(input)[0], FULL_WOEXT=os.path.splitext(input)[0], basename=os.path.basename(input), BASE=os.path.basename(input), basename_woext=os.path.splitext( os.path.basename(input))[0] if os.path.splitext(os.path.basename(input))[1] != ".gz" else os.path.splitext( os.path.splitext(os.path.basename(input))[0])[0], BASE_WOEXT=os.path.splitext(os.path.basename(input))[0] if os.path.splitext(os.path.basename(input))[1] != ".gz" else os.path.splitext( os.path.splitext(os.path.basename(input))[0])[0])) for i, input in enumerate(ilist) ]
def command_format(self, inputs=None, outputs=None, arguments=None): """ Returns command string by formatting function template with `inputs` and `outputs` arguments. This method requires the user to **explicitly** specify the `inputs` and `outputs` to be used in the command string. """ inputs = ' '.join(parse_string_list(inputs)) outputs = ' '.join(parse_string_list(outputs)) arguments = ' '.join(parse_string_list(arguments)) return self.cmd_format.format( executable = self.path, EXE = self.path, inputs = inputs, IN = inputs, outputs = outputs, OUT = outputs, arguments = arguments, ARG = arguments)
def get_outputs(self, output_list=None, input_list=None): """ If `output_list` is a string template, then it may have the following fields: - `{fullpath}`, `{FULL}` -- Full input file path. - `{basename}`, `{BASE}` -- Base input file name. - `{fullpath_woext}`, `{FULLWE}` -- Full input file path without extension - `{basename_woext}`, `{BASEWE}` -- Base input file name without extension """ if output_list is None: return [] if isinstance(output_list, str): ilist = [] if not input_list or not '{' in str(output_list): if input_list is not None and len(input_list) == 0: return [] else: return [output_list] # if multiple list of inputs is used elif isinstance(input_list[0], list): for i, val in enumerate(input_list[0]): iter_values = [] for j, ingroup in enumerate(input_list): iter_values.append(os.path.basename(input_list[j][i])) ilist.append(self._longestCommonSubstr(iter_values)) else: ilist = parse_string_list(input_list) return [os.path.join(self.output_directory, str(output_list).format( fullpath = input, FULL = input, i = '{0:05X}'.format(i), NUMBER = '{0:05X}'.format(i), fullpath_woext = os.path.splitext(input)[0], FULL_WOEXT = os.path.splitext(input)[0], basename = os.path.basename(input), BASE = os.path.basename(input), basename_woext = os.path.splitext(os.path.basename(input))[0] if os.path.splitext(os.path.basename(input))[1] != ".gz" else os.path.splitext(os.path.splitext(os.path.basename(input))[0])[0], BASE_WOEXT = os.path.splitext(os.path.basename(input))[0] if os.path.splitext(os.path.basename(input))[1] != ".gz" else os.path.splitext(os.path.splitext(os.path.basename(input))[0])[0])) for i, input in enumerate(ilist)]
def test_00_string(self): self.assertEqual(parse_string_list("a"), ["a"])
def test_02_tuple(self): t = ('a', ) self.assertEqual(parse_string_list(t), ['a'])
def test_03_generator(self): g = range(10) self.assertEqual(parse_string_list(g), list(map(str, g)))
def enable(self, systems): """ Enable logging of specified `systems`. """ for system in parse_string_list(systems): self.systems.add(system.lower()) self.debug(D_LOGGER, 'enable %s' % system)
def Export(variables): CurrentNest().exports.update(parse_string_list(variables))
def test_02_tuple(self): t = ("a",) self.assertEqual(parse_string_list(t), ["a"])
def test_01_list(self): l = ['a'] self.assertEqual(parse_string_list(l), l)
def Export(variables): CurrentNest().exports.update(parse_string_list(variables)) # vim: set sts=4 sw=4 ts=8 expandtab ft=python:
def test_02_tuple(self): t = ('a',) self.assertEqual(parse_string_list(t), ['a'])
def test_00_string(self): self.assertEqual(parse_string_list('a'), ['a'])
def test_01_list(self): l = ["a"] self.assertEqual(parse_string_list(l), l)