Example #1
0
 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
Example #2
0
 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
Example #3
0
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))
Example #4
0
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:
Example #5
0
    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)
Example #6
0
    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)
            ]
Example #7
0
    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)
Example #8
0
    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)]
Example #9
0
 def test_00_string(self):
     self.assertEqual(parse_string_list("a"), ["a"])
Example #10
0
 def test_02_tuple(self):
     t = ('a', )
     self.assertEqual(parse_string_list(t), ['a'])
Example #11
0
 def test_03_generator(self):
     g = range(10)
     self.assertEqual(parse_string_list(g), list(map(str, g)))
Example #12
0
 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)
Example #13
0
def Export(variables):
    CurrentNest().exports.update(parse_string_list(variables))
Example #14
0
 def test_03_generator(self):
     g = range(10)
     self.assertEqual(parse_string_list(g), list(map(str, g)))
Example #15
0
 def test_02_tuple(self):
     t = ("a",)
     self.assertEqual(parse_string_list(t), ["a"])
Example #16
0
 def test_01_list(self):
     l = ['a']
     self.assertEqual(parse_string_list(l), l)
Example #17
0
 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)
Example #18
0
def Export(variables):
    CurrentNest().exports.update(parse_string_list(variables))

# vim: set sts=4 sw=4 ts=8 expandtab ft=python:
Example #19
0
def Export(variables):
    CurrentNest().exports.update(parse_string_list(variables))
Example #20
0
 def test_02_tuple(self):
     t = ('a',)
     self.assertEqual(parse_string_list(t), ['a'])
Example #21
0
 def test_00_string(self):
     self.assertEqual(parse_string_list('a'), ['a'])
Example #22
0
 def test_01_list(self):
     l = ["a"]
     self.assertEqual(parse_string_list(l), l)
Example #23
0
 def test_00_string(self):
     self.assertEqual(parse_string_list('a'), ['a'])