def test_unindent(self):
     lines1 = ['   qwe',
               '  etryry',
               '',
               '     xxx',
               ]
     self.assertEquals(fut.unindent(lines1),  
                       [' qwe', 'etryry', '', '   xxx'])
     self.assertEquals(fut.unindent([]), [])
     lines2 = ['a', 'b', 'c']
     self.assertEquals(fut.unindent(lines2), lines2)
示例#2
0
 def test_unindent(self):
     lines1 = [
         '   qwe',
         '  etryry',
         '',
         '     xxx',
     ]
     self.assertEquals(fut.unindent(lines1),
                       [' qwe', 'etryry', '', '   xxx'])
     self.assertEquals(fut.unindent([]), [])
     lines2 = ['a', 'b', 'c']
     self.assertEquals(fut.unindent(lines2), lines2)
示例#3
0
    def _read_config(self):
        """ Read pipeline configuration from three possible sources:
        
        (1) Fixed class variable config, not requiring an input parameter
        (2) External configuration file
        (3) Configuration in a multi-line text variable  ???????????????
        
        Here is an example configuration file, with the two special
        headings, [--main--] and [--route--]
        
        [--main--]
        ftype = foo
        description = TO-DO: docstring
        # a1, a2, b1, b2 are essential keys, while gfgf, jj, and uuu
        # are optional, with default values.
        keys = a1, a2, b1, b2, gfgf:34, jj:fred, uuu:none
                    
        [filter34]
        adasd = 45
        space = 96
        name = bill
        
        [--route--]
        temp_text_after1:${a1} >>>
        temp_text_before1:${b1} >>>
        reverse_string1 >>>
        temp_text_after2:${a2} >>>
        temp_text_before2:${b2} >>>
        reverse_string2                    
        """
        # config has been passed in as parameter, or set as class attribute
        config_lines = self.config.splitlines()
        if len(config_lines) == 1:
            # Then the config was a file name containing the actual config
            config_file = open(config_lines[0])
            try:
                config_lines = config_file.readlines()
            finally:
                config_file.close()
        ### Move config input left if whole file is indented
        ### TO-DO Put this into FilterUtils -- unindent_block()
        ##config_lines2 = []
        ##for line in config_lines:
####            print '**10624** "%s"' % line
##if not line.startswith(' ' * 4) and line.strip():
##break
##config_lines2.append(line[4:])
##else:
### All lines had 4 spaces at the start
##config_lines = config_lines2
        config_lines2 = fut.unindent(config_lines)

        ##      print '**10622** line %5.5d: %s' % (line_no, line)
        # Before stripping lines, check for python code filters. We have to
        # prefix each line with "line_XXXXX =" to get it through config_obj.
        self.in_python = False
        self.config_lines3 = []
        self.all_global_params = set()
        for line_no, line in enumerate(config_lines2):
            if self.in_python:
                if line.startswith('['):
                    self._python_function_end()
                    self.config_lines3.append(line)
                else:
                    line = self._python_function_middle(1000 + line_no, line)
                self.this_fn_lines.append(line)
            else:
                self.config_lines3.append(line)
##            print '**10620**', line
            if line.startswith('[py_'):
                self._python_function_start(line)
        if self.in_python:
            self._python_function_end()
##        print '**12400** config_lines3 =\n------------\n%s' % (
##            '\n'.join(self.config_lines3))
# Remove white space and blank lines
        config_lines4 = [
            line.strip() for line in self.config_lines3 if line.strip()
        ]
        ##        print '**10621** ----------------\nconfig_lines4 =\n', config_lines4
        # All pipeline configs must have a '[--route--]' section, as the final
        # section in the *.pype file. Read and split the file into two parts.
        try:
            route_heading_index = config_lines4.index('[--route--]')
        except ValueError:
            # TO-DO <<<< Put all these errors together in a list
            msg = '[--route--] heading is missing from config for class %s'
            raise dfb.FilterRoutingError, msg % self.__class__.__name__
        self.config_only = config_lines4[:route_heading_index]
        self.route = '\n'.join(config_lines4[route_heading_index + 1:])
        if not self.route.strip():
            msg = '[--route--] section is empty for class %s'
            raise dfb.FilterRoutingError, msg % self.__class__.__name__
示例#4
0
    def _read_config(self):
        """ Read pipeline configuration from three possible sources:
        
        (1) Fixed class variable config, not requiring an input parameter
        (2) External configuration file
        (3) Configuration in a multi-line text variable  ???????????????
        
        Here is an example configuration file, with the two special
        headings, [--main--] and [--route--]
        
        [--main--]
        ftype = foo
        description = TO-DO: docstring
        # a1, a2, b1, b2 are essential keys, while gfgf, jj, and uuu
        # are optional, with default values.
        keys = a1, a2, b1, b2, gfgf:34, jj:fred, uuu:none
                    
        [filter34]
        adasd = 45
        space = 96
        name = bill
        
        [--route--]
        temp_text_after1:${a1} >>>
        temp_text_before1:${b1} >>>
        reverse_string1 >>>
        temp_text_after2:${a2} >>>
        temp_text_before2:${b2} >>>
        reverse_string2                    
        """
        # config has been passed in as parameter, or set as class attribute
        config_lines = self.config.splitlines()
        if len(config_lines) == 1:
            # Then the config was a file name containing the actual config
            config_file = open(config_lines[0])
            try:
                config_lines = config_file.readlines()
            finally:
                config_file.close()
        ### Move config input left if whole file is indented
        ### TO-DO Put this into FilterUtils -- unindent_block()
        ##config_lines2 = []
        ##for line in config_lines:
####            print '**10624** "%s"' % line
            ##if not line.startswith(' ' * 4) and line.strip():
                ##break
            ##config_lines2.append(line[4:])
        ##else:
            ### All lines had 4 spaces at the start
            ##config_lines = config_lines2
        config_lines2 = fut.unindent(config_lines)
            
      ##      print '**10622** line %5.5d: %s' % (line_no, line)
        # Before stripping lines, check for python code filters. We have to 
        # prefix each line with "line_XXXXX =" to get it through config_obj.
        self.in_python = False
        self.config_lines3 = []
        self.all_global_params = set()
        for line_no, line in enumerate(config_lines2):
            if self.in_python:
                if line.startswith('['):
                    self._python_function_end()
                    self.config_lines3.append(line)  
                else:
                    line = self._python_function_middle(1000 + line_no, line)
                self.this_fn_lines.append(line)
            else:
                self.config_lines3.append(line)  
##            print '**10620**', line
            if line.startswith('[py_'):
                self._python_function_start(line)
        if self.in_python:    
            self._python_function_end()
##        print '**12400** config_lines3 =\n------------\n%s' % (
##            '\n'.join(self.config_lines3))       
        # Remove white space and blank lines
        config_lines4 = [line.strip() for line in self.config_lines3 
                         if line.strip()]
##        print '**10621** ----------------\nconfig_lines4 =\n', config_lines4
        # All pipeline configs must have a '[--route--]' section, as the final
        # section in the *.pype file. Read and split the file into two parts.
        try:
            route_heading_index = config_lines4.index('[--route--]')
        except ValueError:
            # TO-DO <<<< Put all these errors together in a list
            msg = '[--route--] heading is missing from config for class %s' 
            raise dfb.FilterRoutingError, msg % self.__class__.__name__
        self.config_only = config_lines4[:route_heading_index]
        self.route = '\n'.join(config_lines4[route_heading_index + 1:])
        if not self.route.strip():
            msg = '[--route--] section is empty for class %s'
            raise dfb.FilterRoutingError, msg % self.__class__.__name__