<s> """<STR_LIT>""" <EOL> import os <EOL> import stat <EOL> from conary . cmds import branch <EOL> from conary import checkin <EOL> from conary import state <EOL> from conary . conaryclient import cmdline <EOL> from conary . lib import log , util <EOL> from conary . versions import Label <EOL> from conary . repository . changeset import ChangesetExploder <EOL> class DeriveCallback ( checkin . CheckinCallback ) : <EOL> def setUpdateJob ( self , * args , ** kw ) : <EOL> pass <EOL> def derive ( repos , cfg , targetLabel , troveSpec , checkoutDir = None , <EOL> extract = False , info = False , callback = None ) : <EOL> """<STR_LIT>""" <EOL> origDir = os . getcwd ( ) <EOL> try : <EOL> if callback is None : <EOL> callback = DeriveCallback ( ) <EOL> if isinstance ( troveSpec , tuple ) : <EOL> troveName , versionSpec , flavor = troveSpec <EOL> versionSpec = str ( versionSpec ) <EOL> troveSpec = cmdline . toTroveSpec ( troveName , versionSpec , flavor ) <EOL> else : <EOL> troveName , versionSpec , flavor = cmdline . parseTroveSpec ( troveSpec ) <EOL> if isinstance ( targetLabel , str ) : <EOL> targetLabel = Label ( targetLabel ) <EOL> troveName , versionSpec , flavor = cmdline . parseTroveSpec ( troveSpec ) <EOL> result = repos . findTrove ( cfg . buildLabel , <EOL> ( troveName , versionSpec , flavor ) , <EOL> cfg . flavor ) <EOL> troveToDerive , = result <EOL> log . info ( '<STR_LIT>' % ( troveToDerive [ <NUM_LIT:0> ] , <EOL> troveToDerive [ <NUM_LIT:1> ] , <EOL> troveToDerive [ <NUM_LIT:2> ] , <EOL> targetLabel ) ) <EOL> if info : <EOL> cfg . interactive = False <EOL> error = branch . branch ( repos , cfg , str ( targetLabel ) , <EOL> [ '<STR_LIT>' % troveToDerive ] , <EOL> makeShadow = True , sourceOnly = True , <EOL> binaryOnly = False , allowEmptyShadow = True , <EOL> info = info ) <EOL> if info or error : <EOL> return <EOL> shadowedVersion = troveToDerive [ <NUM_LIT:1> ] . createShadow ( targetLabel ) <EOL> shadowedVersion = shadowedVersion . getSourceVersion ( False ) <EOL> troveName = troveName . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] <EOL> checkoutDir = checkoutDir or troveName <EOL> checkin . checkout ( repos , cfg , checkoutDir , <EOL> [ "<STR_LIT>" % ( troveName , shadowedVersion ) ] , <EOL> callback = callback ) <EOL> os . chdir ( checkoutDir ) <EOL> nvfs = repos . getTrovesBySource ( troveToDerive [ <NUM_LIT:0> ] + '<STR_LIT>' , <EOL> troveToDerive [ <NUM_LIT:1> ] . getSourceVersion ( ) ) <EOL> trvs = repos . getTroves ( nvfs ) <EOL> hasCapsule = [ x for x in trvs if x . troveInfo . capsule . type ( ) ] <EOL> if hasCapsule : <EOL> derivedRecipeType = '<STR_LIT>' <EOL> removeText = '<STR_LIT>' <EOL> else : <EOL> derivedRecipeType = '<STR_LIT>' <EOL> removeText = """<STR_LIT>""" <EOL> log . info ( '<STR_LIT>' ) <EOL> recipeName = troveName + '<STR_LIT>' <EOL> className = util . convertPackageNameToClassName ( troveName ) <EOL> derivedRecipe = """<STR_LIT>""" % dict ( className = className , <EOL> name = troveName , <EOL> version = shadowedVersion . trailingRevision ( ) . getVersion ( ) , <EOL> recipeBaseClass = derivedRecipeType , <EOL> removeText = removeText ) <EOL> open ( recipeName , '<STR_LIT:w>' ) . write ( derivedRecipe ) <EOL> log . info ( '<STR_LIT>' ) <EOL> conaryState = state . ConaryStateFromFile ( '<STR_LIT>' , repos ) <EOL> sourceState = conaryState . getSourceState ( ) <EOL> sourceState . setFactory ( '<STR_LIT>' ) <EOL> addRecipe = True <EOL> for ( pathId , path , fileId , version ) in list ( sourceState . iterFileList ( ) ) : <EOL> if path == recipeName : <EOL> addRecipe = False <EOL> continue <EOL> sourceState . removeFile ( pathId ) <EOL> if util . exists ( path ) : <EOL> statInfo = os . lstat ( path ) <EOL> try : <EOL> if statInfo . st_mode & stat . S_IFDIR : <EOL> os . rmdir ( path ) <EOL> else : <EOL> os . unlink ( path ) <EOL> except OSError , e : <EOL> log . warning ( "<STR_LIT>" % ( path , e . strerror ) ) <EOL> conaryState . write ( '<STR_LIT>' ) <EOL> if addRecipe : <EOL> checkin . addFiles ( [ recipeName ] ) <EOL> if extract : <EOL> log . info ( '<STR_LIT>' % ( troveToDerive ) ) <EOL> extractDir = os . path . join ( os . getcwd ( ) , '<STR_LIT>' ) <EOL> ts = [ ( troveToDerive [ <NUM_LIT:0> ] , ( None , None ) , <EOL> ( troveToDerive [ <NUM_LIT:1> ] , troveToDerive [ <NUM_LIT:2> ] ) , True ) ] <EOL> cs = repos . createChangeSet ( ts , recurse = True ) <EOL> ChangesetExploder ( cs , extractDir ) <EOL> secondDir = os . path . join ( os . getcwd ( ) , '<STR_LIT>' ) <EOL> cs = repos . createChangeSet ( ts , recurse = True ) <EOL> ChangesetExploder ( cs , secondDir ) <EOL> finally : <EOL> os . chdir ( origDir ) </s>
