<s> """<STR_LIT>""" <EOL> import os <EOL> import re <EOL> import stat <EOL> import sre_constants <EOL> from conary import files <EOL> from conary . lib import util <EOL> from conary import rpmhelper <EOL> from conary . deps import deps <EOL> from conary . build import filter <EOL> from conary . build import policy <EOL> from conary . build import packagepolicy <EOL> class ComponentSpec ( packagepolicy . ComponentSpec ) : <EOL> requires = ( x for x in packagepolicy . ComponentSpec . requires <EOL> if x [ <NUM_LIT:0> ] != '<STR_LIT>' ) <EOL> class Config ( packagepolicy . Config ) : <EOL> invariantinclusions = None <EOL> invariantexceptions = [ ] <EOL> processUnmodified = True <EOL> requires = ( <EOL> ( '<STR_LIT>' , policy . REQUIRED_PRIOR ) , <EOL> ( '<STR_LIT>' , policy . CONDITIONAL_SUBSEQUENT ) , <EOL> ( '<STR_LIT>' , policy . REQUIRED_SUBSEQUENT ) , <EOL> ) <EOL> def doFile ( self , filename ) : <EOL> fullpath = self . macros . destdir + filename <EOL> hardlinkMap = self . recipe . autopkg . findComponent ( filename ) . hardlinkMap <EOL> if ( os . path . isfile ( fullpath ) and util . isregular ( fullpath ) and <EOL> not self . _fileIsBinary ( filename , fullpath , maxsize = <NUM_LIT:20> * <NUM_LIT> ) and <EOL> not filename in hardlinkMap ) : <EOL> self . info ( filename ) <EOL> for pkg in self . recipe . autopkg . findComponents ( filename ) : <EOL> f = pkg . getFile ( filename ) <EOL> f . flags . isConfig ( True ) <EOL> else : <EOL> self . recipe . InitialContents ( filename ) <EOL> class InitialContents ( packagepolicy . InitialContents ) : <EOL> invariantinclusions = None <EOL> invariantexceptions = [ ] <EOL> processUnmodified = True <EOL> def updateArgs ( self , * args , ** keywords ) : <EOL> policy . Policy . updateArgs ( self , * args , ** keywords ) <EOL> def doFile ( self , filename ) : <EOL> fullpath = self . macros . destdir + filename <EOL> recipe = self . recipe <EOL> if not os . path . isdir ( fullpath ) or os . path . islink ( fullpath ) : <EOL> for pkg in self . recipe . autopkg . findComponents ( filename ) : <EOL> f = pkg . getFile ( filename ) <EOL> if f . flags . isConfig ( ) : <EOL> return <EOL> self . info ( filename ) <EOL> for pkg in self . recipe . autopkg . findComponents ( filename ) : <EOL> f = pkg . getFile ( filename ) <EOL> f . flags . isInitialContents ( True ) <EOL> class Transient ( packagepolicy . Transient ) : <EOL> invariantinclusions = None <EOL> processUnmodified = True <EOL> def doFile ( self , filename ) : <EOL> fullpath = self . macros . destdir + filename <EOL> if os . path . isfile ( fullpath ) and util . isregular ( fullpath ) : <EOL> recipe = self . recipe <EOL> for pkg in self . recipe . autopkg . findComponents ( filename ) : <EOL> f = pkg . getFile ( filename ) <EOL> if f . flags . isConfig ( ) or f . flags . isInitialContents ( ) : <EOL> return <EOL> self . info ( filename ) <EOL> for pkg in self . recipe . autopkg . findComponents ( filename ) : <EOL> f = pkg . getFile ( filename ) <EOL> f . flags . isTransient ( True ) <EOL> class MissingOkay ( policy . Policy ) : <EOL> """<STR_LIT>""" <EOL> requires = ( <EOL> ( '<STR_LIT>' , policy . REQUIRED_PRIOR ) , <EOL> ) <EOL> bucket = policy . PACKAGE_CREATION <EOL> filetree = policy . PACKAGE <EOL> processUnmodified = True <EOL> invariantinclusions = None <EOL> invariantexceptions = [ ] <EOL> def doFile ( self , filename ) : <EOL> if not self . recipe . _getCapsulePathsForFile ( filename ) : <EOL> return <EOL> self . info ( filename ) <EOL> for pkg in self . recipe . autopkg . findComponents ( filename ) : <EOL> f = pkg . getFile ( filename ) <EOL> f . flags . isMissingOkay ( True ) <EOL> class setModes ( packagepolicy . setModes ) : <EOL> def do ( self ) : <EOL> for filename , package , _ , _ , mode , mtime in self . recipe . _iterCapsulePathData ( ) : <EOL> mode = stat . S_IMODE ( mode ) <EOL> for pkg in self . recipe . autopkg . findComponents ( filename ) : <EOL> if pkg . getName ( ) == package : <EOL> f = pkg . getFile ( filename ) <EOL> f . inode . perms . set ( mode ) <EOL> if f . inode . mtime ( ) != mtime : <EOL> f . inode . mtime . set ( mtime ) <EOL> packagepolicy . setModes . do ( self ) <EOL> class Ownership ( packagepolicy . Ownership ) : <EOL> def do ( self ) : <EOL> for filename , package , user , group , _ , _ in self . recipe . _iterCapsulePathData ( ) : <EOL> for pkg in self . recipe . autopkg . findComponents ( filename ) : <EOL> if pkg . getName ( ) == package : <EOL> f = pkg . getFile ( filename ) <EOL> f . inode . owner . set ( user ) <EOL> f . inode . group . set ( group ) <EOL> packagepolicy . Ownership . do ( self ) <EOL> class Payload ( policy . Policy ) : <EOL> """<STR_LIT>""" <EOL> bucket = policy . PACKAGE_CREATION <EOL> filetree = policy . PACKAGE <EOL> processUnmodified = True <EOL> requires = ( <EOL> ( '<STR_LIT>' , policy . REQUIRED_PRIOR ) , <EOL> ( '<STR_LIT>' , policy . REQUIRED_PRIOR ) , <EOL> ) <EOL> def doFile ( self , filename ) : <EOL> if self . recipe . _getCapsulePathsForFile ( filename ) : <EOL> for pkg in self . recipe . autopkg . findComponents ( filename ) : <EOL> f = pkg . getFile ( filename ) <EOL> if ( isinstance ( f , files . RegularFile ) <EOL> and not f . flags . isConfig ( ) <EOL> and not ( f . flags . isInitialContents ( ) <EOL> and not f . contents . size ( ) ) ) : <EOL> f . flags . isEncapsulatedContent ( True ) <EOL> class RPMProvides ( policy . Policy ) : <EOL> """<STR_LIT>""" <EOL> bucket = policy . PACKAGE_CREATION <EOL> requires = ( <EOL> ( '<STR_LIT>' , policy . REQUIRED_PRIOR ) , <EOL> ) <EOL> keywords = { <EOL> '<STR_LIT>' : { } <EOL> } <EOL> provisionRe = re . compile ( '<STR_LIT>' ) <EOL> def __init__ ( self , * args , ** keywords ) : <EOL> policy . Policy . __init__ ( self , * args , ** keywords ) <EOL> self . mergeKmodSymbols = False <EOL> self . exceptDeps = [ ] <EOL> def updateArgs ( self , * args , ** keywords ) : <EOL> if len ( args ) is <NUM_LIT:2> : <EOL> name = args [ <NUM_LIT:1> ] <EOL> if '<STR_LIT::>' not in name : <EOL> name = name + '<STR_LIT>' <EOL> if not self . provisions . get ( name ) : <EOL> self . provisions [ name ] = deps . DependencySet ( ) <EOL> reMatch = self . provisionRe . match ( args [ <NUM_LIT:0> ] ) <EOL> if not reMatch or len ( reMatch . groups ( ) ) != <NUM_LIT:3> : <EOL> return <EOL> depClass = reMatch . group ( <NUM_LIT:1> ) . strip ( ) . lower ( ) <EOL> if depClass != '<STR_LIT>' and depClass != '<STR_LIT>' : <EOL> raise policy . PolicyError , "<STR_LIT>" "<STR_LIT>" % args [ <NUM_LIT:0> ] <EOL> dep = reMatch . group ( <NUM_LIT:2> ) . strip ( ) <EOL> flags = reMatch . group ( <NUM_LIT:3> ) . strip ( ) . split ( ) <EOL> flags = [ ( x , deps . FLAG_SENSE_REQUIRED ) for x in flags if x ] <EOL> if not self . provisions . get ( name ) : <EOL> self . provisions [ name ] = deps . DependencySet ( ) <EOL> self . provisions [ name ] . addDep ( <EOL> deps . dependencyClassesByName [ depClass ] , <EOL> deps . Dependency ( dep , flags ) ) <EOL> exceptDeps = keywords . pop ( '<STR_LIT>' , None ) <EOL> if exceptDeps : <EOL> if type ( exceptDeps ) is str : <EOL> exceptDeps = ( '<STR_LIT>' , exceptDeps ) <EOL> assert ( type ( exceptDeps ) == tuple ) <EOL> if type ( exceptDeps [ <NUM_LIT:0> ] ) is tuple : <EOL> self . exceptDeps . extend ( exceptDeps ) <EOL> else : <EOL> self . exceptDeps . append ( exceptDeps ) <EOL> if '<STR_LIT>' in keywords : <EOL> self . mergeKmodSymbols = keywords . pop ( '<STR_LIT>' ) <EOL> policy . Policy . updateArgs ( self , ** keywords ) <EOL> def preProcess ( self ) : <EOL> exceptDeps = [ ] <EOL> for fE , rE in self . exceptDeps : <EOL> try : <EOL> exceptDeps . append ( ( filter . Filter ( fE , self . macros ) , <EOL> re . compile ( rE % self . macros ) ) ) <EOL> except sre_constants . error , e : <EOL> self . error ( '<STR_LIT>' , <EOL> rE , fE , e ) <EOL> self . exceptDeps = exceptDeps <EOL> def do ( self ) : <EOL> for comp in self . recipe . autopkg . components . items ( ) : <EOL> capsule = self . recipe . _getCapsule ( comp [ <NUM_LIT:0> ] ) <EOL> if capsule and capsule [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> path = capsule [ <NUM_LIT:1> ] <EOL> h = rpmhelper . readHeader ( file ( path ) ) <EOL> prov = h . getProvides ( mergeKmodSymbols = self . mergeKmodSymbols , <EOL> enableRPMVersionDeps = self . recipe . cfg . enableRPMVersionDeps ) <EOL> fltrprov = self . _filterProvides ( comp [ <NUM_LIT:0> ] , prov ) <EOL> comp [ <NUM_LIT:1> ] . provides . union ( fltrprov ) <EOL> if self . provisions : <EOL> userProvs = self . provisions . get ( comp [ <NUM_LIT:0> ] ) <EOL> if userProvs : <EOL> comp [ <NUM_LIT:1> ] . provides . union ( userProvs ) <EOL> def _filterProvides ( self , compName , provides ) : <EOL> removeDeps = deps . DependencySet ( ) <EOL> for depClass , dep in provides . iterDeps ( ) : <EOL> for compRe , depRe in self . exceptDeps : <EOL> if not compRe . match ( compName ) : <EOL> continue <EOL> depName = '<STR_LIT>' % ( depClass . tagName , str ( dep ) ) <EOL> if depRe . match ( depName ) : <EOL> removeDeps . addDep ( depClass , dep ) <EOL> break <EOL> return provides - removeDeps <EOL> class RPMRequires ( policy . Policy ) : <EOL> """<STR_LIT>""" <EOL> bucket = policy . PACKAGE_CREATION <EOL> requires = ( <EOL> ( '<STR_LIT>' , policy . REQUIRED_PRIOR ) , <EOL> ( '<STR_LIT>' , policy . REQUIRED_PRIOR ) , <EOL> ( '<STR_LIT>' , policy . REQUIRED_SUBSEQUENT ) , <EOL> ) <EOL> keywords = { <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : [ ] <EOL> } <EOL> requirementRe = re . compile ( '<STR_LIT>' ) <EOL> rpmStringRe = re . compile ( '<STR_LIT>' ) <EOL> def __init__ ( self , * args , ** keywords ) : <EOL> policy . Policy . __init__ ( self , * args , ** keywords ) <EOL> self . excepts = set ( ) <EOL> self . requirements = { } <EOL> self . filters = [ ] <EOL> self . mergeKmodSymbols = False <EOL> def updateArgs ( self , * args , ** keywords ) : <EOL> if len ( args ) is <NUM_LIT:2> : <EOL> name = args [ <NUM_LIT:1> ] <EOL> if '<STR_LIT::>' not in name : <EOL> name = name + '<STR_LIT>' <EOL> reMatch = self . requirementRe . match ( args [ <NUM_LIT:0> ] ) <EOL> if not reMatch or len ( reMatch . groups ( ) ) != <NUM_LIT:3> : <EOL> return <EOL> depClass = reMatch . group ( <NUM_LIT:1> ) . strip ( ) . lower ( ) <EOL> if depClass != '<STR_LIT>' and depClass != '<STR_LIT>' : <EOL> raise policy . PolicyError , "<STR_LIT>" "<STR_LIT>" % args [ <NUM_LIT:0> ] <EOL> dep = reMatch . group ( <NUM_LIT:2> ) . strip ( ) <EOL> flags = reMatch . group ( <NUM_LIT:3> ) . strip ( ) . split ( ) <EOL> flags = [ ( x , deps . FLAG_SENSE_REQUIRED ) for x in flags if x ] <EOL> if not self . requirements . get ( name ) : <EOL> self . requirements [ name ] = deps . DependencySet ( ) <EOL> self . requirements [ name ] . addDep ( <EOL> deps . dependencyClassesByName [ depClass ] , <EOL> deps . Dependency ( dep , flags ) ) <EOL> allowUnusedFilters = keywords . pop ( '<STR_LIT>' , False ) or self . allowUnusedFilters <EOL> exceptions = keywords . pop ( '<STR_LIT>' , None ) <EOL> if exceptions : <EOL> if type ( exceptions ) is str : <EOL> self . excepts . add ( exceptions ) <EOL> if not allowUnusedFilters : <EOL> self . unusedFilters [ '<STR_LIT>' ] . add ( exceptions ) <EOL> elif type ( exceptions ) in ( tuple , list ) : <EOL> self . excepts . update ( exceptions ) <EOL> if not allowUnusedFilters : <EOL> self . unusedFilters [ '<STR_LIT>' ] . update ( exceptions ) <EOL> exceptDeps = keywords . pop ( '<STR_LIT>' , None ) <EOL> if exceptDeps : <EOL> if type ( exceptDeps ) is str : <EOL> exceptDeps = ( '<STR_LIT>' , exceptDeps ) <EOL> assert ( type ( exceptDeps ) == tuple ) <EOL> if type ( exceptDeps [ <NUM_LIT:0> ] ) is tuple : <EOL> self . exceptDeps . extend ( exceptDeps ) <EOL> else : <EOL> self . exceptDeps . append ( exceptDeps ) <EOL> if '<STR_LIT>' in keywords : <EOL> self . mergeKmodSymbols = keywords . pop ( '<STR_LIT>' ) <EOL> self . recipe . RPMProvides ( _mergeKmodSymbols = self . mergeKmodSymbols ) <EOL> policy . Policy . updateArgs ( self , ** keywords ) <EOL> def preProcess ( self ) : <EOL> exceptDeps = [ ] <EOL> for fE , rE in self . exceptDeps : <EOL> try : <EOL> exceptDeps . append ( ( filter . Filter ( fE , self . macros ) , <EOL> re . compile ( rE % self . macros ) ) ) <EOL> except sre_constants . error , e : <EOL> self . error ( '<STR_LIT>' , <EOL> rE , fE , e ) <EOL> self . exceptDeps = exceptDeps <EOL> def do ( self ) : <EOL> for comp in self . recipe . autopkg . components . items ( ) : <EOL> capsule = self . recipe . _getCapsule ( comp [ <NUM_LIT:0> ] ) <EOL> if capsule and capsule [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> if not self . filters : <EOL> self . filters = [ ( x , filter . Filter ( x , self . macros ) ) <EOL> for x in self . excepts ] <EOL> path = capsule [ <NUM_LIT:1> ] <EOL> matchFound = False <EOL> for regexp , f in self . filters : <EOL> if f . match ( path ) : <EOL> self . unusedFilters [ '<STR_LIT>' ] . discard ( regexp ) <EOL> matchFound = True <EOL> if matchFound : <EOL> continue <EOL> h = rpmhelper . readHeader ( file ( path ) ) <EOL> rReqs , rProv = h . getDeps ( mergeKmodSymbols = self . mergeKmodSymbols , <EOL> enableRPMVersionDeps = self . recipe . cfg . enableRPMVersionDeps ) <EOL> if self . requirements : <EOL> userReqs = self . requirements . get ( comp [ <NUM_LIT:0> ] ) <EOL> if userReqs : <EOL> rReqs . union ( userReqs ) <EOL> rReqs = rReqs . difference ( rProv ) <EOL> culledReqs = deps . DependencySet ( ) <EOL> cnyReqs = comp [ <NUM_LIT:1> ] . requires <EOL> cnyProv = comp [ <NUM_LIT:1> ] . provides <EOL> if rReqs . hasDepClass ( deps . RpmDependencies ) : <EOL> soDeps = deps . DependencySet ( ) <EOL> soDeps . addDeps ( deps . SonameDependencies , list ( cnyReqs . iterDepsByClass ( deps . SonameDependencies ) ) + list ( cnyProv . iterDepsByClass ( deps . SonameDependencies ) ) ) <EOL> for r in list ( rReqs . iterDepsByClass ( deps . RpmDependencies ) ) : <EOL> reMatch = self . rpmStringRe . match ( r . name ) <EOL> if reMatch and reMatch . groups ( ) : <EOL> rpmFile = reMatch . group ( <NUM_LIT:1> ) <EOL> rpmFlags = reMatch . group ( <NUM_LIT:2> ) . strip ( ) <EOL> else : <EOL> rpmFile = r . name <EOL> rpmFlags = '<STR_LIT>' <EOL> if rpmFile == '<STR_LIT>' and rpmFlags : <EOL> ds = deps . DependencySet ( ) <EOL> dep = deps . Dependency ( rpmFlags ) <EOL> dep . flags = r . flags <EOL> ds . addDep ( deps . PerlDependencies , dep ) <EOL> if cnyReqs . satisfies ( ds ) or cnyProv . satisfies ( ds ) : <EOL> culledReqs . addDep ( <EOL> deps . RpmDependencies , r ) <EOL> elif '<STR_LIT>' in rpmFile : <EOL> ds = deps . DependencySet ( ) <EOL> if rpmFlags == '<STR_LIT>' : <EOL> elfPrefix = '<STR_LIT>' <EOL> else : <EOL> elfPrefix = '<STR_LIT>' <EOL> dep = deps . Dependency ( elfPrefix + rpmFile ) <EOL> dep . flags = r . flags <EOL> ds . addDep ( deps . SonameDependencies , dep ) <EOL> if soDeps . satisfies ( ds ) : <EOL> culledReqs . addDep ( deps . RpmDependencies , r ) <EOL> rReqs = rReqs . difference ( culledReqs ) <EOL> for filt , exceptRe in self . exceptDeps : <EOL> if filt . match ( path ) : <EOL> for depClass , dep in list ( rReqs . iterDeps ( ) ) : <EOL> matchName = '<STR_LIT>' % ( depClass . tagName , str ( dep ) ) <EOL> if exceptRe . match ( matchName ) : <EOL> rReqs . removeDeps ( depClass , [ dep ] ) <EOL> cnyReqs . union ( rReqs ) <EOL> class PureCapsuleComponents ( policy . Policy ) : <EOL> """<STR_LIT>""" <EOL> bucket = policy . ENFORCEMENT <EOL> requires = ( <EOL> ( '<STR_LIT>' , policy . REQUIRED_PRIOR ) , <EOL> ) <EOL> def doFile ( self , path ) : <EOL> inCapsule = bool ( self . recipe . _getCapsulePathsForFile ( path ) ) <EOL> if inCapsule : <EOL> return <EOL> comp = self . recipe . autopkg . componentMap . get ( path , None ) <EOL> if comp : <EOL> compHasCapsule = bool ( self . recipe . _hasCapsulePackage ( comp . name ) ) <EOL> if compHasCapsule : <EOL> self . error ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( comp . name , path ) ) <EOL> class CapsuleModifications ( policy . Policy ) : <EOL> """<STR_LIT>""" <EOL> bucket = policy . PACKAGE_CREATION <EOL> filetree = policy . PACKAGE <EOL> requires = ( <EOL> ( '<STR_LIT>' , policy . REQUIRED_PRIOR ) , <EOL> ( '<STR_LIT>' , policy . REQUIRED_PRIOR ) , <EOL> ) <EOL> def doFile ( self , filename ) : <EOL> changeState = self . fileChanged ( filename ) <EOL> if changeState : <EOL> for pkg in self . recipe . autopkg . findComponents ( filename ) : <EOL> capPath = self . recipe . _getCapsulePathsForFile ( filename ) <EOL> hasCapsule = bool ( self . recipe . _hasCapsulePackage ( pkg . name ) ) <EOL> if hasCapsule : <EOL> if capPath : <EOL> continue <EOL> f = pkg . getFile ( filename ) <EOL> f . flags . isCapsuleAddition ( True ) <EOL> f . flags . isCapsuleOverride ( True ) <EOL> f . flags . isEncapsulatedContent ( False ) <EOL> class RemoveCapsuleFiles ( packagepolicy . _filterSpec ) : <EOL> """<STR_LIT>""" <EOL> requires = ( <EOL> ( '<STR_LIT>' , policy . REQUIRED_PRIOR ) , <EOL> ) <EOL> def do ( self ) : <EOL> """<STR_LIT>""" <EOL> filters = { } <EOL> for name , regex in self . extraFilters : <EOL> name %= self . macros <EOL> filters . setdefault ( name , [ ] ) . append ( <EOL> filter . Filter ( regex , self . macros , name = name ) ) <EOL> components = dict ( ( x . name , x ) for x in <EOL> self . recipe . autopkg . getComponents ( ) ) <EOL> for name , fltrs in filters . iteritems ( ) : <EOL> if name not in components : <EOL> self . error ( "<STR_LIT>" % name ) ; <EOL> continue <EOL> provides = components [ name ] . provides <EOL> files = components [ name ] . keys ( ) <EOL> for fn in files : <EOL> for fltr in fltrs : <EOL> if fltr . match ( fn ) : <EOL> self . recipe . autopkg . delFile ( fn ) <EOL> self . recipe . _capsulePathMap . pop ( fn ) <EOL> self . recipe . _capsuleDataMap . pop ( fn ) <EOL> provides . removeDeps ( deps . FileDependencies , <EOL> [ deps . Dependency ( fn ) ] , missingOkay = True ) <EOL> break </s>
