(self)
return True
Load the defined file and attempt to build the struct
Load the defined file and attempt to build the struct
Load the defined file and attempt to build the struct
def load_file(self):
        """ Load the defined file and attempt to build the struct
        """
        with open(self.config['replace_file'].value, 'r') as f:
            lines = f.readlines()
            for line in lines:
                if (len(line) > 0 and line[0] == '#') or len(line) <= 2:
                    continue

                cut = line.split(" = ")
                if len(cut) < 2 or len(cut) > 2:
                    util.Error("Incorrect formatting for line '%s'" % cut)
                else:
                    try:
                        if cut[0][0] == '1':
                            # this is a regex entry, parse and try to compile it
                            tmp = re.compile(cut[0][2:])
                            self.replace_regex[cut[0][2:]] = cut[1].rstrip('\n')
                        elif cut[0][0] == '2':
                            #
                            # this is a tag, split it out and build a dictionary.
                            # The dictionary is essentially:
                            #               {'outer' : {'attribute' : 'replacement'}}
                            # Each outer tag may have multiple attributes for 
                            # replacement.
                            #
                            tags = cut[0][2:].split(' ')

                            if tags[0] in self.replace_tags:
                                self.replace_tags[tags[0]][tags[1]] = cut[1].rstrip('\n')
                            else:
                                self.replace_tags[tags[0]] = {}
                                self.replace_tags[tags[0]][tags[1]] = cut[1].rstrip('\n')
                    except:
                        util.Error("Incorrect regex: '%s'" % cut[0][2:])
        util.Msg("Loaded %s matches" % (len(self.replace_regex) + len(self.replace_tags)))
        return True
def load_file ( self ) : with open ( self . config [ 'replace_file' ] . value , 'r' ) as f : lines = f . readlines ( ) for line in lines : if ( len ( line ) > 0 and line [ 0 ] == '#' ) or len ( line ) <= 2 : continue cut = line . split ( " = " ) if len ( cut ) < 2 or len ( cut ) > 2 : util . Error ( "Incorrect formatting for line '%s'" % cut ) else : try : if cut [ 0 ] [ 0 ] == '1' : # this is a regex entry, parse and try to compile it tmp = re . compile ( cut [ 0 ] [ 2 : ] ) self . replace_regex [ cut [ 0 ] [ 2 : ] ] = cut [ 1 ] . rstrip ( '\n' ) elif cut [ 0 ] [ 0 ] == '2' : # # this is a tag, split it out and build a dictionary. # The dictionary is essentially: #               {'outer' : {'attribute' : 'replacement'}} # Each outer tag may have multiple attributes for  # replacement. # tags = cut [ 0 ] [ 2 : ] . split ( ' ' ) if tags [ 0 ] in self . replace_tags : self . replace_tags [ tags [ 0 ] ] [ tags [ 1 ] ] = cut [ 1 ] . rstrip ( '\n' ) else : self . replace_tags [ tags [ 0 ] ] = { } self . replace_tags [ tags [ 0 ] ] [ tags [ 1 ] ] = cut [ 1 ] . rstrip ( '\n' ) except : util . Error ( "Incorrect regex: '%s'" % cut [ 0 ] [ 2 : ] ) util . Msg ( "Loaded %s matches" % ( len ( self . replace_regex ) + len ( self . replace_tags ) ) ) return True