Ticket #4: yum-multiinclude.patch

File yum-multiinclude.patch, 2.7 kB (added by arogge, 3 years ago)

Patch to allow multiple inclusion of the same file

  • parser.py

    old new  
    5858    def __init__(self, configfile, vars=None): 
    5959        # put the vars away in a helpful place 
    6060        self._vars = vars 
     61 
     62        # used to track the current ini-section 
     63        self._section = None 
    6164         
    6265        # set some file-like object attributes for ConfigParser 
    6366        # these just make confpp look more like a real file object. 
     
    129132                        # whooohoo a valid include line.. push it on the stack 
    130133                        fo = self._pushfile( url ) 
    131134                else: 
     135                    # check if the current line starts a new section 
     136                    secmatch = re.match( r'\s*\[(?P<section>.*)\]', line ) 
     137                    if secmatch: 
     138                        self._section = secmatch.group('section') 
    132139                    # line didn't match include=, just return it as is 
    133140                    # for the ConfigParser 
    134141                    break 
     
    156163            return url 
    157164        else: 
    158165            return urlparse.urljoin( self.geturl(), url ) 
    159      
    160      
     166 
    161167    def _pushfile( self, url ): 
    162168        """ 
    163169        Opens the url specified, pushes it on the stack, and  
     
    169175        # absolutize this url using the including files url 
    170176        # as a base url. 
    171177        absurl = self._absurl(url) 
     178 
     179        # get the current section to add it to the included 
     180        # url's name. 
     181        includetuple = (absurl, self._section) 
    172182        # check if this has previously been included. 
    173         if self._urlalreadyincluded(absurl): 
     183        if self._isalreadyincluded(includetuple): 
    174184            return None 
    175185        try: 
    176186            fo = urlgrabber.grabber.urlopen(absurl) 
     
    179189        if fo is not None: 
    180190            self.name = absurl 
    181191            self._incstack.append( fo ) 
    182             self._alreadyincluded.append(absurl
     192            self._alreadyincluded.append(includetuple
    183193        else: 
    184194            raise Errors.ConfigError, \ 
    185195                  'Error accessing file for config %s' % (absurl) 
     
    199209            self.name = None 
    200210     
    201211     
    202     def _urlalreadyincluded( self, url ): 
     212    def _isalreadyincluded( self, tuple ): 
    203213        """ 
    204         Checks if the url has already been included at all.. this  
    205         does not necessarily have to be recursive 
     214        Checks if the tuple describes an include that was already done. 
     215        This does not necessarily have to be recursive 
    206216        """ 
    207         for eurl in self._alreadyincluded: 
    208             if eurl == url: return 1 
     217        for etuple in self._alreadyincluded: 
     218            if etuple == tuple: return 1 
    209219        return 0 
    210220     
    211221