<s> """<STR_LIT>""" <EOL> import fnmatch <EOL> import os <EOL> import sys <EOL> import xml <EOL> import re <EOL> import tempfile <EOL> import textwrap <EOL> import traceback <EOL> import urllib <EOL> from conary . deps import deps , arch <EOL> from conary . lib import util , api <EOL> from conary . lib . cfg import ParseError , SectionedConfigFile , ConfigSection <EOL> from conary . lib . cfgtypes import ( CfgType , CfgString , CfgBool , CfgPath , CfgEnum , <EOL> CfgList , CfgDict , CfgLineList , CfgPathList , CfgRegExpList , CfgInt , <EOL> CfgBytes ) <EOL> from conary . lib . http import proxy_map <EOL> from conary import errors <EOL> from conary import versions <EOL> from conary import flavorcfg <EOL> from conary . repository import transport <EOL> class ServerGlobList ( object ) : <EOL> multipleMatches = False <EOL> def __init__ ( self , items = ( ) ) : <EOL> self . _exact = { } <EOL> self . _globs = [ ] <EOL> self . _caseMap = { } <EOL> self . extend ( items ) <EOL> def find ( self , server ) : <EOL> server = server . lower ( ) <EOL> l = list ( self . _exact . get ( server , ( ) ) ) <EOL> if l and not self . multipleMatches : <EOL> assert len ( l ) == <NUM_LIT:1> <EOL> return l [ <NUM_LIT:0> ] <EOL> for ( serverGlob , item ) in self . _globs : <EOL> if fnmatch . fnmatchcase ( server , serverGlob ) : <EOL> if not self . multipleMatches : <EOL> return item <EOL> l . append ( item ) <EOL> if not self . multipleMatches : <EOL> return None <EOL> return l <EOL> def append ( self , newItem ) : <EOL> newGlob , newInfo = newItem <EOL> newGlobLower = newGlob . lower ( ) <EOL> self . _caseMap [ newGlobLower ] = newGlob <EOL> newGlob = newGlobLower <EOL> if not any ( x in newGlob for x in '<STR_LIT>' ) : <EOL> if self . multipleMatches and newGlob in self . _exact : <EOL> self . _exact [ newGlob ] . append ( newInfo ) <EOL> else : <EOL> self . _exact [ newGlob ] = [ newInfo ] <EOL> else : <EOL> location = None <EOL> removeOld = False <EOL> for i , ( serverGlob , info ) in enumerate ( self . _globs ) : <EOL> if fnmatch . fnmatch ( newItem [ <NUM_LIT:0> ] , serverGlob ) : <EOL> if not self . multipleMatches and serverGlob == newItem [ <NUM_LIT:0> ] : <EOL> removeOld = True <EOL> location = i <EOL> break <EOL> if location is None : <EOL> self . _globs . append ( newItem ) <EOL> elif removeOld : <EOL> self . _globs [ location ] = newItem <EOL> else : <EOL> self . _globs . insert ( location , newItem ) <EOL> def extend ( self , itemList ) : <EOL> for newItem in reversed ( list ( itemList ) ) : <EOL> self . append ( newItem ) <EOL> def clear ( self ) : <EOL> self . _exact . clear ( ) <EOL> self . _caseMap . clear ( ) <EOL> del self . _globs [ : ] <EOL> def __iter__ ( self ) : <EOL> for serverGlob , infoList in sorted ( self . _exact . iteritems ( ) ) : <EOL> for info in infoList : <EOL> yield self . _caseMap [ serverGlob ] , info <EOL> for serverGlob , info in self . _globs : <EOL> yield self . _caseMap [ serverGlob ] , info <EOL> def __nonzero__ ( self ) : <EOL> return bool ( self . _exact ) or bool ( self . _globs ) <EOL> def __eq__ ( self , other ) : <EOL> return list ( self ) == list ( other ) <EOL> def __ne__ ( self , other ) : <EOL> return list ( self ) != list ( other ) <EOL> class UserInformation ( ServerGlobList ) : <EOL> def __iter__ ( self ) : <EOL> for x in ServerGlobList . __iter__ ( self ) : <EOL> yield ( x [ <NUM_LIT:0> ] , x [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , x [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) <EOL> def addServerGlob ( self , * args ) : <EOL> if len ( args ) == <NUM_LIT:3> : <EOL> args = args [ <NUM_LIT:0> ] , ( args [ <NUM_LIT:1> ] , args [ <NUM_LIT:2> ] ) <EOL> ServerGlobList . append ( self , args ) <EOL> def addServerGlobs ( self , items ) : <EOL> for item in reversed ( list ( items ) ) : <EOL> self . addServerGlob ( * item ) <EOL> def extend ( self , other ) : <EOL> for item in other : <EOL> self . addServerGlob ( * item ) <EOL> def append ( self , item ) : <EOL> self . addServerGlob ( * item ) <EOL> def __init__ ( self , initVal = None ) : <EOL> ServerGlobList . __init__ ( self ) <EOL> if initVal is not None : <EOL> for val in initVal : <EOL> self . addServerGlob ( * val ) <EOL> class CfgUserInfoItem ( CfgType ) : <EOL> def parseString ( self , str ) : <EOL> val = str . split ( ) <EOL> if len ( val ) < <NUM_LIT:2> or len ( val ) > <NUM_LIT:3> : <EOL> raise ParseError ( "<STR_LIT>" ) <EOL> elif len ( val ) == <NUM_LIT:2> : <EOL> return ( val [ <NUM_LIT:0> ] , val [ <NUM_LIT:1> ] , None ) <EOL> else : <EOL> pw = ( val [ <NUM_LIT:2> ] is not None and util . ProtectedString ( val [ <NUM_LIT:2> ] ) ) or None <EOL> return ( val [ <NUM_LIT:0> ] , val [ <NUM_LIT:1> ] , pw ) <EOL> def format ( self , val , displayOptions = None ) : <EOL> serverGlob , user , password = val <EOL> if password is None : <EOL> return '<STR_LIT>' % ( serverGlob , user ) <EOL> elif displayOptions . get ( '<STR_LIT>' ) : <EOL> return '<STR_LIT>' % ( serverGlob , user ) <EOL> else : <EOL> return '<STR_LIT>' % ( serverGlob , user , password ) <EOL> class CfgUserInfo ( CfgList ) : <EOL> def __init__ ( self , default = [ ] ) : <EOL> CfgList . __init__ ( self , CfgUserInfoItem , UserInformation , <EOL> default = default ) <EOL> def set ( self , curVal , newVal ) : <EOL> curVal . extend ( newVal ) <EOL> return curVal <EOL> class EntitlementList ( ServerGlobList ) : <EOL> multipleMatches = True <EOL> def addEntitlement ( self , serverGlob , entitlement , entClass = None ) : <EOL> self . append ( ( serverGlob , ( entClass , util . ProtectedString ( entitlement ) ) ) ) <EOL> class CfgEntitlementItem ( CfgType ) : <EOL> def parseString ( self , str ) : <EOL> val = str . split ( ) <EOL> if len ( val ) == <NUM_LIT:3> : <EOL> import warnings <EOL> warnings . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( str , val [ <NUM_LIT:0> ] , val [ <NUM_LIT:2> ] ) , <EOL> DeprecationWarning ) <EOL> return ( val [ <NUM_LIT:0> ] , ( val [ <NUM_LIT:1> ] , util . ProtectedString ( val [ <NUM_LIT:2> ] ) ) ) <EOL> elif len ( val ) != <NUM_LIT:2> : <EOL> raise ParseError ( "<STR_LIT>" ) <EOL> return ( val [ <NUM_LIT:0> ] , ( None , util . ProtectedString ( val [ <NUM_LIT:1> ] ) ) ) <EOL> def format ( self , val , displayOptions = None ) : <EOL> if val [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] is None : <EOL> return '<STR_LIT>' % ( val [ <NUM_LIT:0> ] , val [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) <EOL> else : <EOL> return '<STR_LIT>' % ( val [ <NUM_LIT:0> ] , val [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , val [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) <EOL> class CfgEntitlement ( CfgList ) : <EOL> def __init__ ( self , default = [ ] ) : <EOL> CfgList . __init__ ( self , CfgEntitlementItem , EntitlementList , <EOL> default = default ) <EOL> def set ( self , curVal , newVal ) : <EOL> curVal . extend ( newVal ) <EOL> return curVal <EOL> class CfgLabel ( CfgType ) : <EOL> def format ( self , val , displayOptions = None ) : <EOL> return val . asString ( ) <EOL> def parseString ( self , val ) : <EOL> try : <EOL> return versions . Label ( val ) <EOL> except versions . ParseError , e : <EOL> raise ParseError , e <EOL> class CfgDependencyClass ( CfgType ) : <EOL> def format ( self , val , displayOptions = None ) : <EOL> return val . tagName <EOL> def parseString ( self , val ) : <EOL> klass = deps . dependencyClassesByName . get ( val , None ) <EOL> if klass is None : <EOL> raise ParseError ( '<STR_LIT>' % val ) <EOL> return klass <EOL> class CfgRepoMapEntry ( CfgType ) : <EOL> def parseString ( self , str ) : <EOL> val = str . split ( ) <EOL> if len ( val ) != <NUM_LIT:2> : <EOL> raise ParseError ( "<STR_LIT>" ) <EOL> match = re . match ( '<STR_LIT>' , val [ <NUM_LIT:1> ] ) <EOL> if match is not None : <EOL> user , server = match . groups ( ) <EOL> raise ParseError , ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> ( server , user ) ) <EOL> return ( val [ <NUM_LIT:0> ] , val [ <NUM_LIT:1> ] ) <EOL> def format ( self , val , displayOptions = None ) : <EOL> return '<STR_LIT>' % ( val [ <NUM_LIT:0> ] , val [ <NUM_LIT:1> ] ) <EOL> class RepoMap ( ServerGlobList ) : <EOL> def __setitem__ ( self , key , val ) : <EOL> self . append ( ( key , val ) ) <EOL> def __getitem__ ( self , key ) : <EOL> return self . find ( key ) <EOL> def has_key ( self , key ) : <EOL> r = self . find ( key ) <EOL> if r is None : <EOL> return False <EOL> return True <EOL> def update ( self , other ) : <EOL> for key , val in other . iteritems ( ) : <EOL> self . append ( ( key , val ) ) <EOL> def iteritems ( self ) : <EOL> return iter ( self ) <EOL> def items ( self ) : <EOL> return self <EOL> def keys ( self ) : <EOL> return [ x [ <NUM_LIT:0> ] for x in self ] <EOL> def iterkeys ( self ) : <EOL> return ( x [ <NUM_LIT:0> ] for x in self ) <EOL> def values ( self ) : <EOL> return [ x [ <NUM_LIT:1> ] for x in self ] <EOL> def itervalues ( self ) : <EOL> return ( x [ <NUM_LIT:1> ] for x in self ) <EOL> def get ( self , key , default ) : <EOL> r = self . find ( key ) <EOL> if r is None : <EOL> return default <EOL> return r <EOL> def __init__ ( self , repoMap = [ ] ) : <EOL> if hasattr ( repoMap , '<STR_LIT>' ) : <EOL> ServerGlobList . __init__ ( self ) <EOL> self . update ( repoMap ) <EOL> else : <EOL> ServerGlobList . __init__ ( self , repoMap ) <EOL> class CfgRepoMap ( CfgList ) : <EOL> def __init__ ( self , default = [ ] ) : <EOL> CfgList . __init__ ( self , CfgRepoMapEntry , RepoMap , default = default ) <EOL> def set ( self , curVal , newVal ) : <EOL> curVal . extend ( newVal ) <EOL> return curVal <EOL> class CfgFlavor ( CfgType ) : <EOL> default = deps . Flavor ( ) <EOL> def copy ( self , val ) : <EOL> return val . copy ( ) <EOL> def parseString ( self , val ) : <EOL> try : <EOL> f = deps . parseFlavor ( val ) <EOL> except Exception , e : <EOL> raise ParseError , e <EOL> if f is None : <EOL> raise ParseError , '<STR_LIT>' % val <EOL> return f <EOL> def format ( self , val , displayOptions = None ) : <EOL> val = '<STR_LIT:U+002CU+0020>' . join ( deps . formatFlavor ( val ) . split ( '<STR_LIT:U+002C>' ) ) <EOL> if displayOptions and displayOptions . get ( '<STR_LIT>' , False ) : <EOL> val = ( '<STR_LIT>' % '<STR_LIT>' ) . join ( textwrap . wrap ( val , <NUM_LIT> ) ) <EOL> return val <EOL> class CfgFingerPrintMapItem ( CfgType ) : <EOL> def parseString ( self , val ) : <EOL> val = val . split ( None , <NUM_LIT:1> ) <EOL> label = val [ <NUM_LIT:0> ] <EOL> try : <EOL> re . compile ( label ) <EOL> except Exception , e : <EOL> raise ParseError , "<STR_LIT>" % label + str ( e ) <EOL> if len ( val ) == <NUM_LIT:1> or not val [ <NUM_LIT:1> ] or val [ <NUM_LIT:1> ] . lower ( ) == '<STR_LIT:none>' : <EOL> fingerprint = None <EOL> else : <EOL> fingerprint = '<STR_LIT>' . join ( val [ <NUM_LIT:1> ] . split ( ) ) <EOL> return label , fingerprint <EOL> def format ( self , val , displayOptions = None ) : <EOL> return '<STR_LIT:U+0020>' . join ( [ val [ <NUM_LIT:0> ] , str ( val [ <NUM_LIT:1> ] ) ] ) <EOL> class CfgFingerPrintMap ( CfgList ) : <EOL> def __init__ ( self , default = { } ) : <EOL> CfgList . __init__ ( self , CfgFingerPrintMapItem , default = default ) <EOL> class CfgFingerPrint ( CfgType ) : <EOL> def parseString ( self , val ) : <EOL> val = val . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) <EOL> if not val or val . lower ( ) == '<STR_LIT:none>' : <EOL> return None <EOL> return val <EOL> class CfgLabelList ( list ) : <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % list . __repr__ ( self ) <EOL> def __getslice__ ( self , i , j ) : <EOL> return CfgLabelList ( list . __getslice__ ( self , i , j ) ) <EOL> def versionPriority ( self , first , second ) : <EOL> return self . priority ( first . trailingLabel ( ) , second . trailingLabel ( ) ) <EOL> def priority ( self , first , second ) : <EOL> firstIdx = None <EOL> secondIdx = None <EOL> for i , l in enumerate ( self ) : <EOL> if firstIdx is None and l == first : <EOL> firstIdx = i <EOL> if secondIdx is None and l == second : <EOL> secondIdx = i <EOL> if firstIdx is None or secondIdx is None : <EOL> return None <EOL> return cmp ( firstIdx , secondIdx ) <EOL> class ProxyEntry ( CfgType ) : <EOL> def parseString ( self , str ) : <EOL> match = re . match ( '<STR_LIT>' , str ) <EOL> if match is None : <EOL> raise ParseError ( '<STR_LIT>' % str ) <EOL> return CfgType . parseString ( self , str ) <EOL> class CfgProxy ( CfgDict ) : <EOL> def updateFromString ( self , val , str ) : <EOL> suppProtocols = [ '<STR_LIT:http>' , '<STR_LIT>' ] <EOL> vlist = str . split ( ) <EOL> if len ( vlist ) > <NUM_LIT:2> : <EOL> raise ParseError ( "<STR_LIT>" <EOL> % str ) <EOL> if not vlist : <EOL> raise ParseError ( "<STR_LIT>" ) <EOL> if len ( vlist ) == <NUM_LIT:2> : <EOL> if vlist [ <NUM_LIT:0> ] not in suppProtocols : <EOL> raise ParseError ( '<STR_LIT>' % vlist [ <NUM_LIT:0> ] ) <EOL> if vlist [ <NUM_LIT:1> ] == "<STR_LIT:None>" : <EOL> if vlist [ <NUM_LIT:0> ] in val : <EOL> del val [ vlist [ <NUM_LIT:0> ] ] <EOL> return val <EOL> return CfgDict . updateFromString ( self , val , str ) <EOL> try : <EOL> protocol , rest = str . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> except ValueError : <EOL> if str == "<STR_LIT:None>" : <EOL> for protocol in suppProtocols : <EOL> if protocol in val : <EOL> del val [ protocol ] <EOL> return val <EOL> raise ParseError ( "<STR_LIT>" % str ) <EOL> if protocol not in suppProtocols : <EOL> raise ParseError ( '<STR_LIT>' % protocol ) <EOL> CfgDict . updateFromString ( self , val , '<STR_LIT>' + rest ) <EOL> CfgDict . updateFromString ( self , val , '<STR_LIT>' + rest ) <EOL> return val <EOL> def __init__ ( self , default = { } ) : <EOL> CfgDict . __init__ ( self , ProxyEntry , default = default ) <EOL> CfgInstallLabelPath = CfgLineList ( CfgLabel , listType = CfgLabelList ) <EOL> CfgDependencyClassList = CfgLineList ( CfgDependencyClass ) <EOL> class CfgSearchPathItem ( CfgType ) : <EOL> def parseString ( self , item ) : <EOL> return item <EOL> CfgSearchPath = CfgLineList ( CfgSearchPathItem ) <EOL> class CfgProxyMap ( CfgType ) : <EOL> default = proxy_map . ProxyMap ( ) <EOL> def updateFromString ( self , val , string ) : <EOL> parts = string . split ( ) <EOL> if parts == [ '<STR_LIT>' ] : <EOL> val . clear ( ) <EOL> return val <EOL> if len ( parts ) < <NUM_LIT:2> : <EOL> raise ParseError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> pattern , targets = parts [ <NUM_LIT:0> ] , parts [ <NUM_LIT:1> : ] <EOL> val . addStrategy ( pattern , targets ) <EOL> return val <EOL> def setFromString ( self , val , string ) : <EOL> pm = val . __class__ ( ) <EOL> return self . updateFromString ( pm , string ) <EOL> def toStrings ( self , value , displayOptions ) : <EOL> for pattern , targets in value . filterList : <EOL> yield '<STR_LIT:U+0020>' . join ( [ str ( pattern ) ] + [ str ( x ) for x in targets ] ) <EOL> class CfgCapsuleSync ( CfgEnum ) : <EOL> validValues = [ '<STR_LIT:false>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def parseString ( self , val ) : <EOL> if val . lower ( ) == '<STR_LIT:true>' : <EOL> val = '<STR_LIT>' <EOL> return CfgEnum . parseString ( self , val ) <EOL> def _getDefaultPublicKeyrings ( ) : <EOL> publicKeyrings = [ ] <EOL> try : <EOL> import pwd <EOL> ent = pwd . getpwuid ( os . getuid ( ) ) <EOL> pwDir = ent [ <NUM_LIT:5> ] <EOL> if os . path . isdir ( pwDir ) : <EOL> publicKeyrings . append ( os . path . join ( pwDir , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> except KeyError : <EOL> pass <EOL> publicKeyrings . append ( '<STR_LIT>' ) <EOL> return publicKeyrings <EOL> def _getDefaultTempDir ( ) : <EOL> if os . name == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return tempfile . gettempdir ( ) <EOL> class ConaryContext ( ConfigSection ) : <EOL> """<STR_LIT>""" <EOL> archDirs = ( CfgPathList , ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> autoLoadRecipes = CfgList ( CfgString ) <EOL> autoResolve = ( CfgBool , False ) <EOL> autoResolvePackages = ( CfgBool , True ) <EOL> buildFlavor = CfgFlavor <EOL> buildLabel = CfgLabel <EOL> buildPath = ( CfgPath , '<STR_LIT>' ) <EOL> cleanAfterCook = ( CfgBool , True ) <EOL> commitRelativeChangeset = ( CfgBool , False ) <EOL> componentDirs = ( CfgPathList , ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> configComponent = ( CfgBool , True ) <EOL> contact = None <EOL> context = None <EOL> dbPath = '<STR_LIT>' <EOL> debugExceptions = ( CfgBool , False ) <EOL> debugRecipeExceptions = ( CfgBool , False ) <EOL> defaultMacros = ( CfgPathList , ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> emergeUser = ( CfgString , '<STR_LIT>' ) <EOL> enableRPMVersionDeps = ( CfgBool , True ) <EOL> enforceManagedPolicy = ( CfgBool , True ) <EOL> entitlement = CfgEntitlement <EOL> entitlementDirectory = ( CfgPath , '<STR_LIT>' ) <EOL> environment = CfgDict ( CfgString ) <EOL> excludeTroves = CfgRegExpList <EOL> flavor = CfgList ( CfgFlavor ) <EOL> flavorPreferences = CfgList ( CfgFlavor ) <EOL> fullVersions = CfgBool <EOL> fullFlavors = CfgBool <EOL> localRollbacks = CfgBool <EOL> keepRequired = CfgBool <EOL> ignoreDependencies = ( CfgDependencyClassList , <EOL> [ deps . AbiDependency , deps . RpmLibDependencies ] ) <EOL> installLabelPath = CfgInstallLabelPath <EOL> interactive = ( CfgBool , False ) <EOL> logFile = ( CfgPathList , ( '<STR_LIT>' , <EOL> '<STR_LIT>' , ) ) <EOL> lookaside = ( CfgPath , '<STR_LIT>' ) <EOL> macros = CfgDict ( CfgString ) <EOL> mirrorDirs = ( CfgPathList , ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) ) <EOL> modelPath = '<STR_LIT>' <EOL> name = None <EOL> quiet = CfgBool <EOL> pinTroves = CfgRegExpList <EOL> policyDirs = ( CfgPathList , ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> shortenGroupFlavors = CfgBool <EOL> syncCapsuleDatabase = ( CfgCapsuleSync , '<STR_LIT>' ) <EOL> conaryProxy = CfgProxy <EOL> proxy = CfgProxy <EOL> proxyMap = CfgProxyMap <EOL> connectAttempts = ( CfgInt , <NUM_LIT:3> , "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> downloadAttempts = ( CfgInt , <NUM_LIT:3> , "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> downloadRetryThreshold = ( CfgBytes ( '<STR_LIT:M>' ) , <NUM_LIT> , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> downloadRetryTrim = ( CfgBytes ( '<STR_LIT:k>' ) , <NUM_LIT> , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> pubRing = ( CfgPathList , _getDefaultPublicKeyrings ( ) ) <EOL> uploadRateLimit = ( CfgBytes ( perSecond = True ) , <NUM_LIT:0> , <EOL> "<STR_LIT>" ) <EOL> downloadRateLimit = ( CfgBytes ( perSecond = True ) , <NUM_LIT:0> , <EOL> "<STR_LIT>" ) <EOL> recipeTemplate = None <EOL> groupTemplate = None <EOL> factoryTemplate = None <EOL> repositoryMap = CfgRepoMap <EOL> resolveLevel = ( CfgInt , <NUM_LIT:2> ) <EOL> root = ( CfgPath , '<STR_LIT:/>' ) <EOL> recipeTemplateDirs = ( CfgPathList , ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> showLabels = CfgBool <EOL> showComponents = CfgBool <EOL> searchPath = CfgSearchPath <EOL> signatureKey = CfgFingerPrint <EOL> signatureKeyMap = CfgFingerPrintMap <EOL> siteConfigPath = ( CfgPathList , ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> sourceSearchDir = ( CfgPath , '<STR_LIT:.>' ) <EOL> threaded = ( CfgBool , True ) <EOL> downloadFirst = ( CfgBool , False ) <EOL> tmpDir = ( CfgPath , _getDefaultTempDir ( ) ) <EOL> trustThreshold = ( CfgInt , <NUM_LIT:0> ) <EOL> trustedCerts = ( CfgPathList , ( ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> trustedKeys = ( CfgList ( CfgString ) , [ ] ) <EOL> updateThreshold = ( CfgInt , <NUM_LIT:15> ) <EOL> useDirs = ( CfgPathList , ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> user = CfgUserInfo <EOL> baseClassDir = ( CfgPath , '<STR_LIT>' ) <EOL> verifyDirsNoNewFiles = ( CfgPathList , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> windowsBuildService = CfgString <EOL> systemIdScript = CfgPath <EOL> def _resetSigMap ( self ) : <EOL> self . resetToDefault ( '<STR_LIT>' ) <EOL> def __init__ ( self , * args , ** kw ) : <EOL> ConfigSection . __init__ ( self , * args , ** kw ) <EOL> self . addListener ( '<STR_LIT>' , lambda * args : self . _resetSigMap ( ) ) <EOL> def _writeKey ( self , out , cfgItem , value , options ) : <EOL> name = cfgItem . name <EOL> if name not in self . _values or self . _values [ name ] . isDefault ( ) : <EOL> return <EOL> ConfigSection . _writeKey ( self , out , cfgItem , value , options ) <EOL> class ConaryConfiguration ( SectionedConfigFile ) : <EOL> _cfg_bases = ( ConaryContext , ) <EOL> _allowNewSections = True <EOL> _defaultSectionType = ConaryContext <EOL> @ api . publicApi <EOL> def __init__ ( self , readConfigFiles = False , ignoreErrors = False , <EOL> readProxyValuesFirst = True ) : <EOL> """<STR_LIT>""" <EOL> SectionedConfigFile . __init__ ( self ) <EOL> self . _ignoreErrors = ignoreErrors <EOL> self . addListener ( '<STR_LIT>' , lambda * args : self . _resetSigMap ( ) ) <EOL> if readConfigFiles : <EOL> if readProxyValuesFirst : <EOL> self . limitToKeys ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . ignoreUrlIncludes ( ) <EOL> self . readFiles ( ) <EOL> self . limitToKeys ( False ) <EOL> self . ignoreUrlIncludes ( False ) <EOL> self . readFiles ( ) <EOL> self . readEntitlementDirectory ( ) <EOL> util . settempdir ( self . tmpDir ) <EOL> def getProxyMap ( self ) : <EOL> return getProxyMap ( self ) <EOL> def _getOpener ( self ) : <EOL> return transport . URLOpener ( proxyMap = self . getProxyMap ( ) , <EOL> connectAttempts = self . connectAttempts ) <EOL> def readEntitlementDirectory ( self ) : <EOL> if not os . path . isdir ( self . entitlementDirectory ) : <EOL> return <EOL> try : <EOL> files = os . listdir ( self . entitlementDirectory ) <EOL> except OSError : <EOL> return <EOL> for basename in files : <EOL> try : <EOL> if os . path . isfile ( os . path . join ( self . entitlementDirectory , <EOL> basename ) ) : <EOL> ent = loadEntitlement ( self . entitlementDirectory , basename ) <EOL> if not ent : <EOL> continue <EOL> self . entitlement . addEntitlement ( ent [ <NUM_LIT:0> ] , ent [ <NUM_LIT:2> ] , <EOL> entClass = ent [ <NUM_LIT:1> ] ) <EOL> except OSError : <EOL> return <EOL> def readFiles ( self ) : <EOL> self . read ( "<STR_LIT>" , exception = False ) <EOL> if os . environ . has_key ( "<STR_LIT>" ) : <EOL> self . read ( os . environ [ "<STR_LIT>" ] + "<STR_LIT:/>" + "<STR_LIT>" , exception = False ) <EOL> self . read ( "<STR_LIT>" , exception = False ) <EOL> def setContext ( self , name ) : <EOL> """<STR_LIT>""" <EOL> if not self . hasSection ( name ) : <EOL> return False <EOL> self . context = name <EOL> context = self . getSection ( name ) <EOL> for key , ctxval in context . _values . iteritems ( ) : <EOL> if ctxval . isDefault ( ) : <EOL> continue <EOL> newval = self . _cow ( key ) <EOL> newval . updateFromContext ( ctxval ) <EOL> return True <EOL> def getContext ( self , name ) : <EOL> if not self . hasSection ( name ) : <EOL> return False <EOL> return self . getSection ( name ) <EOL> def displayContext ( self , out = None ) : <EOL> if out is None : <EOL> out = sys . stdout <EOL> if self . context : <EOL> out . write ( '<STR_LIT>' % self . context ) <EOL> context = self . getContext ( self . context ) <EOL> context . setDisplayOptions ( ** self . _displayOptions ) <EOL> context . display ( out ) <EOL> else : <EOL> out . write ( '<STR_LIT>' ) <EOL> def _writeSection ( self , name , options ) : <EOL> return self . getDisplayOption ( '<STR_LIT>' , False ) <EOL> def requireInstallLabelPath ( self ) : <EOL> if not self . installLabelPath : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def _resetSigMap ( self ) : <EOL> self . resetToDefault ( '<STR_LIT>' ) <EOL> def initializeFlavors ( self ) : <EOL> """<STR_LIT>""" <EOL> self . flavorConfig = flavorcfg . FlavorConfig ( self . useDirs , <EOL> self . archDirs ) <EOL> if self . flavor == [ ] : <EOL> self . flavor = [ deps . Flavor ( ) ] <EOL> self . flavor = self . flavorConfig . toDependency ( override = self . flavor ) <EOL> newFlavors = [ ] <EOL> hasIns = False <EOL> for flavor in self . flavor : <EOL> if deps . DEP_CLASS_IS in flavor . getDepClasses ( ) : <EOL> hasIns = True <EOL> break <EOL> if not hasIns : <EOL> for depList in arch . currentArch : <EOL> for flavor in self . flavor : <EOL> insSet = deps . Flavor ( ) <EOL> for dep in depList : <EOL> insSet . addDep ( deps . InstructionSetDependency , dep ) <EOL> newFlavor = flavor . copy ( ) <EOL> newFlavor . union ( insSet ) <EOL> newFlavors . append ( newFlavor ) <EOL> self . flavor = newFlavors <EOL> self . buildFlavor = deps . overrideFlavor ( self . flavor [ <NUM_LIT:0> ] , <EOL> self . buildFlavor ) <EOL> if self . isDefault ( '<STR_LIT>' ) : <EOL> self . flavorPreferences = arch . getFlavorPreferencesFromFlavor ( <EOL> self . flavor [ <NUM_LIT:0> ] ) <EOL> self . flavorConfig . populateBuildFlags ( ) <EOL> def selectSignatureKey ( cfg , label ) : <EOL> if not cfg . signatureKeyMap : <EOL> return cfg . signatureKey <EOL> label = str ( label ) <EOL> if "<STR_LIT>" in label : <EOL> label = str ( cfg . buildLabel ) <EOL> for sigLabel , fingerprint in cfg . signatureKeyMap : <EOL> if re . match ( sigLabel , label ) : <EOL> return fingerprint <EOL> return cfg . signatureKey <EOL> def emitEntitlement ( serverName , className = None , key = None , timeout = None , <EOL> retryOnTimeout = None ) : <EOL> if className is None : <EOL> classInfo = "<STR_LIT>" <EOL> else : <EOL> classInfo = "<STR_LIT>" % className <EOL> s = """<STR_LIT>""" % ( serverName , classInfo , key ) <EOL> if timeout is not None or retryOnTimeout is not None : <EOL> s += "<STR_LIT>" <EOL> if timeout is not None : <EOL> s += '<STR_LIT>' % timeout <EOL> if retryOnTimeout : <EOL> s += '<STR_LIT>' <EOL> elif retryOnTimeout is not None : <EOL> s += '<STR_LIT>' <EOL> s += '<STR_LIT>' <EOL> s += "<STR_LIT>" <EOL> return s <EOL> def loadEntitlementFromString ( xmlContent , * args , ** kw ) : <EOL> source = kw . get ( '<STR_LIT:source>' , '<STR_LIT>' ) <EOL> serverName = kw . get ( '<STR_LIT>' , None ) <EOL> if len ( args ) : <EOL> if len ( args ) == <NUM_LIT:1> : <EOL> source = args [ <NUM_LIT:0> ] <EOL> elif len ( args ) == <NUM_LIT:2> : <EOL> serverName = args [ <NUM_LIT:0> ] <EOL> source = args [ <NUM_LIT:1> ] <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' % len ( args ) ) <EOL> if serverName : <EOL> import warnings <EOL> warnings . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" , DeprecationWarning ) <EOL> returnTimeout = kw . pop ( '<STR_LIT>' , False ) <EOL> p = EntitlementParser ( ) <EOL> try : <EOL> if '<STR_LIT>' not in xmlContent : <EOL> p . parse ( "<STR_LIT>" + xmlContent + "<STR_LIT>" ) <EOL> else : <EOL> p . parse ( xmlContent ) <EOL> try : <EOL> entClass = p . get ( '<STR_LIT:class>' , None ) <EOL> entKey = p [ '<STR_LIT:key>' ] <EOL> except KeyError : <EOL> raise errors . ConaryError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> except Exception , err : <EOL> raise errors . ConaryError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( source , err ) ) <EOL> if returnTimeout : <EOL> return ( p [ '<STR_LIT>' ] , entClass , entKey , p [ '<STR_LIT>' ] , p [ '<STR_LIT>' ] ) <EOL> return ( p [ '<STR_LIT>' ] , entClass , entKey ) <EOL> def loadEntitlementFromProgram ( fullPath , serverName ) : <EOL> """<STR_LIT>""" <EOL> readFd , writeFd = os . pipe ( ) <EOL> stdErrRead , stdErrWrite = os . pipe ( ) <EOL> childPid = os . fork ( ) <EOL> if not childPid : <EOL> nullFd = os . open ( "<STR_LIT>" , os . O_RDONLY ) <EOL> try : <EOL> try : <EOL> os . close ( readFd ) <EOL> os . dup2 ( nullFd , <NUM_LIT:0> ) <EOL> os . close ( nullFd ) <EOL> os . dup2 ( writeFd , <NUM_LIT:1> ) <EOL> os . dup2 ( stdErrWrite , <NUM_LIT:2> ) <EOL> os . close ( writeFd ) <EOL> os . close ( stdErrWrite ) <EOL> util . massCloseFileDescriptors ( <NUM_LIT:3> , <NUM_LIT> ) <EOL> os . execl ( fullPath , fullPath , serverName ) <EOL> except Exception : <EOL> traceback . print_exc ( sys . stderr ) <EOL> finally : <EOL> os . _exit ( <NUM_LIT:1> ) <EOL> os . close ( writeFd ) <EOL> os . close ( stdErrWrite ) <EOL> output = [ ] <EOL> errorOutput = [ ] <EOL> buf = os . read ( readFd , <NUM_LIT> ) <EOL> errBuf = os . read ( stdErrRead , <NUM_LIT> ) <EOL> while buf or errBuf : <EOL> if buf : <EOL> output . append ( buf ) <EOL> buf = os . read ( readFd , <NUM_LIT> ) <EOL> if errBuf : <EOL> errorOutput . append ( errBuf ) <EOL> errBuf = os . read ( stdErrRead , <NUM_LIT> ) <EOL> pid , status = os . waitpid ( childPid , <NUM_LIT:0> ) <EOL> os . close ( readFd ) <EOL> os . close ( stdErrRead ) <EOL> errMsg = '<STR_LIT>' <EOL> if os . WIFEXITED ( status ) and os . WEXITSTATUS ( status ) : <EOL> errMsg = ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( fullPath , <EOL> os . WEXITSTATUS ( status ) ) ) <EOL> elif os . WIFSIGNALED ( status ) : <EOL> errMsg = ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( fullPath , os . WTERMSIG ( status ) ) ) <EOL> else : <EOL> errMsg = '<STR_LIT>' <EOL> if errMsg : <EOL> if errorOutput : <EOL> errMsg += '<STR_LIT>' % '<STR_LIT>' . join ( errorOutput ) <EOL> else : <EOL> errMsg += '<STR_LIT>' <EOL> raise errors . ConaryError ( errMsg ) <EOL> xmlContent = '<STR_LIT>' . join ( output ) <EOL> return loadEntitlementFromString ( xmlContent , fullPath ) <EOL> def loadEntitlement ( dirName , serverName ) : <EOL> if not dirName : <EOL> return None <EOL> fullPath = os . path . join ( dirName , serverName ) <EOL> if not os . access ( fullPath , os . R_OK ) : <EOL> return None <EOL> if os . access ( fullPath , os . X_OK ) : <EOL> return loadEntitlementFromProgram ( fullPath , <EOL> '<STR_LIT>' % fullPath ) <EOL> elif os . access ( fullPath , os . R_OK ) : <EOL> return loadEntitlementFromString ( open ( fullPath ) . read ( ) , fullPath ) <EOL> else : <EOL> return None <EOL> class EntitlementParser ( dict ) : <EOL> def StartElementHandler ( self , name , attrs ) : <EOL> if name not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:class>' , '<STR_LIT:key>' , '<STR_LIT>' ] : <EOL> raise SyntaxError <EOL> self . state . append ( ( str ( name ) , attrs ) ) <EOL> self . data = None <EOL> def EndElementHandler ( self , name ) : <EOL> state , attrs = self . state . pop ( ) <EOL> if state == '<STR_LIT>' : <EOL> self [ '<STR_LIT>' ] = ( str ( attrs [ '<STR_LIT>' ] ) == '<STR_LIT:True>' ) <EOL> if '<STR_LIT>' in attrs : <EOL> self [ '<STR_LIT>' ] = int ( attrs [ '<STR_LIT>' ] ) <EOL> else : <EOL> self [ state ] = str ( self . data ) <EOL> def CharacterDataHandler ( self , data ) : <EOL> self . data = data <EOL> def parse ( self , s ) : <EOL> self . state = [ ] <EOL> return self . p . Parse ( s ) <EOL> def __init__ ( self ) : <EOL> self . p = xml . parsers . expat . ParserCreate ( ) <EOL> self . p . StartElementHandler = self . StartElementHandler <EOL> self . p . EndElementHandler = self . EndElementHandler <EOL> self . p . CharacterDataHandler = self . CharacterDataHandler <EOL> dict . __init__ ( self ) <EOL> self [ '<STR_LIT>' ] = True <EOL> self [ '<STR_LIT>' ] = None <EOL> def getProxyFromConfig ( cfg ) : <EOL> """<STR_LIT>""" <EOL> proxy = { } <EOL> for k , v in cfg . conaryProxy . iteritems ( ) : <EOL> v = '<STR_LIT>' + v [ <NUM_LIT:4> : ] <EOL> proxy [ k ] = v <EOL> if proxy : <EOL> return proxy <EOL> return cfg . proxy <EOL> def getProxyMap ( cfg ) : <EOL> """<STR_LIT>""" <EOL> if cfg . proxyMap : <EOL> return cfg . proxyMap <EOL> proxyDict = urllib . getproxies ( ) <EOL> proxyDict . update ( cfg . proxy ) <EOL> if hasattr ( cfg , '<STR_LIT>' ) : <EOL> for scheme , url in cfg . conaryProxy . items ( ) : <EOL> if url . startswith ( '<STR_LIT>' ) : <EOL> url = '<STR_LIT>' + url [ <NUM_LIT:5> : ] <EOL> elif url . startswith ( '<STR_LIT>' ) : <EOL> url = '<STR_LIT>' + url [ <NUM_LIT:6> : ] <EOL> proxyDict [ scheme ] = url <EOL> return proxy_map . ProxyMap . fromDict ( proxyDict ) <EOL> from conary . lib . cfgtypes import ( CfgType , CfgString , CfgPath , CfgInt , CfgBool , <EOL> CfgRegExp , CfgSignedRegExp , CfgEnum , CfgCallBack , CfgLineList , <EOL> CfgQuotedLineList , CfgList , CfgDict , CfgEnumDict , CfgRegExpList , <EOL> CfgSignedRegExpList , CfgError , CfgEnvironmentError , <EOL> RegularExpressionList , SignedRegularExpressionList , CfgPathList ) <EOL> from conary . lib . cfg import ConfigFile , ConfigSection , SectionedConfigFile </s>
