def doProcess(self, recipe): self.rootdir = self.rootdir % recipe.macros self.targetFilters = [] self.macros = recipe.macros # for filterExpression for targetitem, requirement in self.targetexceptions: filterargs = self.filterExpression(targetitem) self.targetFilters.append( (filter.Filter(*filterargs), requirement)) policy.PackagePolicy.doProcess(self, recipe)
def preProcess(self): exceptDeps = [] for fE, rE in self.exceptDeps: try: exceptDeps.append( (filter.Filter(fE, self.macros), re.compile(rE % self.macros))) except sre_constants.error, e: self.error('Bad regular expression %s for file spec %s: %s', rE, fE, e)
def compileFilters(self, expressionList, filterList, unusedList=None): seen = [] newUnused = [] for expression in expressionList: if expression in seen: # only put each expression on the list once continue if isinstance(expression, action.Glob): expression = expression() elif isinstance(expression, action.Regexp): expression = expression.pattern seen.append(expression) args, kwargs = self.filterExpArgs(expression) f = filter.Filter(*args, **kwargs) if unusedList and expression in unusedList: unusedList.discard(expression) newUnused.append(f.regexp) filterList.append(f) if unusedList is not None: unusedList.update(newUnused)
def do(self): """ Remove files from the Conary package manifest that match any specified filters. """ # Compile the set of filters. filters = {} for name, regex in self.extraFilters: name %= self.macros filters.setdefault(name, []).append( filter.Filter(regex, self.macros, name=name)) # Get a mapping of component name to component object components = dict( (x.name, x) for x in self.recipe.autopkg.getComponents()) for name, fltrs in filters.iteritems(): if name not in components: self.error("Component %s does not exist" % name) continue provides = components[name].provides # make a copy of the files list since it will be modified in place. files = components[name].keys() for fn in files: for fltr in fltrs: if fltr.match(fn): self.recipe.autopkg.delFile(fn) self.recipe._capsulePathMap.pop(fn) self.recipe._capsuleDataMap.pop(fn) provides.removeDeps(deps.FileDependencies, [deps.Dependency(fn)], missingOkay=True) break
def exclude(self, val): if not self.macros: return self.filterlist.append((EXCLUDE, filter.Filter(val, self.macros)))
def do(self): for comp in self.recipe.autopkg.components.items(): capsule = self.recipe._getCapsule(comp[0]) if capsule and capsule[0] == 'rpm': if not self.filters: self.filters = [(x, filter.Filter(x, self.macros)) for x in self.excepts] path = capsule[1] matchFound = False for regexp, f in self.filters: if f.match(path): self.unusedFilters['exceptions'].discard(regexp) matchFound = True if matchFound: continue h = rpmhelper.readHeader(file(path)) rReqs, rProv = h.getDeps( mergeKmodSymbols=self.mergeKmodSymbols) # integrate user specified requirements if self.requirements: userReqs = self.requirements.get(comp[0]) if userReqs: rReqs.union(userReqs) # remove rpm provisions from the requirements rReqs = rReqs.difference(rProv) # cull duplicate rpm reqs that have a standard conary # representations # currently we only handle perl and sonames culledReqs = deps.DependencySet() cnyReqs = comp[1].requires cnyProv = comp[1].provides if rReqs.hasDepClass(deps.RpmDependencies): soDeps = deps.DependencySet() soDeps.addDeps(deps.SonameDependencies, \ list(cnyReqs.iterDepsByClass(deps.SonameDependencies))+\ list(cnyProv.iterDepsByClass(deps.SonameDependencies))) for r in list(rReqs.iterDepsByClass(deps.RpmDependencies)): reMatch = self.rpmStringRe.match(r.name) if reMatch and reMatch.groups(): rpmFile = reMatch.group(1) rpmFlags = reMatch.group(2).strip() else: rpmFile = r.name rpmFlags = '' if rpmFile == 'perl' and rpmFlags: ds = deps.DependencySet() dep = deps.Dependency(rpmFlags) dep.flags = r.flags ds.addDep(deps.PerlDependencies, dep) if cnyReqs.satisfies(ds) or \ cnyProv.satisfies(ds): culledReqs.addDep(deps.RpmDependencies, r) elif '.so' in rpmFile: ds = deps.DependencySet() if rpmFlags == '64bit': elfPrefix = 'ELF64/' else: elfPrefix = 'ELF32/' dep = deps.Dependency(elfPrefix + rpmFile) dep.flags = r.flags ds.addDep(deps.SonameDependencies, dep) if soDeps.satisfies(ds): culledReqs.addDep(deps.RpmDependencies, r) rReqs = rReqs.difference(culledReqs) # remove any excepted deps for filt, exceptRe in self.exceptDeps: if filt.match(path): for depClass, dep in list(rReqs.iterDeps()): matchName = '%s: %s' % (depClass.tagName, str(dep)) if exceptRe.match(matchName): rReqs.removeDeps(depClass, [dep]) cnyReqs.union(rReqs)