<s> import atexit <EOL> import BaseHTTPServer <EOL> import copy <EOL> import errno <EOL> import inspect <EOL> import itertools <EOL> import new <EOL> import os <EOL> import re <EOL> import shutil <EOL> import shlex <EOL> import signal <EOL> import socket <EOL> import stat <EOL> import StringIO <EOL> import subprocess <EOL> import sys <EOL> import time <EOL> import traceback <EOL> import testsuite <EOL> from M2Crypto import SSL <EOL> from conary . cmds import branch <EOL> from conary import callbacks <EOL> from conary import checkin <EOL> from conary . cmds import clone <EOL> from conary import conarycfg <EOL> from conary import conaryclient <EOL> from conary . cmds import cscmd <EOL> from conary import errors <EOL> from conary import files <EOL> from conary import rpmhelper <EOL> from conary import trove <EOL> from conary import versions <EOL> from conary . build import cook , loadrecipe , use <EOL> from conary . cmds import conarycmd <EOL> from conary . cmds import cvccmd <EOL> from conary . cmds import rollbacks <EOL> from conary . cmds import updatecmd <EOL> from conary . cmds import verify <EOL> from conary . conaryclient import cmdline , filetypes <EOL> from conary . deps import arch , deps <EOL> from conary . lib import cfg as cfgmod <EOL> from conary . lib import cfgtypes , log <EOL> from conary . lib import httputils <EOL> from conary . lib import openpgpkey <EOL> from conary . lib import sha1helper <EOL> from conary . lib import util <EOL> from conary . local import database <EOL> from conary . repository import changeset , filecontents , trovesource <EOL> from conary . repository import searchsource <EOL> from conary . server . server import SecureHTTPServer <EOL> from testrunner import testhelp <EOL> from testrunner . testcase import safe_repr <EOL> from testutils import base_server , os_utils , sock_utils <EOL> from testutils import sqlharness <EOL> from conary_test import recipes <EOL> from conary_test import resources <EOL> from conary_test . lib . repserver import RepositoryServer , ProxyServer <EOL> tryConnect = sock_utils . tryConnect <EOL> class _NoneArg : <EOL> pass <EOL> NoneArg = _NoneArg ( ) <EOL> _File = filetypes . _File <EOL> def _isIndividual ( ) : <EOL> return False <EOL> class Symlink ( filetypes . Symlink ) : <EOL> pass <EOL> class RegularFile ( filetypes . RegularFile ) : <EOL> pass <EOL> class BlockDevice ( filetypes . BlockDevice ) : <EOL> pass <EOL> class CharacterDevice ( filetypes . CharacterDevice ) : <EOL> pass <EOL> class Directory ( filetypes . Directory ) : <EOL> pass <EOL> _fileClasses = [ Symlink , RegularFile , BlockDevice , CharacterDevice , Directory ] <EOL> if hasattr ( filetypes , '<STR_LIT>' ) : <EOL> class NamedPipe ( filetypes . NamedPipe ) : <EOL> pass <EOL> _fileClasses . append ( NamedPipe ) <EOL> if hasattr ( filetypes , '<STR_LIT>' ) : <EOL> class Socket ( filetypes . Socket ) : <EOL> pass <EOL> _fileClasses . append ( Socket ) <EOL> for klass in _fileClasses : <EOL> klass . kwargs [ '<STR_LIT:version>' ] = None <EOL> klass . kwargs [ '<STR_LIT>' ] = None <EOL> klass . kwargs [ '<STR_LIT>' ] = None <EOL> class TroveScript : <EOL> def __init__ ( self , script = None , conversions = None ) : <EOL> self . script = script <EOL> self . conversions = conversions <EOL> class RollbackScript ( TroveScript ) : <EOL> pass <EOL> class LoaderFromString ( loadrecipe . RecipeLoaderFromString ) : <EOL> @ staticmethod <EOL> def _validateName ( recipeClass , name ) : <EOL> return recipeClass . __name__ == name <EOL> def x86flags ( archTag , * args ) : <EOL> if archTag == '<STR_LIT>' : <EOL> flags = [ ] <EOL> for f in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> flags . append ( ( f , deps . FLAG_SENSE_PREFERRED ) ) <EOL> return deps . Dependency ( archTag , flags ) <EOL> return deps . Dependency ( archTag ) <EOL> arch . x86flags = x86flags <EOL> arch . initializeArch ( ) <EOL> class IdGen0 ( cook . _IdGen ) : <EOL> formatStr = "<STR_LIT:%s>" <EOL> def __call__ ( self , path , version , flavor ) : <EOL> if self . map . has_key ( path ) : <EOL> return self . map [ path ] <EOL> fileid = sha1helper . md5String ( self . formatStr % path ) <EOL> self . map [ ( path , flavor ) ] = ( fileid , None , None ) <EOL> return ( fileid , None , None ) <EOL> class IdGen1 ( IdGen0 ) : <EOL> formatStr = "<STR_LIT>" <EOL> class IdGen3 ( IdGen0 ) : <EOL> formatStr = "<STR_LIT>" <EOL> class ServerCache ( object ) : <EOL> serverClass = RepositoryServer <EOL> serverType = '<STR_LIT>' <EOL> def __init__ ( self ) : <EOL> self . _topDir = None <EOL> self . servers = { } <EOL> atexit . register ( self . cleanup ) <EOL> @ property <EOL> def topDir ( self ) : <EOL> if not self . _topDir : <EOL> self . _topDir = testhelp . getTempDir ( '<STR_LIT>' ) <EOL> return self . _topDir <EOL> def stopServer ( self , key ) : <EOL> if key in self . servers : <EOL> server = self . servers . pop ( key ) <EOL> server . stop ( ) <EOL> def getCachedServer ( self , key = <NUM_LIT:0> ) : <EOL> return self . servers . get ( key ) <EOL> getServer = getCachedServer <EOL> def startServer ( self , <EOL> SQLserver , <EOL> key = <NUM_LIT:0> , <EOL> serverName = None , <EOL> singleWorker = False , <EOL> resetDir = True , <EOL> ** kwargs ) : <EOL> if key in self . servers : <EOL> server = self . servers [ key ] <EOL> server . resetIfNeeded ( ) <EOL> return server <EOL> if not serverName : <EOL> serverName = '<STR_LIT:localhost>' <EOL> if key != <NUM_LIT:0> : <EOL> serverName += '<STR_LIT:%s>' % key <EOL> reposDir = os . path . join ( self . topDir , '<STR_LIT>' % key ) <EOL> reposDB = SQLserver . getDB ( "<STR_LIT>" % key , keepExisting = True ) <EOL> if resetDir : <EOL> reposDB . reset ( ) <EOL> server = self . serverClass ( reposDir , <EOL> nameList = serverName , <EOL> reposDB = reposDB , <EOL> singleWorker = singleWorker , <EOL> ** kwargs ) <EOL> server . start ( ) <EOL> self . servers [ key ] = server <EOL> return server <EOL> def resetAllServers ( self ) : <EOL> for server in self . servers . values ( ) : <EOL> server . reset ( ) <EOL> def resetAllServersIfNeeded ( self ) : <EOL> for server in self . servers . values ( ) : <EOL> server . resetIfNeeded ( ) <EOL> def stopAllServers ( self ) : <EOL> for server in self . servers . values ( ) : <EOL> server . stop ( ) <EOL> server . reset ( ) <EOL> self . servers = { } <EOL> def cleanup ( self ) : <EOL> self . stopAllServers ( ) <EOL> if self . _topDir : <EOL> util . rmtree ( self . _topDir , ignore_errors = True ) <EOL> self . _topDir = None <EOL> def getMap ( self ) : <EOL> servers = { } <EOL> for server in self . servers . values ( ) : <EOL> servers . update ( server . getMap ( ) ) <EOL> return servers <EOL> def getServerNames ( self ) : <EOL> names = set ( ) <EOL> for server in self . servers . values ( ) : <EOL> names . update ( server . nameList ) <EOL> return names <EOL> _servers = ServerCache ( ) <EOL> _proxy = None <EOL> _httpProxy = None <EOL> class RepositoryHelper ( testhelp . TestCase ) : <EOL> topDir = None <EOL> defLabel = versions . Label ( "<STR_LIT>" ) <EOL> def __init__ ( self , * args , ** kw ) : <EOL> testhelp . TestCase . __init__ ( self , * args , ** kw ) <EOL> global _servers , _proxy <EOL> self . servers = _servers <EOL> self . proxy = _proxy <EOL> def setUp ( self ) : <EOL> if '<STR_LIT>' in os . environ : <EOL> className = "<STR_LIT>" % os . environ [ '<STR_LIT>' ] <EOL> cook . _IdGen = sys . modules [ __name__ ] . __dict__ [ className ] <EOL> self . tmpDir = testhelp . getTempDir ( '<STR_LIT>' ) <EOL> self . workDir = self . tmpDir + "<STR_LIT>" <EOL> self . buildDir = self . tmpDir + "<STR_LIT>" <EOL> self . rootDir = self . tmpDir + "<STR_LIT>" <EOL> self . cacheDir = self . tmpDir + "<STR_LIT>" <EOL> self . configDir = self . tmpDir + "<STR_LIT>" <EOL> self . cfg = conarycfg . ConaryConfiguration ( False ) <EOL> self . cfg . name = '<STR_LIT>' <EOL> self . cfg . contact = '<STR_LIT>' <EOL> self . cfg . installLabelPath = conarycfg . CfgLabelList ( [ self . defLabel ] ) <EOL> self . cfg . installLabel = self . defLabel <EOL> self . cfg . buildLabel = self . defLabel <EOL> self . cfg . buildPath = self . buildDir <EOL> self . cfg . dbPath = '<STR_LIT>' <EOL> self . cfg . debugRecipeExceptions = False <EOL> self . cfg . repositoryMap . clear ( ) <EOL> self . cfg . useDir = None <EOL> self . cfg . quiet = True <EOL> self . cfg . resolveLevel = <NUM_LIT:1> <EOL> self . cfg . user . addServerGlob ( '<STR_LIT:*>' , '<STR_LIT:test>' , '<STR_LIT:foo>' ) <EOL> self . cfg . connectAttempts = <NUM_LIT:1> <EOL> global _proxy <EOL> self . proxy = _proxy <EOL> conaryDir = resources . get_path ( ) <EOL> if conaryDir . startswith ( '<STR_LIT>' ) or '<STR_LIT>' in conaryDir : <EOL> if '<STR_LIT>' in conaryDir : <EOL> offset = conaryDir . index ( '<STR_LIT>' ) + len ( '<STR_LIT>' ) <EOL> else : <EOL> offset = <NUM_LIT:0> <EOL> siteDir = conaryDir [ : offset ] + '<STR_LIT>' <EOL> componentDir = conaryDir [ : offset ] + '<STR_LIT>' <EOL> else : <EOL> siteDir = conaryDir + '<STR_LIT>' <EOL> componentDir = conaryDir + '<STR_LIT>' <EOL> self . cfg . siteConfigPath = [ cfgtypes . Path ( siteDir ) ] <EOL> self . cfg . componentDirs = [ cfgtypes . Path ( componentDir ) ] <EOL> self . cfg . configComponent = False <EOL> self . cfg . root = self . rootDir <EOL> self . cfg . lookaside = self . cacheDir <EOL> os . umask ( <NUM_LIT> <NUM_LIT> ) <EOL> self . initializeFlavor ( ) <EOL> self . _origDir = os . getcwd ( ) <EOL> testhelp . TestCase . setUp ( self ) <EOL> self . cfg . buildLabel = self . defLabel <EOL> self . cfg . installLabelPath = conarycfg . CfgLabelList ( [ self . defLabel ] ) <EOL> self . cfg . defaultMacros = [ <EOL> resources . get_archive ( '<STR_LIT>' ) , <EOL> resources . get_archive ( '<STR_LIT>' , '<STR_LIT:*>' ) , <EOL> resources . get_archive ( '<STR_LIT>' ) , <EOL> ] <EOL> self . cfg . siteConfigPath = [ resources . get_archive ( '<STR_LIT>' ) ] <EOL> self . logFilter . clear ( ) <EOL> self . cfg . sourceSearchDir = self . sourceSearchDir = resources . get_archive ( ) <EOL> self . cfg . enforceManagedPolicy = False <EOL> self . cfg . resolveLevel = <NUM_LIT:2> <EOL> self . cfg . updateThreshold = <NUM_LIT:10> <EOL> policyPath = os . environ . get ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) . split ( '<STR_LIT::>' ) <EOL> self . cfg . policyDirs = policyPath <EOL> self . cfg . baseClassDir = self . tmpDir + "<STR_LIT>" <EOL> keyCache = openpgpkey . OpenPGPKeyFileCache ( ) <EOL> openpgpkey . setKeyCache ( keyCache ) <EOL> keyCache . setPrivatePath ( resources . get_archive ( '<STR_LIT>' ) ) <EOL> self . prepopulateKeyCache ( keyCache ) <EOL> pubRing = util . joinPaths ( self . configDir , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . cfg . pubRing = [ pubRing , resources . get_archive ( '<STR_LIT>' ) ] <EOL> keyCache . setPublicPath ( self . cfg . pubRing ) <EOL> keyCache . getPublicKey ( '<STR_LIT>' ) <EOL> self . origTroveVersion = ( trove . TROVE_VERSION , trove . TROVE_VERSION_1_1 ) <EOL> if not os . path . exists ( self . tmpDir ) : <EOL> os . mkdir ( self . tmpDir ) <EOL> os . mkdir ( self . workDir ) <EOL> os . mkdir ( self . rootDir ) <EOL> os . mkdir ( self . cacheDir ) <EOL> os . mkdir ( self . configDir ) <EOL> self . origEnv = dict ( os . environ ) <EOL> loadrecipe . _defaultsLoaded = True <EOL> httputils . IPCache . clear ( ) <EOL> def prepopulateKeyCache ( self , keyCache ) : <EOL> fingerprint = '<STR_LIT>' <EOL> keyCache . getPrivateKey ( fingerprint , '<STR_LIT>' ) <EOL> keyCache . getPrivateKey ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> log . setVerbosity ( log . WARNING ) <EOL> self . resetFlavors ( ) <EOL> os . chdir ( self . _origDir ) <EOL> testhelp . TestCase . tearDown ( self ) <EOL> self . reset ( ) <EOL> shutil . rmtree ( self . tmpDir ) <EOL> trove . TROVE_VERSION = self . origTroveVersion [ <NUM_LIT:0> ] <EOL> trove . TROVE_VERSION_1_1 = self . origTroveVersion [ <NUM_LIT:1> ] <EOL> self . logFilter . clear ( ) <EOL> for key in os . environ . keys ( ) : <EOL> del os . environ [ key ] <EOL> for key , value in self . origEnv . iteritems ( ) : <EOL> os . environ [ key ] = value <EOL> self . cfg = None <EOL> def getRepositoryClient ( self , user = '<STR_LIT:test>' , password = '<STR_LIT:foo>' , <EOL> serverIdx = None , repositoryMap = None ) : <EOL> cfg = copy . copy ( self . cfg ) <EOL> self . cfg . entitlementDirectory = '<STR_LIT>' <EOL> cfg . user = conarycfg . UserInformation ( ) <EOL> if repositoryMap is None : <EOL> cfg . repositoryMap = conarycfg . RepoMap ( ) <EOL> if serverIdx is None : <EOL> for name in self . servers . getServerNames ( ) : <EOL> cfg . user . addServerGlob ( name , user , password ) <EOL> cfg . repositoryMap . update ( self . servers . getMap ( ) ) <EOL> else : <EOL> server = self . servers . getCachedServer ( serverIdx ) <EOL> if server is not None : <EOL> for name in server . nameList : <EOL> cfg . user . addServerGlob ( name , user , password ) <EOL> cfg . repositoryMap . update ( server . getMap ( ) ) <EOL> else : <EOL> cfg . repositoryMap = repositoryMap <EOL> client = conaryclient . ConaryClient ( cfg ) <EOL> return client . getRepos ( ) <EOL> def addUserAndRole ( self , repos , reposLabel , user , pw ) : <EOL> repos . addRole ( reposLabel , user ) <EOL> repos . addUser ( reposLabel , user , pw ) <EOL> repos . updateRoleMembers ( reposLabel , user , [ user ] ) <EOL> def setupUser ( self , repos , reposLabel , user , pw , troves , label ) : <EOL> self . addUserAndRole ( repos , reposLabel , user , pw ) <EOL> repos . addAcl ( reposLabel , user , troves , label ) <EOL> repos . setRoleCanMirror ( reposLabel , user , True ) <EOL> return self . getRepositoryClient ( user = user , password = pw ) <EOL> def printRepMap ( self ) : <EOL> rmap = self . servers . getMap ( ) <EOL> for name , url in rmap . items ( ) : <EOL> print '<STR_LIT>' % ( name , url ) <EOL> def openDatabase ( self , root = None ) : <EOL> if root is None : <EOL> root = self . rootDir <EOL> return database . Database ( root , self . cfg . dbPath ) <EOL> def getConaryClient ( self ) : <EOL> return conaryclient . ConaryClient ( self . cfg ) <EOL> def openRepository ( self , <EOL> serverIdx = <NUM_LIT:0> , <EOL> resetDir = True , <EOL> configValues = { } , <EOL> proxies = None , <EOL> serverCache = None , <EOL> serverName = None , <EOL> singleWorker = False , <EOL> sslCert = None , <EOL> sslKey = None , <EOL> useSSL = False , <EOL> authCheck = None , <EOL> authTimeout = None , <EOL> commitAction = None , <EOL> deadlockRetry = None , <EOL> entCheck = None , <EOL> excludeCapsuleContents = None , <EOL> forceSSL = None , <EOL> readOnlyRepository = None , <EOL> requireSigs = None , <EOL> ) : <EOL> defaultValues = dict ( <EOL> authCacheTimeout = authTimeout , <EOL> commitAction = commitAction , <EOL> deadlockRetry = deadlockRetry , <EOL> entitlementCheckURL = entCheck , <EOL> externalPasswordURL = authCheck , <EOL> forceSSL = forceSSL , <EOL> readOnlyRepository = readOnlyRepository , <EOL> requireSigs = requireSigs , <EOL> ) <EOL> configValues = dict ( configValues ) <EOL> for key , value in defaultValues . items ( ) : <EOL> if value is None : <EOL> continue <EOL> if key in configValues : <EOL> continue <EOL> configValues [ key ] = value <EOL> configValues . update ( self . _reformatProxies ( proxies ) ) <EOL> if useSSL : <EOL> if sslCert : <EOL> sslCertAndKey = ( sslCert , sslKey ) <EOL> else : <EOL> sslCertAndKey = True <EOL> else : <EOL> sslCertAndKey = None <EOL> for count in range ( <NUM_LIT:4> ) : <EOL> try : <EOL> return self . __openRepository ( <EOL> serverIdx = serverIdx , <EOL> resetDir = resetDir , <EOL> configValues = configValues , <EOL> serverCache = serverCache , <EOL> serverName = serverName , <EOL> singleWorker = singleWorker , <EOL> sslCertAndKey = sslCertAndKey , <EOL> ) <EOL> except : <EOL> if count == <NUM_LIT:3> : <EOL> raise <EOL> time . sleep ( <NUM_LIT:0.5> * ( count + <NUM_LIT:1> ) ) <EOL> raise <EOL> @ staticmethod <EOL> def _reformatProxies ( proxies ) : <EOL> if not proxies : <EOL> return { } <EOL> values = { } <EOL> for key , value in proxies . items ( ) : <EOL> if value . startswith ( '<STR_LIT>' ) : <EOL> values . setdefault ( '<STR_LIT>' , [ ] ) . append ( <EOL> '<STR_LIT>' % ( key , value [ <NUM_LIT:6> : ] ) ) <EOL> else : <EOL> values . setdefault ( '<STR_LIT>' , [ ] ) . append ( <EOL> '<STR_LIT>' % ( key , value ) ) <EOL> return values <EOL> def __openRepository ( self , serverIdx , resetDir , configValues , serverCache , <EOL> serverName , sslCertAndKey , singleWorker ) : <EOL> if serverCache is None : <EOL> serverCache = self . servers <EOL> server = serverCache . getCachedServer ( serverIdx ) <EOL> SQLserver = sqlharness . start ( ) <EOL> if server is None : <EOL> newServer = True <EOL> server = serverCache . startServer ( <EOL> SQLserver = SQLserver , <EOL> key = serverIdx , <EOL> serverName = serverName , <EOL> singleWorker = singleWorker , <EOL> resetDir = resetDir , <EOL> sslCertAndKey = sslCertAndKey , <EOL> withCache = True , <EOL> configValues = configValues , <EOL> ) <EOL> if getattr ( server , '<STR_LIT>' , None ) : <EOL> self . _expectedFdLeak ( server . socket . fileno ( ) ) <EOL> else : <EOL> newServer = False <EOL> server . setNeedsReset ( ) <EOL> self . cfg . repositoryMap . update ( serverCache . getMap ( ) ) <EOL> client = conaryclient . ConaryClient ( self . cfg ) <EOL> repos = client . getRepos ( ) <EOL> label = versions . Label ( "<STR_LIT>" % server . getName ( ) ) <EOL> if server . needsPGPKey and not server . configValues . get ( '<STR_LIT>' ) : <EOL> ascKey = open ( resources . get_archive ( '<STR_LIT>' ) , '<STR_LIT:r>' ) . read ( ) <EOL> repos . addNewAsciiPGPKey ( label , '<STR_LIT:test>' , ascKey ) <EOL> server . clearNeedsPGPKey ( ) <EOL> return repos <EOL> def addfile ( self , * fileList , ** kwArgs ) : <EOL> cvccmd . sourceCommand ( self . cfg , ( "<STR_LIT>" , ) + fileList , kwArgs ) <EOL> def revertSource ( self , * fileList , ** kwArgs ) : <EOL> cvccmd . sourceCommand ( self . cfg , ( "<STR_LIT>" , ) + fileList , kwArgs ) <EOL> def setSourceFlag ( self , path , text = None , binary = None ) : <EOL> if text : <EOL> argSet = { '<STR_LIT:text>' : True } <EOL> elif binary : <EOL> argSet = { '<STR_LIT>' : True } <EOL> else : <EOL> argSet = { } <EOL> cvccmd . sourceCommand ( self . cfg , [ "<STR_LIT>" , path ] , argSet ) <EOL> def describe ( self , file ) : <EOL> cvccmd . sourceCommand ( self . cfg , [ '<STR_LIT>' , file ] , { } ) <EOL> def markRemovedCmd ( self , trvSpec ) : <EOL> oldStdin = sys . stdin <EOL> sys . stdin = StringIO . StringIO ( "<STR_LIT>" ) <EOL> try : <EOL> self . discardOutput ( cvccmd . sourceCommand , self . cfg , <EOL> [ '<STR_LIT>' , trvSpec ] , { } ) <EOL> finally : <EOL> sys . stdin = oldStdin <EOL> def markRemoved ( self , trvSpec , repos = None ) : <EOL> oldStdin = sys . stdin <EOL> sys . stdin = StringIO . StringIO ( "<STR_LIT>" ) <EOL> if not repos : <EOL> repos = self . openRepository ( ) <EOL> try : <EOL> self . discardOutput ( checkin . markRemoved , self . cfg , repos , trvSpec ) <EOL> finally : <EOL> sys . stdin = oldStdin <EOL> def mkbranch ( self , src , newVer , what = None , shadow = False , binaryOnly = False , <EOL> sourceOnly = False , ignoreConflicts = True , targetFile = None ) : <EOL> if isinstance ( src , ( list , tuple ) ) : <EOL> troveSpecs = src <EOL> else : <EOL> assert ( what ) <EOL> if type ( src ) == str and src [ <NUM_LIT:0> ] != "<STR_LIT:/>" and src . find ( "<STR_LIT:@>" ) == - <NUM_LIT:1> : <EOL> assert ( what ) <EOL> src = "<STR_LIT:/>" + self . cfg . buildLabel . asString ( ) + "<STR_LIT:/>" + src <EOL> elif isinstance ( src , ( versions . Version , versions . Label ) ) : <EOL> assert ( what ) <EOL> src = src . asString ( ) <EOL> troveSpecs = [ what + '<STR_LIT:=>' + src ] <EOL> if type ( newVer ) == str and newVer [ <NUM_LIT:0> ] == "<STR_LIT:@>" : <EOL> newVer = versions . Label ( "<STR_LIT:localhost>" + newVer ) <EOL> elif isinstance ( newVer , str ) : <EOL> newVer = versions . Label ( newVer ) <EOL> repos = self . openRepository ( ) <EOL> branch . branch ( repos , self . cfg , newVer . asString ( ) , <EOL> troveSpecs = troveSpecs , makeShadow = shadow , <EOL> sourceOnly = sourceOnly , binaryOnly = binaryOnly , <EOL> forceBinary = True , ignoreConflicts = ignoreConflicts , <EOL> targetFile = targetFile ) <EOL> def checkout ( self , nameList , versionStr = None , dir = None , <EOL> callback = None ) : <EOL> dict = { } <EOL> if dir : <EOL> dict = { "<STR_LIT>" : dir } <EOL> if callback is None : <EOL> callback = checkin . CheckinCallback ( ) <EOL> if type ( nameList ) is str : <EOL> nameList = [ nameList ] <EOL> if versionStr : <EOL> assert ( len ( nameList ) == <NUM_LIT:1> ) <EOL> cvccmd . sourceCommand ( self . cfg , [ "<STR_LIT>" , <EOL> nameList [ <NUM_LIT:0> ] + '<STR_LIT:=>' + versionStr ] , <EOL> dict , callback = callback ) <EOL> else : <EOL> cvccmd . sourceCommand ( self . cfg , [ "<STR_LIT>" ] + nameList , dict , <EOL> callback = callback ) <EOL> def refresh ( self , globs = None , logLevel = log . INFO ) : <EOL> callback = checkin . CheckinCallback ( ) <EOL> level = log . getVerbosity ( ) <EOL> log . setVerbosity ( logLevel ) <EOL> if globs : <EOL> args = [ globs ] <EOL> else : <EOL> args = [ ] <EOL> cvccmd . sourceCommand ( self . cfg , [ "<STR_LIT>" ] + args , None , <EOL> callback = callback ) <EOL> log . setVerbosity ( level ) <EOL> def commit ( self , logLevel = log . INFO , callback = None , message = '<STR_LIT:foo>' , <EOL> cfg = None ) : <EOL> self . openRepository ( ) <EOL> if not callback : <EOL> callback = checkin . CheckinCallback ( ) <EOL> if not cfg : <EOL> cfg = self . cfg <EOL> level = log . getVerbosity ( ) <EOL> log . setVerbosity ( logLevel ) <EOL> cvccmd . sourceCommand ( cfg , [ "<STR_LIT>" ] , { '<STR_LIT:message>' : message } , <EOL> callback = callback ) <EOL> log . setVerbosity ( level ) <EOL> def context ( self , name = None , cfg = None ) : <EOL> if cfg is None : <EOL> cfg = self . cfg <EOL> cvccmd . sourceCommand ( cfg , [ "<STR_LIT>" , name ] , { } ) <EOL> def diff ( self , * args , ** kwargs ) : <EOL> self . openRepository ( ) <EOL> ( retVal , str ) = self . captureOutput ( cvccmd . sourceCommand , <EOL> self . cfg , [ "<STR_LIT>" ] + list ( args ) , <EOL> { } ) <EOL> str = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , str , <NUM_LIT:1> ) <EOL> if kwargs . get ( '<STR_LIT>' , None ) is not None : <EOL> assert ( kwargs [ '<STR_LIT>' ] == retVal ) <EOL> return str <EOL> def stat ( self , * args ) : <EOL> self . openRepository ( ) <EOL> ( rc , str ) = self . captureOutput ( cvccmd . sourceCommand , <EOL> self . cfg , [ "<STR_LIT>" ] + list ( args ) , { } ) <EOL> return str <EOL> def removeDateFromLogMessage ( self , str ) : <EOL> str = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , str ) <EOL> return str <EOL> def showLog ( self , * args , ** argSet ) : <EOL> self . openRepository ( ) <EOL> ( rc , str ) = self . captureOutput ( cvccmd . sourceCommand , <EOL> self . cfg , [ "<STR_LIT>" ] + list ( args ) , argSet ) <EOL> return self . removeDateFromLogMessage ( str ) <EOL> def annotate ( self , * args ) : <EOL> self . openRepository ( ) <EOL> ( rc , str ) = self . captureOutput ( cvccmd . sourceCommand , <EOL> self . cfg , [ "<STR_LIT>" ] + list ( args ) , <EOL> { } ) <EOL> str = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , str ) <EOL> str = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , str ) <EOL> return str <EOL> def rdiff ( self , * args ) : <EOL> self . openRepository ( ) <EOL> ( rc , str ) = self . captureOutput ( cvccmd . sourceCommand , <EOL> self . cfg , [ "<STR_LIT>" ] + list ( args ) , <EOL> { } ) <EOL> str = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , str , <NUM_LIT:1> ) <EOL> return str <EOL> def rollbackList ( self , root ) : <EOL> db = database . Database ( root , self . cfg . dbPath ) <EOL> ( rc , str ) = self . captureOutput ( rollbacks . listRollbacks , db , self . cfg ) <EOL> return str <EOL> def rollbackCount ( self ) : <EOL> f = open ( self . rootDir + "<STR_LIT>" ) <EOL> l = f . readline ( ) <EOL> ( min , max ) = l . split ( ) <EOL> max = int ( max ) <EOL> return max <EOL> def rollback ( self , root , num = None , replaceFiles = False , tagScript = None , <EOL> justDatabase = False , showInfoOnly = False , <EOL> abortOnError = False , capsuleChangesets = [ ] ) : <EOL> if num is None and type ( root ) == int : <EOL> num = root <EOL> root = self . rootDir <EOL> self . cfg . root = root <EOL> client = conaryclient . ConaryClient ( self . cfg ) <EOL> repos = self . openRepository ( ) <EOL> try : <EOL> ret = client . applyRollback ( "<STR_LIT>" % num , <EOL> replaceFiles = replaceFiles , <EOL> tagScript = tagScript , <EOL> justDatabase = justDatabase , <EOL> showInfoOnly = showInfoOnly , <EOL> abortOnError = abortOnError , <EOL> capsuleChangesets = capsuleChangesets ) <EOL> finally : <EOL> client . close ( ) <EOL> return ret <EOL> def newpkg ( self , name , factory = None , template = None ) : <EOL> self . openRepository ( ) <EOL> args = { } <EOL> if factory : <EOL> args [ '<STR_LIT>' ] = factory <EOL> if template : <EOL> args [ '<STR_LIT>' ] = template <EOL> cvccmd . sourceCommand ( self . cfg , [ "<STR_LIT>" , name ] , args ) <EOL> def makeSourceTrove ( self , name , recipeFile , buildLabel = None , <EOL> extraFiles = None , factory = None ) : <EOL> if factory is None : <EOL> factory = ( name . startswith ( '<STR_LIT>' ) and '<STR_LIT>' ) or None <EOL> oldBuildLabel = self . cfg . buildLabel <EOL> if buildLabel : <EOL> self . cfg . buildLabel = buildLabel <EOL> origDir = os . getcwd ( ) <EOL> try : <EOL> os . chdir ( self . workDir ) <EOL> self . newpkg ( name , factory = factory ) <EOL> os . chdir ( name ) <EOL> if recipeFile is not None : <EOL> self . writeFile ( name + '<STR_LIT>' , recipeFile ) <EOL> self . addfile ( name + '<STR_LIT>' ) <EOL> if extraFiles : <EOL> for fname in extraFiles : <EOL> kwargs = dict ( binary = False , text = False ) <EOL> if isinstance ( fname , tuple ) : <EOL> fname , ftype = fname [ : <NUM_LIT:2> ] <EOL> if ftype == '<STR_LIT>' : <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> elif ftype == '<STR_LIT:text>' : <EOL> kwargs [ '<STR_LIT:text>' ] = True <EOL> bname = os . path . basename ( fname ) <EOL> shutil . copy ( fname , bname ) <EOL> self . addfile ( bname , ** kwargs ) <EOL> self . commit ( ) <EOL> finally : <EOL> os . chdir ( origDir ) <EOL> self . cfg . buildLabel = oldBuildLabel <EOL> def updateSourceTrove ( self , name , recipeFile , versionStr = None ) : <EOL> origDir = os . getcwd ( ) <EOL> os . chdir ( self . workDir ) <EOL> self . checkout ( name , versionStr = versionStr ) <EOL> os . chdir ( name ) <EOL> self . writeFile ( name + '<STR_LIT>' , recipeFile ) <EOL> self . commit ( ) <EOL> os . chdir ( origDir ) <EOL> def remove ( self , name ) : <EOL> self . openRepository ( ) <EOL> cvccmd . sourceCommand ( self . cfg , [ "<STR_LIT>" , name ] , { } ) <EOL> def rename ( self , oldname , newname ) : <EOL> self . openRepository ( ) <EOL> cvccmd . sourceCommand ( self . cfg , [ "<STR_LIT>" , oldname , newname ] , { } ) <EOL> def update ( self , * args ) : <EOL> self . openRepository ( ) <EOL> callback = checkin . CheckinCallback ( ) <EOL> cvccmd . sourceCommand ( self . cfg , [ "<STR_LIT>" ] + list ( args ) , { } , <EOL> callback = callback ) <EOL> def resetFlavors ( self ) : <EOL> use . clearFlags ( ) <EOL> use . track ( False ) <EOL> def resetAllRepositories ( self ) : <EOL> self . servers . resetAllServers ( ) <EOL> if self . proxy : <EOL> self . proxy . reset ( ) <EOL> def merge ( self , * args ) : <EOL> self . openRepository ( ) <EOL> cvccmd . sourceCommand ( self . cfg , [ "<STR_LIT>" ] + list ( args ) , { } ) <EOL> def resetRepository ( self , serverIdx = <NUM_LIT:0> ) : <EOL> server = self . servers . getServer ( serverIdx ) <EOL> if server is not None : <EOL> server . reset ( ) <EOL> self . openRepository ( serverIdx = serverIdx ) <EOL> def stopRepository ( self , serverIdx = <NUM_LIT:0> ) : <EOL> server = self . servers . getServer ( serverIdx ) <EOL> if server is not None : <EOL> self . servers . stopServer ( serverIdx ) <EOL> def resetWork ( self ) : <EOL> if os . path . exists ( self . workDir ) : <EOL> util . rmtree ( self . workDir ) <EOL> if os . path . exists ( self . workDir ) : <EOL> raise IOError , '<STR_LIT>' % self . workDir <EOL> util . mkdirChain ( self . workDir ) <EOL> def resetRoot ( self ) : <EOL> if os . path . exists ( self . rootDir ) : <EOL> util . rmtree ( self . rootDir ) <EOL> util . mkdirChain ( self . rootDir ) <EOL> def resetCache ( self ) : <EOL> if os . path . exists ( self . cacheDir ) : <EOL> util . rmtree ( self . cacheDir ) <EOL> util . mkdirChain ( self . cacheDir ) <EOL> def reset ( self ) : <EOL> self . servers . resetAllServersIfNeeded ( ) <EOL> self . resetWork ( ) <EOL> self . resetRoot ( ) <EOL> self . resetCache ( ) <EOL> def _cvtVersion ( self , verStr , source = False ) : <EOL> if isinstance ( verStr , versions . Version ) : <EOL> return verStr <EOL> verStr = str ( verStr ) <EOL> if verStr [ <NUM_LIT:0> ] == '<STR_LIT::>' : <EOL> buildLabel = self . cfg . buildLabel <EOL> if '<STR_LIT:/>' not in verStr : <EOL> verStr += '<STR_LIT>' <EOL> verStr = '<STR_LIT>' % ( buildLabel . getHost ( ) , <EOL> buildLabel . getNamespace ( ) , <EOL> verStr ) <EOL> elif verStr [ <NUM_LIT:0> ] == '<STR_LIT:@>' : <EOL> buildLabel = self . cfg . buildLabel <EOL> if '<STR_LIT:/>' not in verStr : <EOL> verStr += '<STR_LIT>' <EOL> verStr = '<STR_LIT>' % ( buildLabel . getHost ( ) , verStr ) <EOL> elif verStr [ <NUM_LIT:0> ] != '<STR_LIT:/>' : <EOL> if '<STR_LIT:@>' in verStr : <EOL> if '<STR_LIT:/>' not in verStr : <EOL> verStr += '<STR_LIT>' <EOL> verStr = '<STR_LIT>' % verStr <EOL> else : <EOL> verStr = '<STR_LIT>' % ( self . cfg . buildLabel . asString ( ) , verStr ) <EOL> if '<STR_LIT:->' not in verStr : <EOL> if source : <EOL> verStr += '<STR_LIT>' <EOL> else : <EOL> verStr += '<STR_LIT>' <EOL> try : <EOL> v = versions . VersionFromString ( verStr ) . copy ( ) <EOL> v . resetTimeStamps ( ) <EOL> return v <EOL> except errors . ParseError : <EOL> pass <EOL> try : <EOL> newVerStr = verStr <EOL> if '<STR_LIT:->' not in verStr . rsplit ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] : <EOL> if source : <EOL> newVerStr += '<STR_LIT>' <EOL> else : <EOL> newVerStr += '<STR_LIT>' <EOL> v = versions . VersionFromString ( newVerStr ) . copy ( ) <EOL> v . resetTimeStamps ( ) <EOL> return v <EOL> except errors . ParseError : <EOL> pass <EOL> v = versions . ThawVersion ( verStr ) <EOL> return v <EOL> def addCollection ( self , name , version = None , strongList = None , <EOL> weakRefList = None , calcSize = False , repos = None , <EOL> defaultFlavor = None , createComps = False , <EOL> existsOkay = False , redirect = None , <EOL> changeSetFile = None , buildReqs = None , <EOL> labelPath = None , sourceName = None , <EOL> preUpdateScript = None , postInstallScript = None , <EOL> postUpdateScript = None , <EOL> preRollbackScript = None , postRollbackScript = None , <EOL> preInstallScript = None , preEraseScript = None , <EOL> postEraseScript = None , <EOL> compatClass = None , flavor = None , <EOL> loadedReqs = None , metadata = None , imageGroup = None , <EOL> pathConflicts = None ) : <EOL> if not repos : <EOL> repos = self . openRepository ( ) <EOL> if isinstance ( version , ( list , tuple ) ) : <EOL> strongList = version <EOL> version = None <EOL> assert ( strongList or redirect ) <EOL> if version is None and defaultFlavor is None : <EOL> name , version , defaultFlavor = cmdline . parseTroveSpec ( name ) <EOL> if not version : <EOL> version = '<STR_LIT:1.0>' <EOL> version = self . _cvtVersion ( version ) <EOL> assert ( '<STR_LIT::>' not in name and not name . startswith ( '<STR_LIT>' ) ) <EOL> if defaultFlavor is None : <EOL> defaultFlavor = deps . Flavor ( ) <EOL> elif isinstance ( defaultFlavor , str ) : <EOL> defaultFlavor = deps . parseFlavor ( defaultFlavor ) <EOL> fullList = { } <EOL> if weakRefList is None : <EOL> hasWeakRefs = False <EOL> weakRefList = [ ] <EOL> else : <EOL> hasWeakRefs = True <EOL> idx = <NUM_LIT:0> <EOL> for weakRef , troveList in zip ( ( False , True ) , ( strongList , weakRefList ) ) : <EOL> for info in troveList : <EOL> idx += <NUM_LIT:1> <EOL> trvFlavor = None <EOL> trvVersion = None <EOL> byDefault = True <EOL> if isinstance ( info , str ) : <EOL> trvName = info <EOL> if '<STR_LIT:=>' in trvName or '<STR_LIT:[>' in trvName : <EOL> ( trvName , trvVersion , trvFlavor ) = cmdline . parseTroveSpec ( trvName ) <EOL> elif isinstance ( info , trove . Trove ) : <EOL> ( trvName , trvVersion , trvFlavor ) = info . getNameVersionFlavor ( ) <EOL> elif len ( info ) == <NUM_LIT:1> : <EOL> ( trvName , ) = info <EOL> elif len ( info ) == <NUM_LIT:2> : <EOL> ( trvName , item ) = info <EOL> if isinstance ( item , bool ) : <EOL> byDefault = item <EOL> else : <EOL> trvVersion = item <EOL> elif len ( info ) == <NUM_LIT:3> : <EOL> ( trvName , trvVersion , trvFlavor ) = info <EOL> elif len ( info ) == <NUM_LIT:4> : <EOL> ( trvName , trvVersion , trvFlavor , byDefault ) = info <EOL> else : <EOL> assert ( False ) <EOL> if trvVersion is None and trvFlavor is None : <EOL> ( trvName , trvVersion , trvFlavor ) = cmdline . parseTroveSpec ( trvName ) <EOL> if not trvVersion : <EOL> trvVersion = version <EOL> else : <EOL> trvVersion = self . _cvtVersion ( trvVersion ) <EOL> if trvFlavor is None : <EOL> trvFlavor = defaultFlavor <EOL> elif type ( trvFlavor ) == str : <EOL> trvFlavor = deps . parseFlavor ( trvFlavor ) <EOL> if trvName [ <NUM_LIT:0> ] == '<STR_LIT::>' : <EOL> trvName = name + trvName <EOL> if createComps and '<STR_LIT::>' in trvName : <EOL> self . addComponent ( trvName , trvVersion . freeze ( ) , <EOL> str ( trvFlavor ) , filePrimer = idx , sourceName = sourceName ) <EOL> fullList [ ( trvName , trvVersion , trvFlavor ) ] = ( byDefault , <EOL> weakRef ) <EOL> if flavor : <EOL> flavor = deps . parseFlavor ( flavor , raiseError = True ) <EOL> else : <EOL> flavor = deps . mergeFlavorList ( [ x [ <NUM_LIT:2> ] for x in fullList ] , <EOL> deps . DEP_MERGE_TYPE_DROP_CONFLICTS ) <EOL> if not hasWeakRefs : <EOL> collList = [ x for x in fullList . iteritems ( ) if trove . troveIsCollection ( x [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) ] <EOL> troves = repos . getTroves ( [ x [ <NUM_LIT:0> ] for x in collList ] , withFiles = False ) <EOL> for ( troveTup , ( byDefault , _ ) ) , trv in itertools . izip ( collList , <EOL> troves ) : <EOL> for childInfo in trv . iterTroveList ( strongRefs = True , <EOL> weakRefs = True ) : <EOL> childByDefault = ( trv . includeTroveByDefault ( * childInfo ) <EOL> and byDefault ) <EOL> currInfo = fullList . get ( childInfo , None ) <EOL> if currInfo : <EOL> childByDefult = currInfo [ <NUM_LIT:0> ] or childByDefault <EOL> fullList [ childInfo ] = ( childByDefault , currInfo [ <NUM_LIT:1> ] ) <EOL> else : <EOL> fullList [ childInfo ] = ( childByDefault , True ) <EOL> if redirect is not None : <EOL> redirectList = [ ] <EOL> for info in redirect : <EOL> if info is None : <EOL> redirectList . append ( ( None , None , None ) ) <EOL> continue <EOL> if not isinstance ( info , ( list , tuple ) ) : <EOL> info = [ info ] <EOL> if len ( info ) == <NUM_LIT:1> : <EOL> redirName = info [ <NUM_LIT:0> ] <EOL> redirBranch = version . branch ( ) <EOL> redirFlavor = flavor <EOL> elif len ( info ) == <NUM_LIT:2> : <EOL> redirName , redirBranch = info <EOL> redirBranch = versions . VersionFromString ( redirBranch ) <EOL> redirFlavor = deps . parseFlavor ( '<STR_LIT>' ) <EOL> else : <EOL> redirName , redirBranch , redirFlavor = info <EOL> redirBranch = versions . VersionFromString ( redirBranch ) <EOL> redirFlavor = deps . parseFlavor ( redirFlavor ) <EOL> redirectList . append ( ( redirName , redirBranch , redirFlavor ) ) <EOL> if redirect is not None : <EOL> troveType = trove . TROVE_TYPE_REDIRECT <EOL> else : <EOL> troveType = trove . TROVE_TYPE_NORMAL <EOL> coll = trove . Trove ( name , version , flavor , None , type = troveType ) <EOL> if existsOkay and repos . hasTrove ( name , version , flavor ) : <EOL> return repos . getTrove ( name , version , flavor ) <EOL> coll . setIsCollection ( True ) <EOL> coll . setSize ( <NUM_LIT:0> ) <EOL> for info , ( byDefault , weakRef ) in fullList . iteritems ( ) : <EOL> coll . addTrove ( * info , ** dict ( byDefault = byDefault , weakRef = weakRef ) ) <EOL> if not sourceName : <EOL> sourceName = name + '<STR_LIT>' <EOL> coll . setSourceName ( sourceName ) <EOL> coll . setBuildTime ( <NUM_LIT> ) <EOL> if redirect : <EOL> for toName , toBranch , toFlavor in redirectList : <EOL> coll . addRedirect ( toName , toBranch , toFlavor ) <EOL> else : <EOL> coll . setProvides ( deps . parseDep ( '<STR_LIT>' % name ) ) <EOL> if buildReqs is not None : <EOL> buildReqs = self . makeTroveTupleList ( buildReqs ) <EOL> coll . setBuildRequirements ( buildReqs ) <EOL> if loadedReqs : <EOL> loadedReqs = self . makeTroveTupleList ( loadedReqs ) <EOL> coll . setLoadedTroves ( loadedReqs ) <EOL> if pathConflicts is not None : <EOL> for path in pathConflicts : <EOL> coll . troveInfo . pathConflicts . append ( path ) <EOL> if labelPath : <EOL> coll . setLabelPath ( labelPath ) <EOL> if compatClass : <EOL> coll . setCompatibilityClass ( compatClass ) <EOL> for spec , script in [ ( preUpdateScript , coll . troveInfo . scripts . preUpdate ) , <EOL> ( postInstallScript , coll . troveInfo . scripts . postInstall ) , <EOL> ( postUpdateScript , coll . troveInfo . scripts . postUpdate ) , <EOL> ( preRollbackScript , coll . troveInfo . scripts . preRollback ) , <EOL> ( postRollbackScript , coll . troveInfo . scripts . postRollback ) , <EOL> ( preInstallScript , coll . troveInfo . scripts . preInstall ) , <EOL> ( preEraseScript , coll . troveInfo . scripts . preErase ) , <EOL> ( postEraseScript , coll . troveInfo . scripts . postErase ) , ] : <EOL> if spec is None : continue <EOL> if type ( spec ) == str : <EOL> spec = TroveScript ( script = spec ) <EOL> script . script . set ( spec . script ) <EOL> if spec . conversions : <EOL> assert ( compatClass ) <EOL> assert ( isinstance ( spec , RollbackScript ) ) <EOL> script . conversions . addList ( <EOL> ( compatClass , x ) for x in spec . conversions ) <EOL> if calcSize : <EOL> compList = [ x for x in fullList if not trove . troveIsCollection ( x [ <NUM_LIT:0> ] ) ] <EOL> size = ( x . getSize ( ) for x in repos . getTroves ( compList , withFiles = False ) ) <EOL> coll . setSize ( sum ( x for x in size if x is not None ) ) <EOL> if metadata : <EOL> if not isinstance ( metadata , ( list , tuple ) ) : <EOL> metadata = [ metadata ] <EOL> for item in metadata : <EOL> coll . troveInfo . metadata . addItem ( item ) <EOL> if imageGroup is not None : <EOL> coll . troveInfo . imageGroup . set ( imageGroup ) <EOL> coll . computeDigests ( ) <EOL> assert ( redirect or list ( coll . iterTroveList ( strongRefs = True ) ) ) <EOL> cs = changeset . ChangeSet ( ) <EOL> diff = coll . diff ( None , absolute = True ) [ <NUM_LIT:0> ] <EOL> cs . newTrove ( diff ) <EOL> if changeSetFile : <EOL> cs . addPrimaryTrove ( coll . getName ( ) , coll . getVersion ( ) , <EOL> coll . getFlavor ( ) ) <EOL> cs . writeToFile ( changeSetFile ) <EOL> else : <EOL> repos . commitChangeSet ( cs ) <EOL> return coll <EOL> addQuickTestCollection = addCollection <EOL> def makeTroveTupleList ( self , troveItems , defaultFlavor = None ) : <EOL> tupleList = [ ] <EOL> for item in troveItems : <EOL> if isinstance ( item , trove . Trove ) : <EOL> tupleList . append ( item . getNameVersionFlavor ( ) ) <EOL> elif isinstance ( item , tuple ) : <EOL> bflv = None <EOL> if len ( item ) == <NUM_LIT:1> : <EOL> bver = self . _cvtVersion ( '<STR_LIT:1>' ) <EOL> bname = item <EOL> elif len ( item ) == <NUM_LIT:2> : <EOL> if isinstance ( item [ <NUM_LIT:0> ] , trove . Trove ) : <EOL> bname , bver = item [ <NUM_LIT:0> ] . getName ( ) , item [ <NUM_LIT:0> ] . getVersion ( ) <EOL> bflv = item [ <NUM_LIT:1> ] <EOL> else : <EOL> bname , bver = item <EOL> bver = self . _cvtVersion ( bver ) <EOL> else : <EOL> bname , bver , bflv = item <EOL> bver = self . _cvtVersion ( bver ) <EOL> if bflv is None : <EOL> bflv = defaultFlavor <EOL> elif isinstance ( bflv , str ) : <EOL> bflv = deps . parseFlavor ( bflv ) <EOL> tupleList . append ( ( bname , bver , bflv ) ) <EOL> else : <EOL> assert <NUM_LIT:0> , "<STR_LIT>" % item <EOL> return tupleList <EOL> def addComponent ( self , * args , ** kw ) : <EOL> changeSetFile = kw . pop ( '<STR_LIT>' , None ) <EOL> hidden = kw . pop ( '<STR_LIT>' , False ) <EOL> repos = kw . pop ( '<STR_LIT>' , None ) <EOL> if not repos : <EOL> repos = self . openRepository ( ) <EOL> kw [ '<STR_LIT>' ] = repos <EOL> t , cs = self . Component ( * args , ** kw ) <EOL> if cs is not None : <EOL> if changeSetFile : <EOL> cs . writeToFile ( changeSetFile ) <EOL> else : <EOL> repos . commitChangeSet ( cs , hidden = hidden ) <EOL> return t <EOL> def Component ( self , troveName , version = None , flavor = None , <EOL> fileContents = None , <EOL> provides = deps . DependencySet ( ) , <EOL> requires = deps . DependencySet ( ) , <EOL> filePrimer = <NUM_LIT:0> , setConfigFlags = True , <EOL> repos = None , existsOkay = False , pathIdSalt = '<STR_LIT>' , <EOL> redirect = None , sourceName = None , metadata = None , <EOL> factory = None , capsule = None , <EOL> versus = None , buildTime = <NUM_LIT> ) : <EOL> if isinstance ( flavor , list ) : <EOL> fileContents = flavor <EOL> flavor = None <EOL> elif isinstance ( version , list ) : <EOL> fileContents = version <EOL> version = None <EOL> if version is None and flavor is None : <EOL> troveName , version , flavor = cmdline . parseTroveSpec ( troveName ) <EOL> if not version : <EOL> version = '<STR_LIT:1.0>' <EOL> if flavor is None : <EOL> flavor = '<STR_LIT>' <EOL> troveVersion = self . _cvtVersion ( version , <EOL> source = troveName . endswith ( '<STR_LIT>' ) ) <EOL> isSource = troveName . endswith ( '<STR_LIT>' ) <EOL> assert ( '<STR_LIT::>' in troveName or trove . troveIsFileSet ( troveName ) ) <EOL> componentDir = self . workDir + "<STR_LIT>" <EOL> if os . path . exists ( componentDir ) : <EOL> shutil . rmtree ( componentDir ) <EOL> util . mkdirChain ( componentDir ) <EOL> if isinstance ( flavor , list ) : <EOL> assert ( fileContents is None ) <EOL> fileContents = flavor <EOL> flavor = '<STR_LIT>' <EOL> flavor = deps . parseFlavor ( flavor ) <EOL> if redirect is not None : <EOL> troveType = trove . TROVE_TYPE_REDIRECT <EOL> else : <EOL> troveType = trove . TROVE_TYPE_NORMAL <EOL> t = trove . Trove ( troveName , troveVersion , flavor , None , type = troveType ) <EOL> fileList = [ ] <EOL> if redirect is not None : <EOL> redirectList = [ ] <EOL> assert ( fileContents is None ) <EOL> for info in redirect : <EOL> if info is None : <EOL> continue <EOL> if not isinstance ( info , ( list , tuple ) ) : <EOL> info = [ info ] <EOL> if len ( info ) == <NUM_LIT:1> : <EOL> redirName = info [ <NUM_LIT:0> ] <EOL> redirBranch = troveVersion . branch ( ) <EOL> redirFlavor = flavor <EOL> elif len ( info ) == <NUM_LIT:2> : <EOL> redirName , redirBranch = info <EOL> redirBranch = versions . VersionFromString ( redirBranch ) <EOL> redirFlavor = None <EOL> else : <EOL> redirName , redirBranch , redirFlavor = info <EOL> redirBranch = versions . VersionFromString ( redirBranch ) <EOL> if redirFlavor is not None : <EOL> redirFlavor = deps . parseFlavor ( redirFlavor ) <EOL> redirectList . append ( ( redirName , redirBranch , redirFlavor ) ) <EOL> else : <EOL> if capsule : <EOL> assert ( capsule . endswith ( '<STR_LIT>' ) ) <EOL> f = files . FileFromFilesystem ( capsule , <EOL> trove . CAPSULE_PATHID ) <EOL> hdr = rpmhelper . readHeader ( open ( capsule ) ) <EOL> t . addRpmCapsule ( os . path . basename ( capsule ) , <EOL> troveVersion , <EOL> f . fileId ( ) , hdr ) <EOL> fileList . append ( ( f , trove . CAPSULE_PATHID , <EOL> filecontents . FromFilesystem ( capsule ) ) ) <EOL> elif fileContents is None : <EOL> path = '<STR_LIT>' % filePrimer <EOL> contents = '<STR_LIT>' <EOL> if not filePrimer : <EOL> filePrimer = '<STR_LIT>' <EOL> filePrimer = str ( filePrimer ) <EOL> pathId = filePrimer . rjust ( <NUM_LIT:16> , '<STR_LIT>' ) <EOL> pathId = pathId [ <NUM_LIT:0> : <NUM_LIT:16> ] <EOL> contents = RegularFile ( contents = contents , pathId = pathId , <EOL> config = None ) <EOL> fileContents = [ ( path , contents ) ] <EOL> index = <NUM_LIT:0> <EOL> for fileInfo in fileContents : <EOL> fileReq = None <EOL> fileProv = None <EOL> fileFlavor = None <EOL> if isinstance ( fileInfo , str ) : <EOL> fileInfo = [ fileInfo , '<STR_LIT:foo>' ] <EOL> fileName , contents = fileInfo [ <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> if isinstance ( contents , filetypes . _File ) : <EOL> assert ( len ( fileInfo ) == <NUM_LIT:2> ) <EOL> else : <EOL> if len ( fileInfo ) > <NUM_LIT:3> : <EOL> if isinstance ( fileInfo [ <NUM_LIT:3> ] , ( list , tuple ) ) : <EOL> fileReq = fileInfo [ <NUM_LIT:3> ] [ <NUM_LIT:0> ] <EOL> fileProv = fileInfo [ <NUM_LIT:3> ] [ <NUM_LIT:1> ] <EOL> else : <EOL> fileReq = fileInfo [ <NUM_LIT:3> ] <EOL> if len ( fileInfo ) > <NUM_LIT:2> and fileInfo [ <NUM_LIT:2> ] is not None : <EOL> fileVersion = self . _cvtVersion ( fileInfo [ <NUM_LIT:2> ] ) <EOL> else : <EOL> fileVersion = troveVersion <EOL> contents = RegularFile ( requires = fileReq , <EOL> provides = fileProv , <EOL> contents = contents ) <EOL> contents . version = fileVersion <EOL> cont = componentDir + '<STR_LIT:/>' + fileName <EOL> dir = os . path . dirname ( cont ) <EOL> if not os . path . exists ( dir ) : <EOL> util . mkdirChain ( dir ) <EOL> pathId = contents . pathId <EOL> if pathId is None : <EOL> pathId = sha1helper . md5String ( pathIdSalt + fileName ) <EOL> else : <EOL> pathId += '<STR_LIT:0>' * ( <NUM_LIT:16> - len ( pathId ) ) <EOL> f = contents . get ( pathId ) <EOL> f . flags . isSource ( isSource ) <EOL> if contents . config is not None : <EOL> f . flags . isConfig ( contents . config ) <EOL> elif ( ( setConfigFlags and fileName . startswith ( '<STR_LIT>' ) ) <EOL> or troveName . endswith ( '<STR_LIT>' ) ) : <EOL> f . flags . isConfig ( True ) <EOL> index += <NUM_LIT:1> <EOL> if capsule and not ( f . flags . isConfig ( ) or <EOL> getattr ( contents , '<STR_LIT>' , None ) ) : <EOL> f . flags . isEncapsulatedContent ( True ) <EOL> if contents . version : <EOL> fileVersion = self . _cvtVersion ( contents . version ) <EOL> elif ( versus and versus . hasFile ( pathId ) and <EOL> versus . getFile ( pathId ) [ <NUM_LIT:1> ] == f . fileId ( ) ) : <EOL> fileVersion = versus . getFile ( pathId ) [ <NUM_LIT:2> ] <EOL> else : <EOL> fileVersion = troveVersion <EOL> if not troveName . endswith ( '<STR_LIT>' ) : <EOL> if fileName [ <NUM_LIT:0> ] != '<STR_LIT:/>' : <EOL> fileName = '<STR_LIT:/>' + fileName <EOL> assert ( len ( pathId ) == <NUM_LIT:16> ) <EOL> t . addFile ( pathId , fileName , fileVersion , f . fileId ( ) ) <EOL> if hasattr ( contents , '<STR_LIT>' ) : <EOL> fileList . append ( ( f , pathId , contents . contents ) ) <EOL> else : <EOL> fileList . append ( ( f , pathId , None ) ) <EOL> for f , pathId , contents in fileList : <EOL> flavor . union ( f . flavor ( ) ) <EOL> t . changeFlavor ( flavor ) <EOL> cs = changeset . ChangeSet ( ) <EOL> if existsOkay and repos . hasTrove ( troveName , troveVersion , flavor ) : <EOL> return repos . getTrove ( troveName , troveVersion , flavor ) , None <EOL> if factory is not None : <EOL> t . setFactory ( factory ) <EOL> if not redirect : <EOL> if isinstance ( requires , str ) : <EOL> req = deps . parseDep ( requires ) <EOL> else : <EOL> req = requires . copy ( ) <EOL> if isinstance ( provides , str ) : <EOL> prov = deps . parseDep ( provides ) <EOL> else : <EOL> prov = provides . copy ( ) <EOL> prov . union ( deps . parseDep ( '<STR_LIT>' % t . getName ( ) ) ) <EOL> for f , pathId , contents in fileList : <EOL> req . union ( f . requires ( ) ) <EOL> prov . union ( f . provides ( ) ) <EOL> t . setRequires ( req ) <EOL> t . setProvides ( prov ) <EOL> if not troveName . endswith ( '<STR_LIT>' ) : <EOL> if not sourceName : <EOL> sourceName = troveName . split ( "<STR_LIT::>" ) [ <NUM_LIT:0> ] + "<STR_LIT>" <EOL> t . setSourceName ( sourceName ) <EOL> t . computePathHashes ( ) <EOL> t . setBuildTime ( buildTime ) <EOL> if redirect : <EOL> for toName , toBranch , toFlavor in redirectList : <EOL> t . addRedirect ( toName , toBranch , toFlavor ) <EOL> if redirect : <EOL> for toName , toBranch , toFlavor in redirectList : <EOL> t . addRedirect ( toName , toBranch , toFlavor ) <EOL> size = <NUM_LIT:0> <EOL> for f , pathId , contents in fileList : <EOL> cs . addFile ( None , f . fileId ( ) , f . freeze ( ) ) <EOL> if f . hasContents and not f . flags . isEncapsulatedContent ( ) : <EOL> cs . addFileContents ( pathId , f . fileId ( ) , <EOL> changeset . ChangedFileTypes . file , contents , <EOL> f . flags . isConfig ( ) ) <EOL> size += f . contents . size ( ) <EOL> if metadata : <EOL> if not isinstance ( metadata , ( tuple , list ) ) : <EOL> metadata = [ metadata ] <EOL> for item in metadata : <EOL> t . troveInfo . metadata . addItem ( item ) <EOL> t . setSize ( size ) <EOL> t . computeDigests ( ) <EOL> diff = t . diff ( None , absolute = True ) [ <NUM_LIT:0> ] <EOL> cs . newTrove ( diff ) <EOL> cs . setPrimaryTroveList ( [ t . getNameVersionFlavor ( ) ] ) <EOL> return t , cs <EOL> addQuickTestComponent = addComponent <EOL> def addDbComponent ( self , db , name , version = '<STR_LIT:1>' , flavor = '<STR_LIT>' , <EOL> provides = deps . DependencySet ( ) , <EOL> requires = deps . DependencySet ( ) ) : <EOL> fileList = [ ] <EOL> cont = self . workDir + '<STR_LIT>' <EOL> f = open ( cont , '<STR_LIT:w>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . close ( ) <EOL> pathId = sha1helper . md5FromString ( '<STR_LIT:0>' * <NUM_LIT:32> ) <EOL> f = files . FileFromFilesystem ( cont , pathId ) <EOL> fileList . append ( ( f , cont , pathId ) ) <EOL> v = self . _cvtVersion ( version ) <EOL> flavor = deps . parseFlavor ( flavor ) <EOL> t = trove . Trove ( name , v , flavor , None ) <EOL> for f , name , pathId in fileList : <EOL> t . addFile ( pathId , '<STR_LIT:/>' + name , v , f . fileId ( ) ) <EOL> t . setRequires ( requires ) <EOL> t . setProvides ( provides ) <EOL> info = db . addTrove ( t ) <EOL> db . addTroveDone ( info ) <EOL> db . commit ( ) <EOL> return t <EOL> addQuickDbTestPkg = addDbComponent <EOL> def addRPMComponent ( self , nameSpec , rpmPath , versus = None , <EOL> fileContents = None , requires = deps . DependencySet ( ) ) : <EOL> if rpmPath [ <NUM_LIT:0> ] != '<STR_LIT:/>' : <EOL> rpmPath = resources . get_archive ( rpmPath ) <EOL> f = open ( rpmPath , "<STR_LIT:r>" ) <EOL> h = rpmhelper . readHeader ( f ) <EOL> expandDir = self . workDir + '<STR_LIT>' <EOL> if os . path . exists ( expandDir ) : <EOL> shutil . rmtree ( expandDir ) <EOL> os . mkdir ( expandDir ) <EOL> p = os . popen ( "<STR_LIT>" % ( expandDir , ) , "<STR_LIT:w>" ) <EOL> rpmhelper . extractRpmPayload ( f , p ) <EOL> p . close ( ) <EOL> f . close ( ) <EOL> fl = [ ] <EOL> for path , mode , flags , linksTo , fileColor , rdev in itertools . izip ( <EOL> h [ rpmhelper . OLDFILENAMES ] , <EOL> h [ rpmhelper . FILEMODES ] , h [ rpmhelper . FILEFLAGS ] , <EOL> h [ rpmhelper . FILELINKTOS ] , <EOL> h [ rpmhelper . FILECOLORS ] , <EOL> h [ rpmhelper . FILERDEVS ] ) : <EOL> if stat . S_ISDIR ( mode ) : <EOL> fl . append ( ( path , Directory ( ) ) ) <EOL> elif stat . S_ISBLK ( mode ) or stat . S_ISCHR ( mode ) : <EOL> minor = rdev & <NUM_LIT> | ( rdev >> <NUM_LIT:12> ) & <NUM_LIT> <EOL> major = ( rdev >> <NUM_LIT:8> ) & <NUM_LIT> <EOL> if stat . S_ISBLK ( mode ) : <EOL> fl . append ( ( path , BlockDevice ( major , minor ) ) ) <EOL> elif stat . S_ISCHR ( mode ) : <EOL> fl . append ( ( path , CharacterDevice ( major , minor ) ) ) <EOL> else : <EOL> isConfig = ( ( flags & rpmhelper . RPMFILE_CONFIG ) != <NUM_LIT:0> ) <EOL> isGhost = ( ( flags & rpmhelper . RPMFILE_GHOST ) != <NUM_LIT:0> ) <EOL> if stat . S_ISLNK ( mode ) : <EOL> fobj = Symlink ( linksTo ) <EOL> else : <EOL> if isGhost : <EOL> contents = '<STR_LIT>' <EOL> isConfig = False <EOL> else : <EOL> contents = open ( expandDir + path ) <EOL> if fileColor == <NUM_LIT:2> : <EOL> req = '<STR_LIT>' <EOL> elif fileColor == <NUM_LIT:1> : <EOL> req = '<STR_LIT>' <EOL> else : <EOL> req = None <EOL> fobj = RegularFile ( contents = contents , <EOL> config = isConfig , <EOL> initialContents = isGhost , <EOL> requires = req ) <EOL> if isGhost : <EOL> fobj . isGhost = True <EOL> fl . append ( ( path , fobj ) ) <EOL> fl . extend ( fileContents or [ ] ) <EOL> return self . addComponent ( nameSpec , fileContents = fl , <EOL> capsule = rpmPath , versus = versus , <EOL> requires = requires ) <EOL> def addTestPkg ( self , num , requires = [ ] , fail = False , content = '<STR_LIT>' , <EOL> flags = [ ] , localflags = [ ] , packageSpecs = [ ] , subPackages = [ ] , <EOL> version = '<STR_LIT:1.0>' , branch = None , <EOL> header = '<STR_LIT>' , fileContents = '<STR_LIT>' , <EOL> tag = None , binary = False ) : <EOL> """<STR_LIT>""" <EOL> origDir = os . getcwd ( ) <EOL> os . chdir ( self . workDir ) <EOL> pkgname = '<STR_LIT>' % num <EOL> if not '<STR_LIT>' in self . __dict__ : <EOL> self . packages = { } <EOL> if num in self . packages : <EOL> self . checkout ( pkgname , branch ) <EOL> else : <EOL> self . newpkg ( pkgname ) <EOL> os . chdir ( pkgname ) <EOL> if not isinstance ( subPackages , ( tuple , list ) ) : <EOL> subPackages = [ subPackages ] <EOL> if not isinstance ( packageSpecs , ( tuple , list ) ) : <EOL> packageSpecs = [ packageSpecs ] <EOL> fileContents = recipes . createRecipe ( num , requires , fail , content , <EOL> packageSpecs , subPackages , version = version , flags = flags , <EOL> localflags = localflags , header = header , fileContents = fileContents , <EOL> tag = tag , binary = binary ) <EOL> self . writeFile ( pkgname + '<STR_LIT>' , fileContents ) <EOL> if num not in self . packages : <EOL> self . addfile ( pkgname + '<STR_LIT>' ) <EOL> self . commit ( ) <EOL> os . chdir ( '<STR_LIT:..>' ) <EOL> shutil . rmtree ( pkgname ) <EOL> os . chdir ( origDir ) <EOL> self . packages [ num ] = pkgname <EOL> return fileContents <EOL> def cookTestPkg ( self , num , logLevel = log . WARNING , macros = { } , prep = False ) : <EOL> stdout = os . dup ( sys . stdout . fileno ( ) ) <EOL> stderr = os . dup ( sys . stderr . fileno ( ) ) <EOL> null = os . open ( '<STR_LIT>' , os . O_WRONLY ) <EOL> os . dup2 ( null , sys . stdout . fileno ( ) ) <EOL> os . dup2 ( null , sys . stderr . fileno ( ) ) <EOL> try : <EOL> return cook . cookItem ( self . repos , self . cfg , '<STR_LIT>' % num , macros = macros , prep = prep ) <EOL> finally : <EOL> os . dup2 ( stdout , sys . stdout . fileno ( ) ) <EOL> os . dup2 ( stderr , sys . stderr . fileno ( ) ) <EOL> os . close ( null ) <EOL> os . close ( stdout ) <EOL> os . close ( stderr ) <EOL> def createMetadataItem ( self , ** kw ) : <EOL> mi = trove . MetadataItem ( ) <EOL> for key , value in kw . items ( ) : <EOL> if isinstance ( value , ( list , tuple ) ) : <EOL> for val in value : <EOL> getattr ( mi , key ) . set ( val ) <EOL> elif isinstance ( value , dict ) : <EOL> getattr ( mi , key ) . update ( value ) <EOL> else : <EOL> getattr ( mi , key ) . set ( value ) <EOL> return mi <EOL> def cookFromRepository ( self , troveName , buildLabel = None , ignoreDeps = False , repos = None , logBuild = False , callback = None ) : <EOL> if buildLabel : <EOL> oldLabel = self . cfg . buildLabel <EOL> self . cfg . buildLabel = buildLabel <EOL> if not repos : <EOL> repos = self . openRepository ( ) <EOL> built = self . discardOutput ( cook . cookItem , repos , self . cfg , troveName , <EOL> ignoreDeps = ignoreDeps , logBuild = logBuild , <EOL> callback = callback ) <EOL> if buildLabel : <EOL> self . cfg . buildLabel = oldLabel <EOL> return built [ <NUM_LIT:0> ] <EOL> def verifyFifo ( self , file ) : <EOL> return stat . S_ISFIFO ( os . lstat ( file ) . st_mode ) <EOL> def verifyFile ( self , path , contents = None , perms = None ) : <EOL> f = open ( path , "<STR_LIT:r>" ) <EOL> other = f . read ( ) <EOL> if contents is not None : <EOL> if other != contents : <EOL> self . fail ( "<STR_LIT>" % path ) <EOL> assert ( other == contents ) <EOL> if perms is not None : <EOL> assert ( os . stat ( path ) [ stat . ST_MODE ] & <NUM_LIT:0> <NUM_LIT> == perms ) <EOL> def verifyNoFile ( self , file ) : <EOL> try : <EOL> f = open ( file , "<STR_LIT:r>" ) <EOL> except IOError , err : <EOL> if err . errno == <NUM_LIT:2> : <EOL> return <EOL> else : <EOL> self . fail ( "<STR_LIT>" % err . errno ) <EOL> else : <EOL> self . fail ( "<STR_LIT>" % file ) <EOL> def verifySrcDirectory ( self , contents , dir = "<STR_LIT:.>" ) : <EOL> self . verifyDirectory ( contents + [ "<STR_LIT>" ] , dir ) <EOL> def verifyDirectory ( self , contents , dir = "<STR_LIT:.>" ) : <EOL> self . verifyFileList ( contents , os . listdir ( dir ) ) <EOL> def verifyPackageFileList ( self , pkg , ideal ) : <EOL> list = [ x [ <NUM_LIT:1> ] for x in pkg . iterFileList ( ) ] <EOL> self . verifyFileList ( ideal , list ) <EOL> def verifyTroves ( self , pkg , ideal ) : <EOL> actual = [ ( x [ <NUM_LIT:0> ] , x [ <NUM_LIT:1> ] . asString ( ) , x [ <NUM_LIT:2> ] ) for x in pkg . iterTroveList ( strongRefs = True ) ] <EOL> if sorted ( actual ) != sorted ( ideal ) : <EOL> self . fail ( "<STR_LIT>" <EOL> % ( actual , ideal ) ) <EOL> def verifyFileList ( self , ideal , actual ) : <EOL> dict = { } <EOL> for n in ideal : dict [ n ] = <NUM_LIT:1> <EOL> for n in actual : <EOL> if dict . has_key ( n ) : <EOL> del dict [ n ] <EOL> else : <EOL> self . fail ( "<STR_LIT>" % n ) <EOL> if dict : <EOL> self . fail ( "<STR_LIT>" % "<STR_LIT:U+0020>" . join ( dict . keys ( ) ) ) <EOL> assert ( not dict ) <EOL> def verifyInstalledFileList ( self , dir , list ) : <EOL> paths = { } <EOL> for path in list : <EOL> paths [ path ] = True <EOL> dirLen = len ( dir ) <EOL> for ( dirName , dirNameList , pathNameList ) in os . walk ( dir ) : <EOL> for path in pathNameList : <EOL> if path [ <NUM_LIT:0> ] == "<STR_LIT:.>" : continue <EOL> fullPath = dirName [ dirLen : ] + "<STR_LIT:/>" + path <EOL> if fullPath == "<STR_LIT>" : continue <EOL> if fullPath . startswith ( "<STR_LIT>" ) : continue <EOL> if paths . has_key ( fullPath ) : <EOL> del paths [ fullPath ] <EOL> else : <EOL> self . fail ( "<STR_LIT>" % fullPath ) <EOL> if paths : <EOL> self . fail ( "<STR_LIT>" % "<STR_LIT:U+0020>" . join ( paths . keys ( ) ) ) <EOL> def cookItem ( self , * args , ** kw ) : <EOL> return self . discardOutput ( cook . cookItem , * args , ** kw ) <EOL> _printOnError = False <EOL> def cookObject ( self , loader , prep = False , macros = { } , sourceVersion = None , <EOL> serverIdx = <NUM_LIT:0> , ignoreDeps = False , logBuild = False , <EOL> targetLabel = None , repos = None , <EOL> groupOptions = None , resume = None ) : <EOL> theClass = loader . getRecipe ( ) <EOL> if repos is None : <EOL> repos = self . openRepository ( serverIdx ) <EOL> if sourceVersion is None : <EOL> sourceVersion = cook . guessSourceVersion ( repos , theClass . name , <EOL> theClass . version , <EOL> self . cfg . buildLabel , <EOL> searchBuiltTroves = True ) [ <NUM_LIT:0> ] <EOL> if not sourceVersion : <EOL> sourceVersion = versions . VersionFromString ( '<STR_LIT>' % ( <EOL> self . cfg . buildLabel . asString ( ) , <EOL> theClass . version ) ) <EOL> use . resetUsed ( ) <EOL> try : <EOL> builtList , _ = self . captureOutput ( cook . cookObject , <EOL> repos , <EOL> self . cfg , <EOL> [ loader ] , <EOL> sourceVersion , <EOL> prep = prep , macros = macros , <EOL> allowMissingSource = True , <EOL> ignoreDeps = ignoreDeps , <EOL> logBuild = logBuild , <EOL> groupOptions = groupOptions , <EOL> resume = resume , <EOL> _printOnError = self . _printOnError , <EOL> ) <EOL> finally : <EOL> repos . close ( ) <EOL> return builtList <EOL> def cookPackageObject ( self , theClass , prep = False , macros = { } , <EOL> sourceVersion = None , serverIdx = <NUM_LIT:0> , <EOL> ignoreDeps = False ) : <EOL> """<STR_LIT>""" <EOL> repos = self . openRepository ( serverIdx ) <EOL> if sourceVersion is None : <EOL> sourceVersion , _ = cook . guessSourceVersion ( repos , theClass . name , <EOL> theClass . version , <EOL> self . cfg . buildLabel , <EOL> searchBuiltTroves = True ) <EOL> if not sourceVersion : <EOL> sourceVersion = versions . VersionFromString ( '<STR_LIT>' % ( <EOL> self . cfg . buildLabel . asString ( ) , <EOL> theClass . version ) ) <EOL> use . resetUsed ( ) <EOL> stdout = os . dup ( sys . stdout . fileno ( ) ) <EOL> stderr = os . dup ( sys . stderr . fileno ( ) ) <EOL> null = os . open ( '<STR_LIT>' , os . O_WRONLY ) <EOL> os . dup2 ( null , sys . stdout . fileno ( ) ) <EOL> os . dup2 ( null , sys . stderr . fileno ( ) ) <EOL> try : <EOL> res = cook . _cookPackageObject ( repos , self . cfg , theClass , <EOL> sourceVersion , <EOL> prep = prep , macros = macros , <EOL> ignoreDeps = ignoreDeps ) <EOL> finally : <EOL> os . dup2 ( stdout , sys . stdout . fileno ( ) ) <EOL> os . dup2 ( stderr , sys . stderr . fileno ( ) ) <EOL> os . close ( null ) <EOL> os . close ( stdout ) <EOL> os . close ( stderr ) <EOL> repos . close ( ) <EOL> if not res : <EOL> return None <EOL> return res [ <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> def getRecipeObjFromRepos ( self , name , repos ) : <EOL> stdout = os . dup ( sys . stdout . fileno ( ) ) <EOL> stderr = os . dup ( sys . stderr . fileno ( ) ) <EOL> null = os . open ( '<STR_LIT>' , os . O_WRONLY ) <EOL> os . dup2 ( null , sys . stdout . fileno ( ) ) <EOL> os . dup2 ( null , sys . stderr . fileno ( ) ) <EOL> try : <EOL> loader , sourceVersion = loadrecipe . recipeLoaderFromSourceComponent ( <EOL> name , self . cfg , repos ) [ <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> recipeObj = cook . _cookPackageObject ( repos , self . cfg , loader , <EOL> sourceVersion , prep = True , requireCleanSources = True ) <EOL> finally : <EOL> os . dup2 ( stdout , sys . stdout . fileno ( ) ) <EOL> os . dup2 ( stderr , sys . stderr . fileno ( ) ) <EOL> os . close ( null ) <EOL> os . close ( stdout ) <EOL> os . close ( stderr ) <EOL> return recipeObj <EOL> def repairTroves ( self , pkgList = [ ] , root = None ) : <EOL> if root is None : <EOL> root = self . rootDir <EOL> repos = self . openRepository ( ) <EOL> db = self . openDatabase ( root = root ) <EOL> troveList = [ ] <EOL> for item in pkgList : <EOL> name , ver , flv = updatecmd . parseTroveSpec ( item ) <EOL> troves = db . findTrove ( None , ( name , ver , flv ) ) <EOL> troveList += troves <EOL> db . repairTroves ( repos , troveList ) <EOL> def updatePkg ( self , root , pkg = [ ] , version = None , tagScript = None , <EOL> noScripts = False , keepExisting = False , replaceFiles = None , <EOL> resolve = False , depCheck = True , justDatabase = False , <EOL> flavor = None , recurse = True , sync = False , <EOL> info = False , fromFiles = [ ] , checkPathConflicts = True , <EOL> test = False , migrate = False , keepRequired = None , <EOL> raiseError = False , callback = None , restartInfo = None , <EOL> applyCriticalOnly = False , syncChildren = False , <EOL> keepJournal = False , noRestart = False , <EOL> exactFlavors = False , replaceManagedFiles = False , <EOL> replaceModifiedFiles = False , replaceUnmanagedFiles = False , <EOL> replaceModifiedConfigFiles = False , skipCapsuleOps = False , <EOL> criticalUpdateInfo = None , modelFile = None ) : <EOL> if not isinstance ( root , str ) or not root [ <NUM_LIT:0> ] == '<STR_LIT:/>' : <EOL> if isinstance ( root , list ) : <EOL> pkg = root <EOL> else : <EOL> pkg = [ root ] <EOL> root = self . rootDir <EOL> newcfg = self . cfg <EOL> newcfg . root = root <EOL> if callback is None : <EOL> callback = callbacks . UpdateCallback ( ) <EOL> if replaceFiles is not None : <EOL> replaceManagedFiles = replaceFiles <EOL> replaceUnmanagedFiles = replaceFiles <EOL> replaceModifiedFiles = replaceFiles <EOL> replaceModifiedConfigFiles = replaceFiles <EOL> repos = self . openRepository ( ) <EOL> if isinstance ( pkg , ( str , list ) ) : <EOL> if isinstance ( pkg , str ) : <EOL> if version is not None : <EOL> if type ( version ) is not str : <EOL> version = version . asString ( ) <EOL> item = "<STR_LIT>" % ( pkg , version ) <EOL> else : <EOL> item = pkg <EOL> if flavor is not None : <EOL> item += '<STR_LIT>' % flavor <EOL> pkgl = [ item ] <EOL> else : <EOL> assert ( version is None ) <EOL> assert ( flavor is None ) <EOL> pkgl = list ( itertools . chain ( * ( util . braceExpand ( x ) for x in pkg ) ) ) <EOL> if migrate : <EOL> newSysArgv = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> else : <EOL> newSysArgv = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> oldSysArgv = sys . argv <EOL> newSysArgv . extend ( pkgl ) <EOL> newcfg . autoResolve = resolve <EOL> try : <EOL> if keepJournal : <EOL> k = { '<STR_LIT>' : True } <EOL> else : <EOL> k = { } <EOL> try : <EOL> sys . argv = newSysArgv <EOL> updatecmd . doUpdate ( newcfg , pkgl , <EOL> tagScript = tagScript , <EOL> keepExisting = keepExisting , <EOL> replaceManagedFiles = replaceManagedFiles , <EOL> replaceUnmanagedFiles = replaceUnmanagedFiles , <EOL> replaceModifiedFiles = replaceModifiedFiles , <EOL> replaceModifiedConfigFiles = replaceModifiedConfigFiles , <EOL> depCheck = depCheck , <EOL> justDatabase = justDatabase , <EOL> recurse = recurse , split = True , <EOL> sync = sync , info = info , <EOL> fromFiles = fromFiles , <EOL> checkPathConflicts = checkPathConflicts , <EOL> test = test , migrate = migrate , <EOL> keepRequired = keepRequired , <EOL> callback = callback , <EOL> restartInfo = restartInfo , <EOL> applyCriticalOnly = applyCriticalOnly , <EOL> syncChildren = syncChildren , <EOL> forceMigrate = migrate , <EOL> noRestart = noRestart , <EOL> exactFlavors = exactFlavors , <EOL> criticalUpdateInfo = criticalUpdateInfo , <EOL> skipCapsuleOps = skipCapsuleOps , <EOL> noScripts = noScripts , <EOL> systemModelFile = modelFile , <EOL> ** k ) <EOL> finally : <EOL> sys . argv = oldSysArgv <EOL> except conaryclient . DependencyFailure , msg : <EOL> if raiseError : <EOL> raise <EOL> print msg <EOL> except errors . InternalConaryError , err : <EOL> raise <EOL> except errors . ConaryError , msg : <EOL> if raiseError : <EOL> raise <EOL> log . error ( msg ) <EOL> else : <EOL> assert ( not info ) <EOL> assert ( not fromFiles ) <EOL> assert ( not test ) <EOL> assert ( checkPathConflicts ) <EOL> cl = conaryclient . ConaryClient ( self . cfg ) <EOL> cl . setUpdateCallback ( callback ) <EOL> job = [ ( x [ <NUM_LIT:0> ] , ( None , None ) , ( x [ <NUM_LIT:1> ] , x [ <NUM_LIT:2> ] ) , <EOL> not keepExisting ) for x in <EOL> pkg . getPrimaryTroveList ( ) ] <EOL> try : <EOL> try : <EOL> updJob , suggMap = cl . updateChangeSet ( job , <EOL> keepExisting = keepExisting , <EOL> keepRequired = keepRequired , <EOL> recurse = recurse , split = True , <EOL> sync = sync , <EOL> fromChangesets = [ pkg ] ) <EOL> if depCheck : <EOL> assert ( not suggMap ) <EOL> if replaceFiles is None : <EOL> replaceFiles = False <EOL> assert ( not replaceManagedFiles ) <EOL> assert ( not replaceUnmanagedFiles ) <EOL> assert ( not replaceModifiedFiles ) <EOL> assert ( not replaceModifiedConfigFiles ) <EOL> cl . applyUpdate ( updJob , replaceFiles = replaceFiles , <EOL> tagScript = tagScript , justDatabase = justDatabase , <EOL> keepJournal = keepJournal ) <EOL> finally : <EOL> updJob . close ( ) <EOL> cl . close ( ) <EOL> except conaryclient . DependencyFailure , msg : <EOL> if raiseError : <EOL> raise <EOL> print msg <EOL> except errors . InternalConaryError , err : <EOL> raise <EOL> except errors . ConaryError , err : <EOL> if raiseError : <EOL> raise <EOL> log . error ( err ) <EOL> def verifyDatabase ( self ) : <EOL> db = self . openDatabase ( ) <EOL> for info in list ( db . iterAllTroves ( ) ) : <EOL> assert db . getTrove ( * info ) . verifyDigests ( ) , "<STR_LIT>" <EOL> def updateAll ( self , ** kw ) : <EOL> updatecmd . updateAll ( self . cfg , ** kw ) <EOL> def localChangeset ( self , root , pkg , fileName ) : <EOL> db = database . Database ( root , self . cfg . dbPath ) <EOL> newcfg = copy . deepcopy ( self . cfg ) <EOL> newcfg . root = root <EOL> db = database . Database ( root , self . cfg . dbPath ) <EOL> newcfg = copy . deepcopy ( self . cfg ) <EOL> newcfg . root = root <EOL> verify . LocalChangeSetCommand ( db , newcfg , pkg , fileName ) <EOL> db . close ( ) <EOL> def changeset ( self , repos , troveSpecs , fileName , recurse = True ) : <EOL> cscmd . ChangeSetCommand ( self . cfg , troveSpecs , fileName , <EOL> recurse = recurse ) <EOL> def erasePkg ( self , root , pkg , version = None , tagScript = None , <EOL> depCheck = True , justDatabase = False , flavor = None , <EOL> test = False , recurse = True , callback = None , <EOL> skipCapsuleOps = False ) : <EOL> db = database . Database ( root , self . cfg . dbPath ) <EOL> try : <EOL> if type ( pkg ) == list : <EOL> sys . argv = [ '<STR_LIT>' , '<STR_LIT>' ] + pkg <EOL> updatecmd . doUpdate ( self . cfg , pkg , <EOL> tagScript = tagScript , depCheck = depCheck , <EOL> justDatabase = justDatabase , <EOL> updateByDefault = False , test = test , <EOL> recurse = recurse , callback = callback , <EOL> skipCapsuleOps = skipCapsuleOps ) <EOL> elif version and flavor : <EOL> item = "<STR_LIT>" % ( pkg , version , flavor ) <EOL> sys . argv = [ '<STR_LIT>' , '<STR_LIT>' , item ] <EOL> updatecmd . doUpdate ( self . cfg , [ item ] , <EOL> tagScript = tagScript , depCheck = depCheck , <EOL> justDatabase = justDatabase , <EOL> updateByDefault = False , test = test , <EOL> recurse = recurse , callback = callback , <EOL> skipCapsuleOps = skipCapsuleOps ) <EOL> elif version : <EOL> item = "<STR_LIT>" % ( pkg , version ) <EOL> sys . argv = [ '<STR_LIT>' , '<STR_LIT>' , item ] <EOL> updatecmd . doUpdate ( self . cfg , [ item ] , <EOL> tagScript = tagScript , depCheck = depCheck , <EOL> justDatabase = justDatabase , <EOL> updateByDefault = False , test = test , <EOL> recurse = recurse , callback = callback , <EOL> skipCapsuleOps = skipCapsuleOps ) <EOL> elif flavor : <EOL> item = "<STR_LIT>" % ( pkg , flavor ) <EOL> sys . argv = [ '<STR_LIT>' , '<STR_LIT>' , item ] <EOL> updatecmd . doUpdate ( self . cfg , [ item ] , <EOL> tagScript = tagScript , depCheck = depCheck , <EOL> justDatabase = justDatabase , <EOL> updateByDefault = False , test = test , <EOL> recurse = recurse , callback = callback , <EOL> skipCapsuleOps = skipCapsuleOps ) <EOL> else : <EOL> sys . argv = [ '<STR_LIT>' , '<STR_LIT>' , pkg ] <EOL> updatecmd . doUpdate ( self . cfg , [ pkg ] , <EOL> tagScript = tagScript , depCheck = depCheck , <EOL> justDatabase = justDatabase , <EOL> updateByDefault = False , test = test , <EOL> recurse = recurse , callback = callback , <EOL> skipCapsuleOps = skipCapsuleOps ) <EOL> except conaryclient . DependencyFailure , msg : <EOL> print msg <EOL> except errors . ClientError , msg : <EOL> log . error ( msg ) <EOL> db . close ( ) <EOL> def restoreTrove ( self , root , * troveList ) : <EOL> rmv = conarycmd . RestoreCommand ( ) <EOL> cfg = copy . copy ( self . cfg ) <EOL> cfg . root = root <EOL> return rmv . runCommand ( cfg , { } , ( '<STR_LIT>' , '<STR_LIT>' ) + troveList ) <EOL> def removeFile ( self , root , * pathList ) : <EOL> rmv = conarycmd . RemoveCommand ( ) <EOL> cfg = copy . copy ( self . cfg ) <EOL> cfg . root = root <EOL> return rmv . runCommand ( cfg , { } , ( '<STR_LIT>' , '<STR_LIT>' ) + pathList ) <EOL> def build ( self , str , name , vars = None , buildDict = None , <EOL> sourceVersion = None , serverIdx = <NUM_LIT:0> , logLevel = log . WARNING , <EOL> returnTrove = None , macros = None , prep = False ) : <EOL> ( built , d ) = self . buildRecipe ( str , name , d = buildDict , <EOL> vars = vars , <EOL> sourceVersion = sourceVersion , <EOL> logLevel = logLevel , macros = macros , <EOL> prep = prep ) <EOL> if prep : <EOL> return <EOL> ( name , version , flavor ) = built [ <NUM_LIT:0> ] <EOL> if returnTrove is None : <EOL> returnTroveList = [ name ] <EOL> else : <EOL> name = name . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] <EOL> if not isinstance ( returnTrove , ( list , tuple ) ) : <EOL> l = ( returnTrove , ) <EOL> else : <EOL> l = returnTrove <EOL> returnTroveList = [ ] <EOL> for compName in l : <EOL> if compName [ <NUM_LIT:0> ] == '<STR_LIT::>' : <EOL> returnTroveList . append ( name + compName ) <EOL> else : <EOL> returnTroveList . append ( compName ) <EOL> version = versions . VersionFromString ( version ) <EOL> repos = self . openRepository ( serverIdx ) <EOL> trvList = repos . getTroves ( <EOL> [ ( x , version , flavor ) for x in returnTroveList ] ) <EOL> if isinstance ( returnTrove , ( list , tuple ) ) : <EOL> return trvList <EOL> return trvList [ <NUM_LIT:0> ] <EOL> def buildRecipe ( self , theClass , theName , vars = None , prep = False , <EOL> macros = None , <EOL> sourceVersion = None , d = None , serverIdx = <NUM_LIT:0> , <EOL> logLevel = None , ignoreDeps = False , <EOL> logBuild = False , repos = None , groupOptions = None , <EOL> resume = None , branch = None ) : <EOL> use . setBuildFlagsFromFlavor ( theName , self . cfg . buildFlavor ) <EOL> if logLevel is None : <EOL> logLevel = log . WARNING <EOL> if vars is None : <EOL> vars = { } <EOL> if macros is None : <EOL> macros = { } <EOL> if branch is None : <EOL> if sourceVersion is not None : <EOL> branch = sourceVersion . branch ( ) <EOL> else : <EOL> branch = versions . Branch ( [ self . cfg . buildLabel ] ) <EOL> built = [ ] <EOL> if repos is None : <EOL> repos = self . openRepository ( ) <EOL> loader = LoaderFromString ( theClass , "<STR_LIT>" , cfg = self . cfg , <EOL> repos = repos , objDict = d , <EOL> component = theName ) <EOL> recipe = loader . getRecipe ( ) <EOL> for name in vars . iterkeys ( ) : <EOL> setattr ( recipe , name , vars [ name ] ) <EOL> level = log . getVerbosity ( ) <EOL> log . setVerbosity ( logLevel ) <EOL> built = self . cookObject ( loader , prep = prep , macros = macros , <EOL> sourceVersion = sourceVersion , <EOL> serverIdx = serverIdx , <EOL> ignoreDeps = ignoreDeps , <EOL> logBuild = logBuild , <EOL> repos = repos , groupOptions = groupOptions , <EOL> resume = resume ) <EOL> log . setVerbosity ( level ) <EOL> recipe = loader . getRecipe ( ) <EOL> del recipe . version <EOL> recipe . internalAbstractBaseClass = True <EOL> newD = { } <EOL> if d : <EOL> newD . update ( d ) <EOL> newD [ theName ] = recipe <EOL> return ( built , newD ) <EOL> def overrideBuildFlavor ( self , flavorStr ) : <EOL> flavor = deps . parseFlavor ( flavorStr ) <EOL> if flavor is None : <EOL> raise RuntimeError , '<STR_LIT>' % flavorStr <EOL> buildFlavor = self . cfg . buildFlavor . copy ( ) <EOL> if ( deps . DEP_CLASS_IS in flavor . getDepClasses ( ) and <EOL> deps . DEP_CLASS_IS in buildFlavor . getDepClasses ( ) ) : <EOL> del buildFlavor . members [ deps . DEP_CLASS_IS ] <EOL> buildFlavor . union ( flavor , <EOL> mergeType = deps . DEP_MERGE_TYPE_OVERRIDE ) <EOL> self . cfg . buildFlavor = buildFlavor <EOL> def pin ( self , troveName ) : <EOL> updatecmd . changePins ( self . cfg , [ troveName ] , True ) <EOL> def unpin ( self , troveName ) : <EOL> updatecmd . changePins ( self . cfg , [ troveName ] , False ) <EOL> def clone ( self , targetBranch , * troveSpecs , ** kw ) : <EOL> oldQuiet = self . cfg . quiet <EOL> if kw . pop ( '<STR_LIT>' , False ) : <EOL> self . cfg . quiet = False <EOL> else : <EOL> self . cfg . quiet = True <EOL> kw . setdefault ( '<STR_LIT>' , True ) <EOL> kw . setdefault ( '<STR_LIT:message>' , '<STR_LIT:foo>' ) <EOL> clone . CloneTrove ( self . cfg , targetBranch , troveSpecs , ** kw ) <EOL> cfgmod . quiet = oldQuiet <EOL> def promote ( self , * params , ** kw ) : <EOL> oldQuiet = self . cfg . quiet <EOL> if kw . pop ( '<STR_LIT>' , False ) : <EOL> self . cfg . quiet = False <EOL> else : <EOL> self . cfg . quiet = True <EOL> kw . setdefault ( '<STR_LIT:message>' , '<STR_LIT:foo>' ) <EOL> kw . setdefault ( '<STR_LIT>' , True ) <EOL> troveSpecs = [ ] <EOL> labelList = [ ] <EOL> for arg in params : <EOL> if '<STR_LIT>' in arg : <EOL> labelList . append ( arg . split ( '<STR_LIT>' , <NUM_LIT:1> ) ) <EOL> else : <EOL> troveSpecs . append ( arg ) <EOL> cs = clone . promoteTroves ( self . cfg , troveSpecs , labelList , ** kw ) <EOL> cfgmod . quiet = oldQuiet <EOL> return cs <EOL> def initializeFlavor ( self ) : <EOL> use . clearFlags ( ) <EOL> self . cfg . useDirs = [ resources . get_archive ( '<STR_LIT>' ) ] <EOL> self . cfg . archDirs = [ resources . get_archive ( '<STR_LIT>' ) ] <EOL> self . cfg . initializeFlavors ( ) <EOL> use . setBuildFlagsFromFlavor ( '<STR_LIT>' , self . cfg . buildFlavor , error = False ) <EOL> self . _origFlavor = use . allFlagsToFlavor ( '<STR_LIT>' ) <EOL> buildIs = use . Arch . getCurrentArch ( ) . _toDependency ( ) <EOL> self . buildIs = { '<STR_LIT>' : buildIs } <EOL> def checkConaryLog ( self , logText , rootDir = None , skipSections = <NUM_LIT:0> ) : <EOL> if rootDir is None : <EOL> rootDir = self . cfg . root <EOL> sections = [ ] <EOL> sectionNum = None <EOL> for line in open ( rootDir + os . path . sep + self . cfg . logFile [ <NUM_LIT:0> ] ) . xreadlines ( ) : <EOL> line = line [ line . index ( '<STR_LIT:]>' ) + <NUM_LIT:1> : ] . strip ( ) <EOL> if sectionNum is None : <EOL> assert ( line . startswith ( '<STR_LIT:version>' ) ) <EOL> line = line [ line . index ( '<STR_LIT::>' ) + <NUM_LIT:2> : ] <EOL> sectionNum = len ( sections ) <EOL> sections . append ( [ line ] ) <EOL> else : <EOL> sections [ sectionNum ] . append ( line ) <EOL> if "<STR_LIT>" in line : <EOL> sectionNum = None <EOL> sections = sections [ skipSections : ] <EOL> gotLog = "<STR_LIT>" . join ( "<STR_LIT:\n>" . join ( x ) + "<STR_LIT:\n>" for x in sections ) <EOL> assert ( gotLog == logText ) <EOL> def checkUpdate ( self , pkgList , expectedJob , depCheck = True , <EOL> keepExisting = False , recurse = True , <EOL> resolve = False , sync = False , replaceFiles = False , <EOL> exactMatch = True , apply = False , erase = False , <EOL> fromChangesets = [ ] , syncChildren = False , <EOL> updateOnly = False , resolveGroupList = [ ] , <EOL> syncUpdate = False , keepRequired = None , <EOL> migrate = False , removeNotByDefault = False , <EOL> oldMigrate = False , checkPrimaryPins = True , <EOL> client = None , resolveSource = None ) : <EOL> """<STR_LIT>""" <EOL> if client : <EOL> assert not resolve , "<STR_LIT>" <EOL> cl = client <EOL> else : <EOL> if resolve : <EOL> newcfg = copy . deepcopy ( self . cfg ) <EOL> newcfg . autoResolve = resolve <EOL> else : <EOL> newcfg = self . cfg <EOL> cl = conaryclient . ConaryClient ( newcfg ) <EOL> repos = self . openRepository ( ) <EOL> if oldMigrate : <EOL> syncUpdate = removeNotByDefault = True <EOL> installMissing = syncUpdate <EOL> areAbsolute = not keepExisting <EOL> if isinstance ( pkgList , str ) : <EOL> pkgList = [ pkgList ] <EOL> if isinstance ( expectedJob , str ) : <EOL> expectedJob = [ expectedJob ] <EOL> pkgList = list ( itertools . chain ( * ( util . braceExpand ( x ) for x in pkgList ) ) ) <EOL> applyList = cmdline . parseChangeList ( pkgList , keepExisting , <EOL> updateByDefault = not erase ) <EOL> updJob , suggMap = cl . updateChangeSet ( applyList , <EOL> keepExisting = keepExisting , <EOL> keepRequired = keepRequired , <EOL> recurse = recurse , split = True , sync = sync , <EOL> updateByDefault = not erase , <EOL> fromChangesets = fromChangesets , <EOL> resolveDeps = depCheck , syncChildren = syncChildren , <EOL> updateOnly = updateOnly , <EOL> resolveGroupList = resolveGroupList , <EOL> installMissing = installMissing , <EOL> removeNotByDefault = removeNotByDefault , <EOL> migrate = migrate , <EOL> checkPrimaryPins = checkPrimaryPins , <EOL> resolveSource = resolveSource ) <EOL> if depCheck : <EOL> assert ( not suggMap or resolve ) <EOL> expectedJob = list ( itertools . chain ( * ( util . braceExpand ( x ) for x in expectedJob ) ) ) <EOL> self . checkJobList ( updJob . getJobs ( ) , expectedJob , exactMatch ) <EOL> if apply : <EOL> cl . applyUpdate ( updJob , replaceFiles = replaceFiles ) <EOL> updJob . close ( ) <EOL> def checkLocalUpdates ( self , expectedJobs , troveNames = None , <EOL> exactMatch = True , getImplied = False ) : <EOL> """<STR_LIT>""" <EOL> repos = self . openRepository ( ) <EOL> cl = conaryclient . ConaryClient ( self . cfg ) <EOL> localUpdates = cl . getPrimaryLocalUpdates ( troveNames ) <EOL> if getImplied : <EOL> repos = self . openRepository ( ) <EOL> localUpdates += cl . getChildLocalUpdates ( repos , localUpdates ) <EOL> self . checkJobList ( [ localUpdates ] , expectedJobs , exactMatch ) <EOL> def checkJobList ( self , actualJob , expectedJob , exactMatch ) : <EOL> erases = trovesource . SimpleTroveSource ( ) <EOL> installs = trovesource . SimpleTroveSource ( ) <EOL> jobList = [ ] <EOL> for job in actualJob : <EOL> for ( n , oldInfo , newInfo , isAbs ) in job : <EOL> assert ( not isAbs ) <EOL> if oldInfo [ <NUM_LIT:0> ] : <EOL> erases . addTrove ( n , * oldInfo ) <EOL> if newInfo [ <NUM_LIT:0> ] : <EOL> installs . addTrove ( n , * newInfo ) <EOL> jobList . append ( ( n , oldInfo , newInfo ) ) <EOL> changeList = cmdline . parseChangeList ( expectedJob ) <EOL> for ( n , oldInfo , newInfo , isAbs ) , jobStr in zip ( changeList , expectedJob ) : <EOL> if oldInfo != ( None , None ) : <EOL> try : <EOL> troveList = erases . findTrove ( None , ( n , oldInfo [ <NUM_LIT:0> ] , oldInfo [ <NUM_LIT:1> ] ) ) <EOL> except errors . TroveNotFound : <EOL> relatedJobs = [ x for x in jobList if x [ <NUM_LIT:0> ] == n ] <EOL> if relatedJobs : <EOL> raise RuntimeError ( '<STR_LIT>' % ( jobStr , n , relatedJobs ) ) <EOL> else : <EOL> raise RuntimeError ( '<STR_LIT>' % ( n , jobList ) ) <EOL> if len ( troveList ) > <NUM_LIT:1> : <EOL> raise RuntimeError , ( <EOL> '<STR_LIT>' % ( n , oldInfo [ <NUM_LIT:0> ] , oldInfo [ <NUM_LIT:1> ] ) ) <EOL> oldVer , oldFla = troveList [ <NUM_LIT:0> ] [ <NUM_LIT:1> : ] <EOL> if newInfo != ( None , None ) or isAbs : <EOL> try : <EOL> troveList = installs . findTrove ( None , ( n , newInfo [ <NUM_LIT:0> ] , <EOL> newInfo [ <NUM_LIT:1> ] ) ) <EOL> except errors . TroveNotFound : <EOL> raise RuntimeError ( '<STR_LIT>' % ( jobStr , n , [ x for x in jobList if x [ <NUM_LIT:0> ] == n ] ) ) <EOL> if len ( troveList ) > <NUM_LIT:1> : <EOL> raise RuntimeError , ( <EOL> '<STR_LIT>' % ( n , newInfo [ <NUM_LIT:0> ] , newInfo [ <NUM_LIT:1> ] ) ) <EOL> newVer , newFla = troveList [ <NUM_LIT:0> ] [ <NUM_LIT:1> : ] <EOL> if oldInfo == ( None , None ) : <EOL> if isAbs : <EOL> jobToCheck = [ x for x in jobList if x [ <NUM_LIT:0> ] == n and x [ <NUM_LIT:2> ] == ( newVer , newFla ) ] <EOL> assert ( len ( jobToCheck ) == <NUM_LIT:1> ) <EOL> jobToCheck = jobToCheck [ <NUM_LIT:0> ] <EOL> else : <EOL> jobToCheck = ( n , ( None , None ) , ( newVer , newFla ) ) <EOL> elif newInfo == ( None , None ) : <EOL> jobToCheck = ( n , ( oldVer , oldFla ) , ( None , None ) ) <EOL> else : <EOL> jobToCheck = ( n , ( oldVer , oldFla ) , ( newVer , newFla ) ) <EOL> if jobToCheck in jobList : <EOL> jobList . remove ( jobToCheck ) <EOL> else : <EOL> raise RuntimeError ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( jobToCheck , <EOL> jobStr ) ) <EOL> if exactMatch and jobList : <EOL> raise RuntimeError , '<STR_LIT>' % ( jobList , ) <EOL> def getSearchSource ( self ) : <EOL> return searchsource . NetworkSearchSource ( self . openRepository ( ) , <EOL> self . cfg . installLabelPath , <EOL> self . cfg . flavor ) <EOL> def checkCall ( self , testFn , args , kw , fn , expectedArgs , <EOL> cfgValues = { } , returnVal = None , ignoreKeywords = False , <EOL> checkCallback = None , ** expectedKw ) : <EOL> methodCalled = [ False ] <EOL> def _placeHolder ( * args , ** kw ) : <EOL> """<STR_LIT>""" <EOL> methodCalled [ <NUM_LIT:0> ] = True <EOL> if checkCallback : <EOL> checkCallback ( * args , ** kw ) <EOL> self . assertEqual ( len ( args ) , len ( expectedArgs ) ) <EOL> for i , ( arg , expectedArg ) in enumerate ( zip ( args , expectedArgs ) ) : <EOL> if isinstance ( expectedArg , _NoneArg ) : <EOL> assert arg is None , "<STR_LIT>" % ( arg , i + <NUM_LIT:1> ) <EOL> elif expectedArg is None : <EOL> pass <EOL> elif ( inspect . isclass ( expectedArg ) <EOL> and isinstance ( arg , expectedArg ) ) : <EOL> pass <EOL> else : <EOL> assert arg == expectedArg , "<STR_LIT>" % ( repr ( arg ) , repr ( expectedArg ) ) <EOL> for key , expectedVal in expectedKw . iteritems ( ) : <EOL> val = kw . pop ( key ) <EOL> if isinstance ( expectedVal , _NoneArg ) : <EOL> assert val is None , "<STR_LIT>" % ( key , repr ( val ) ) <EOL> elif expectedVal is None : <EOL> pass <EOL> elif ( inspect . isclass ( expectedVal ) <EOL> and isinstance ( arg , expectedVal ) ) : <EOL> pass <EOL> else : <EOL> assert val == expectedVal , "<STR_LIT>" % ( key , repr ( val ) , repr ( expectedVal ) ) <EOL> if not ignoreKeywords : <EOL> assert not kw , "<STR_LIT:%s>" % repr ( kw ) <EOL> if not cfgValues : <EOL> return <EOL> found = False <EOL> for arg in args : <EOL> if isinstance ( arg , cfgmod . ConfigFile ) : <EOL> found = True <EOL> for cfgKey , cfgValue in cfgValues . iteritems ( ) : <EOL> assert arg [ cfgKey ] == cfgValue , "<STR_LIT>" % ( <EOL> cfgKey , repr ( arg [ cfgKey ] ) , repr ( cfgValue ) ) <EOL> break <EOL> assert ( found ) <EOL> if fn is not None : <EOL> fnModule , fnName = fn . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) <EOL> if fnModule in sys . modules : <EOL> origFn = sys . modules [ fnModule ] . __dict__ [ fnName ] <EOL> sys . modules [ fnModule ] . __dict__ [ fnName ] = _placeHolder <EOL> isClassMethod = False <EOL> else : <EOL> fnModule , className = fnModule . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) <EOL> isClassMethod = True <EOL> class_ = sys . modules [ fnModule ] . __dict__ [ className ] <EOL> origFn = getattr ( class_ , fnName ) <EOL> setattr ( class_ , <EOL> fnName , new . instancemethod ( _placeHolder , None , class_ ) ) <EOL> try : <EOL> rv = testFn ( * args , ** kw ) <EOL> if fn is not None : <EOL> assert ( methodCalled [ <NUM_LIT:0> ] ) <EOL> if returnVal is not None : <EOL> assert ( rv == returnVal ) <EOL> return rv <EOL> finally : <EOL> if fn is not None : <EOL> if isClassMethod : <EOL> setattr ( class_ , fnName , origFn ) <EOL> else : <EOL> sys . modules [ fnModule ] . __dict__ [ fnName ] = origFn <EOL> def checkCommand ( self , testFn , cmd , fn , expectedArgs , <EOL> cfgValues = { } , returnVal = None , ignoreKeywords = False , <EOL> checkCallback = None , <EOL> ** expectedKw ) : <EOL> """<STR_LIT>""" <EOL> level = log . getVerbosity ( ) <EOL> argv = shlex . split ( cmd ) <EOL> try : <EOL> return self . checkCall ( testFn , [ argv ] , { } , fn , expectedArgs , <EOL> cfgValues = cfgValues , returnVal = returnVal , <EOL> ignoreKeywords = ignoreKeywords , <EOL> checkCallback = checkCallback , ** expectedKw ) <EOL> finally : <EOL> log . setVerbosity ( level ) <EOL> def findAndGetTroves ( self , * troveSpecs , ** kw ) : <EOL> repos = kw . pop ( '<STR_LIT>' , None ) <EOL> if not repos : <EOL> repos = self . openRepository ( ) <EOL> troveSpecs = [ cmdline . parseTroveSpec ( x ) for x in troveSpecs ] <EOL> results = repos . findTroves ( self . cfg . installLabelPath , <EOL> troveSpecs , self . cfg . flavor ) <EOL> troveTupList = list ( itertools . chain ( * results . values ( ) ) ) <EOL> troves = repos . getTroves ( troveTupList , ** kw ) <EOL> troves = dict ( itertools . izip ( troveTupList , troves ) ) <EOL> finalResult = [ ] <EOL> for troveSpec in troveSpecs : <EOL> assert ( len ( results [ troveSpec ] ) == <NUM_LIT:1> ) <EOL> finalResult . append ( troves [ results [ troveSpec ] [ <NUM_LIT:0> ] ] ) <EOL> return finalResult <EOL> def findAndGetTrove ( self , troveSpec , ** kw ) : <EOL> return self . findAndGetTroves ( troveSpec , ** kw ) [ <NUM_LIT:0> ] <EOL> def setTroveVersion ( self , val ) : <EOL> trove . TROVE_VERSION = val <EOL> trove . TROVE_VERSION_1_1 = val <EOL> def loadRecipe ( self , name , flavor , init = False ) : <EOL> repos = self . openRepository ( ) <EOL> oldBuildFlavor = self . cfg . buildFlavor <EOL> self . overrideBuildFlavor ( flavor ) <EOL> use . setBuildFlagsFromFlavor ( name , self . cfg . buildFlavor ) <EOL> use . Arch . _getMacro ( '<STR_LIT>' ) <EOL> loader = loadrecipe . recipeLoaderFromSourceComponent ( name , self . cfg , <EOL> repos , <EOL> buildFlavor = self . cfg . buildFlavor ) [ <NUM_LIT:0> ] <EOL> recipeClass = loader . getRecipe ( ) <EOL> if init : <EOL> return recipeClass ( self . cfg , None , [ ] ) <EOL> self . cfg . buildFlavor = oldBuildFlavor <EOL> return recipeClass <EOL> def getConaryProxy ( self , idx = <NUM_LIT:0> , <EOL> proxies = None , <EOL> entitlements = ( ) , <EOL> users = ( ) , <EOL> singleWorker = False , <EOL> useSSL = False , <EOL> cacheTimeout = None , <EOL> cacheLocation = None , <EOL> ) : <EOL> cProxyDir = os . path . join ( self . tmpDir , "<STR_LIT>" ) <EOL> if idx : <EOL> cProxyDir += "<STR_LIT>" % str ( idx ) <EOL> util . rmtree ( cProxyDir , ignore_errors = True ) <EOL> configValues = dict ( <EOL> authCacheTimeout = cacheTimeout , <EOL> entitlement = [ '<STR_LIT:U+0020>' . join ( x ) for x in entitlements ] , <EOL> memCache = cacheLocation , <EOL> memCacheTimeout = ( <NUM_LIT> if cacheLocation else - <NUM_LIT:1> ) , <EOL> user = [ '<STR_LIT:U+0020>' . join ( x ) for x in users ] , <EOL> ) <EOL> configValues . update ( self . _reformatProxies ( proxies ) ) <EOL> return ProxyServer ( cProxyDir , <EOL> withCache = True , <EOL> singleWorker = singleWorker , <EOL> sslCertAndKey = useSSL , <EOL> configValues = configValues , <EOL> ) <EOL> def getHTTPProxy ( self , idx = <NUM_LIT:0> , path = None ) : <EOL> if path : <EOL> cProxyDir = path <EOL> else : <EOL> cProxyDir = os . path . join ( self . tmpDir , "<STR_LIT>" ) <EOL> if idx : <EOL> cProxyDir += "<STR_LIT>" % str ( idx ) <EOL> h = HTTPProxy ( cProxyDir ) <EOL> if h . start ( ) : <EOL> return h <EOL> else : <EOL> raise testhelp . SkipTestException ( "<STR_LIT>" ) <EOL> def assertSubstringIn ( self , val , target ) : <EOL> matches = [ val in x for x in target ] <EOL> self . assertTrue ( matches , "<STR_LIT>" % ( <EOL> safe_repr ( val ) , safe_repr ( target ) ) ) <EOL> @ staticmethod <EOL> def sleep ( length ) : <EOL> '<STR_LIT>' <EOL> start = time . time ( ) <EOL> now = start <EOL> while now < start + length : <EOL> time . sleep ( length - ( now - start ) ) <EOL> now = time . time ( ) <EOL> @ staticmethod <EOL> def trimRecipe ( recipe ) : <EOL> '''<STR_LIT>''' <EOL> minWhitespace = None <EOL> pattern = re . compile ( '<STR_LIT>' ) <EOL> for line in recipe . splitlines ( ) : <EOL> match = pattern . match ( line ) <EOL> if match : <EOL> whitespace = len ( match . group ( <NUM_LIT:1> ) ) <EOL> if minWhitespace is None or whitespace < minWhitespace : <EOL> minWhitespace = whitespace <EOL> if minWhitespace is None : <EOL> return recipe <EOL> ret = '<STR_LIT>' <EOL> for line in recipe . splitlines ( ) : <EOL> ret += line [ minWhitespace : ] + '<STR_LIT:\n>' <EOL> return ret <EOL> class HTTPProxy ( base_server . BaseServer ) : <EOL> """<STR_LIT>""" <EOL> proxyBinPath = "<STR_LIT>" <EOL> configTemplate = """<STR_LIT>""" <EOL> def __init__ ( self , topdir ) : <EOL> self . topdir = topdir <EOL> self . cacheDir = os . path . join ( topdir , "<STR_LIT>" ) <EOL> self . accessLog = os . path . join ( topdir , "<STR_LIT>" ) <EOL> self . cacheLog = os . path . join ( topdir , "<STR_LIT>" ) <EOL> self . storeLog = os . path . join ( topdir , "<STR_LIT>" ) <EOL> self . pidFile = os . path . join ( topdir , "<STR_LIT>" ) <EOL> self . configFile = os . path . join ( topdir , "<STR_LIT>" ) <EOL> self . authPasswdFile = os . path . join ( topdir , "<STR_LIT>" ) <EOL> self . stopped = True <EOL> self . pid = None <EOL> def updateConfig ( self , cfg , auth = False ) : <EOL> port = ( auth and self . authPort ) or self . port <EOL> cfg . proxy = { '<STR_LIT:http>' : '<STR_LIT>' % port , <EOL> '<STR_LIT>' : '<STR_LIT>' % port , <EOL> } <EOL> def start ( self ) : <EOL> if not os . path . exists ( self . proxyBinPath ) : <EOL> return None <EOL> self . port , self . authPort = testhelp . findPorts ( num = <NUM_LIT:2> ) <EOL> self . writeConfigFile ( ) <EOL> stdout = open ( os . devnull , "<STR_LIT>" ) <EOL> stderr = open ( os . devnull , "<STR_LIT>" ) <EOL> p = subprocess . Popen ( self . getStopCmd ( ) , stdout = stderr , stderr = stderr ) <EOL> ret = p . wait ( ) <EOL> p = subprocess . Popen ( self . getInitCmd ( ) , stdout = stderr , stderr = stderr ) <EOL> ret = p . wait ( ) <EOL> if ret != <NUM_LIT:0> : <EOL> raise Exception ( "<STR_LIT>" % <EOL> ( self . configFile , ret ) ) <EOL> p = subprocess . Popen ( self . getStartCmd ( ) , stdout = stderr , stderr = stderr ) <EOL> ret = p . wait ( ) <EOL> if ret != <NUM_LIT:0> : <EOL> raise Exception ( "<STR_LIT>" % <EOL> ( self . configFile , ret ) ) <EOL> sock_utils . tryConnect ( "<STR_LIT:127.0.0.1>" , self . port ) <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> if os . path . exists ( self . pidFile ) : <EOL> break <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> else : <EOL> time . sleep ( <NUM_LIT:2> ) <EOL> self . pid = int ( open ( self . pidFile ) . readline ( ) . strip ( ) ) <EOL> self . stopped = False <EOL> proxyUri = "<STR_LIT>" % self . port <EOL> return proxyUri <EOL> def getStartCmd ( self ) : <EOL> return self . getBaseCmd ( ) <EOL> def getInitCmd ( self ) : <EOL> return self . getBaseCmd ( ) + [ '<STR_LIT>' ] <EOL> def getStopCmd ( self ) : <EOL> return self . getBaseCmd ( ) + [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def getBaseCmd ( self ) : <EOL> return [ self . proxyBinPath , '<STR_LIT>' , '<STR_LIT>' , self . configFile ] <EOL> def writeConfigFile ( self ) : <EOL> util . mkdirChain ( os . path . dirname ( self . configFile ) ) <EOL> acls = self . getAcls ( ) <EOL> from distutils import sysconfig <EOL> libdir = sysconfig . get_config_vars ( ) [ '<STR_LIT>' ] <EOL> for name in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> authprog = os . path . join ( libdir , '<STR_LIT>' , name ) <EOL> if os . path . exists ( authprog ) : <EOL> break <EOL> else : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> opts = dict ( port = self . port , authPort = self . authPort , <EOL> cacheDir = self . cacheDir , <EOL> accessLog = self . accessLog , storeLog = self . storeLog , <EOL> cacheLog = self . cacheLog , pidFile = self . pidFile , <EOL> passwdFile = self . authPasswdFile , <EOL> acls = "<STR_LIT:\n>" . join ( acls ) , <EOL> libdir = libdir , <EOL> user = os_utils . effectiveUser , <EOL> group = os_utils . effectiveGroup , <EOL> authprog = authprog , <EOL> ) <EOL> open ( self . configFile , "<STR_LIT>" ) . write ( self . configTemplate % opts ) <EOL> open ( self . authPasswdFile , "<STR_LIT:w>" ) . write ( "<STR_LIT>" ) <EOL> def getAcls ( self ) : <EOL> return [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> def stop ( self ) : <EOL> if self . stopped : <EOL> return <EOL> stdout = open ( os . devnull , "<STR_LIT>" ) <EOL> stderr = open ( os . devnull , "<STR_LIT>" ) <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> p = subprocess . Popen ( self . getStopCmd ( ) , stdout = stdout , stderr = stderr ) <EOL> ret = p . wait ( ) <EOL> if ret == <NUM_LIT:0> : <EOL> break <EOL> time . sleep ( <NUM_LIT> ) <EOL> if ret != <NUM_LIT:0> : <EOL> sys . stderr . write ( "<STR_LIT>" % <EOL> ( self . configFile , ret ) ) <EOL> sys . stderr . write ( "<STR_LIT>" % self . pid ) <EOL> try : <EOL> os . kill ( self . pid , <NUM_LIT:15> ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> os . kill ( self . pid , <NUM_LIT:9> ) <EOL> except OSError , e : <EOL> if e . errno != <NUM_LIT:3> : <EOL> raise <EOL> if os . path . exists ( self . pidFile ) : <EOL> os . unlink ( self . pidFile ) <EOL> self . stopped = True <EOL> def getFileSize ( self , fname ) : <EOL> st = os . stat ( fname ) <EOL> if not st : <EOL> return <NUM_LIT:0> <EOL> return st [ stat . ST_SIZE ] <EOL> def getAccessLogSize ( self ) : <EOL> return self . getFileSize ( self . accessLog ) <EOL> def getAccessLogEntry ( self , start ) : <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> end = self . getAccessLogSize ( ) <EOL> if end != start : <EOL> break <EOL> time . sleep ( <NUM_LIT> ) <EOL> f = open ( self . accessLog ) <EOL> f . seek ( start ) <EOL> line = f . read ( end - start ) <EOL> f . close ( ) <EOL> return line . split ( ) <EOL> def isStarted ( self ) : <EOL> return not self . stopped <EOL> class HTTPServerController ( base_server . BaseServer ) : <EOL> def __init__ ( self , requestHandler , ssl = False ) : <EOL> self . port = testhelp . findPorts ( num = <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> self . ssl = ssl <EOL> self . childPid = os . fork ( ) <EOL> if self . childPid > <NUM_LIT:0> : <EOL> sock_utils . tryConnect ( "<STR_LIT:127.0.0.1>" , self . port ) <EOL> return <EOL> try : <EOL> try : <EOL> if ssl : <EOL> klass = SecureHTTPServer <EOL> ctx = SSL . Context ( "<STR_LIT>" ) <EOL> if isinstance ( ssl , tuple ) : <EOL> sslCert , sslKey = ssl <EOL> else : <EOL> sslCert , sslKey = '<STR_LIT>' , '<STR_LIT>' <EOL> sslCert = os . path . join ( resources . get_archive ( sslCert ) ) <EOL> sslKey = os . path . join ( resources . get_archive ( sslKey ) ) <EOL> ctx . load_cert_chain ( sslCert , sslKey ) <EOL> args = ( ctx , ) <EOL> else : <EOL> klass = BaseHTTPServer . HTTPServer <EOL> args = ( ) <EOL> klass . address_family = socket . AF_INET6 <EOL> httpServer = klass ( ( '<STR_LIT>' , self . port ) , requestHandler , * args ) <EOL> httpServer . serve_forever ( ) <EOL> os . _exit ( <NUM_LIT:0> ) <EOL> except : <EOL> traceback . print_exc ( ) <EOL> finally : <EOL> os . _exit ( <NUM_LIT:1> ) <EOL> def kill ( self ) : <EOL> if not self . childPid : <EOL> self . childPid = None <EOL> return <EOL> if os . environ . get ( '<STR_LIT>' , None ) : <EOL> sendsig = signal . SIGUSR2 <EOL> else : <EOL> sendsig = signal . SIGTERM <EOL> start = time . time ( ) <EOL> while True : <EOL> now = time . time ( ) <EOL> if now - start > <NUM_LIT:15> : <EOL> break <EOL> os . kill ( self . childPid , sendsig ) <EOL> try : <EOL> pid = os . waitpid ( self . childPid , os . WNOHANG ) [ <NUM_LIT:0> ] <EOL> except OSError , err : <EOL> if err . errno == errno . EINTR : <EOL> continue <EOL> elif err . errno == errno . ECHILD : <EOL> self . childPid = None <EOL> return <EOL> else : <EOL> raise <EOL> else : <EOL> if pid : <EOL> self . childPid = None <EOL> return <EOL> time . sleep ( <NUM_LIT:2> ) <EOL> os . kill ( self . childPid , signal . SIGKILL ) <EOL> os . waitpid ( self . childPid , <NUM_LIT:0> ) <EOL> self . childPid = None <EOL> stop = close = kill <EOL> def url ( self ) : <EOL> if self . ssl : <EOL> s = '<STR_LIT:s>' <EOL> else : <EOL> s = '<STR_LIT>' <EOL> return "<STR_LIT>" % ( s , self . port ) <EOL> def isStarted ( self ) : <EOL> return self . childPid not in ( None , <NUM_LIT:0> ) <EOL> def _cleanUp ( ) : <EOL> global _proxy <EOL> if _proxy : <EOL> _proxy . stop ( ) <EOL> util . rmtree ( _proxy . reposDir , ignore_errors = True ) <EOL> _proxy = None <EOL> _servers . cleanup ( ) <EOL> atexit . register ( _cleanUp ) <EOL> def getOpenFiles ( ) : <EOL> procdir = "<STR_LIT>" <EOL> fdlist = os . listdir ( procdir ) <EOL> fdlist = ( ( x , os . path . join ( procdir , x ) ) for x in fdlist ) <EOL> fdlist = set ( ( x [ <NUM_LIT:0> ] , os . readlink ( x [ <NUM_LIT:1> ] ) ) for x in fdlist <EOL> if os . path . exists ( x [ <NUM_LIT:1> ] ) ) <EOL> return fdlist <EOL> notCleanedUpWarning = True </s>
