<s> import sys , os , shutil , time , glob <EOL> import subprocess <EOL> import tempfile <EOL> import tarfile <EOL> from StringIO import StringIO <EOL> import warnings <EOL> from twisted . python import usage , log , versions , deprecate <EOL> initFileData = '''<STR_LIT>''' <EOL> specFileData = '''<STR_LIT>''' <EOL> class MyOptions ( usage . Options ) : <EOL> optFlags = [ [ '<STR_LIT>' , '<STR_LIT:q>' ] ] <EOL> optParameters = [ <EOL> [ "<STR_LIT>" , "<STR_LIT:t>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT:m>" , "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT:p>" , None ] , <EOL> [ "<STR_LIT:description>" , "<STR_LIT:e>" , None ] , <EOL> [ "<STR_LIT>" , "<STR_LIT:l>" , <EOL> "<STR_LIT>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:1.0>" ] , <EOL> [ "<STR_LIT>" , "<STR_LIT:r>" , None ] , <EOL> [ "<STR_LIT:type>" , "<STR_LIT:y>" , "<STR_LIT>" , "<STR_LIT>" <EOL> "<STR_LIT>" ] , <EOL> ] <EOL> compData = usage . Completions ( <EOL> optActions = { "<STR_LIT:type>" : usage . CompleteList ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:source>" , <EOL> "<STR_LIT>" ] ) , <EOL> "<STR_LIT>" : usage . CompleteFiles ( "<STR_LIT>" ) } <EOL> ) <EOL> def postOptions ( self ) : <EOL> """<STR_LIT>""" <EOL> if self [ '<STR_LIT>' ] is None : <EOL> base_tapfile = os . path . basename ( self [ '<STR_LIT>' ] ) <EOL> self [ '<STR_LIT>' ] = os . path . splitext ( base_tapfile ) [ <NUM_LIT:0> ] <EOL> if self [ '<STR_LIT:description>' ] is None : <EOL> self [ '<STR_LIT:description>' ] = "<STR_LIT>" % ( self [ '<STR_LIT>' ] , ) <EOL> if self [ '<STR_LIT>' ] is None : <EOL> self [ '<STR_LIT>' ] = '<STR_LIT>' % ( self [ '<STR_LIT>' ] , ) <EOL> self [ '<STR_LIT>' ] = type_dict [ self [ '<STR_LIT:type>' ] ] <EOL> self [ '<STR_LIT>' ] = '<STR_LIT>' % ( self [ '<STR_LIT>' ] , self [ '<STR_LIT>' ] ) <EOL> def opt_unsigned ( self ) : <EOL> """<STR_LIT>""" <EOL> msg = deprecate . getDeprecationWarningString ( <EOL> self . opt_unsigned , versions . Version ( "<STR_LIT>" , <NUM_LIT:12> , <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> warnings . warn ( msg , category = DeprecationWarning , stacklevel = <NUM_LIT:2> ) <EOL> opt_u = opt_unsigned <EOL> type_dict = { <EOL> '<STR_LIT>' : '<STR_LIT:file>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:source>' : '<STR_LIT:source>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def makeBuildDir ( ) : <EOL> """<STR_LIT>""" <EOL> tmpDir = tempfile . mkdtemp ( ) <EOL> os . makedirs ( os . path . join ( tmpDir , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> os . makedirs ( os . path . join ( tmpDir , '<STR_LIT>' ) ) <EOL> os . makedirs ( os . path . join ( tmpDir , '<STR_LIT>' ) ) <EOL> os . makedirs ( os . path . join ( tmpDir , '<STR_LIT>' ) ) <EOL> os . makedirs ( os . path . join ( tmpDir , '<STR_LIT>' ) ) <EOL> log . msg ( format = "<STR_LIT>" , <EOL> path = tmpDir ) <EOL> return tmpDir <EOL> def setupBuildFiles ( buildDir , config ) : <EOL> """<STR_LIT>""" <EOL> tarballName = "<STR_LIT>" % ( config [ '<STR_LIT>' ] , ) <EOL> tarballPath = os . path . join ( buildDir , "<STR_LIT>" , tarballName ) <EOL> tarballHandle = tarfile . open ( tarballPath , "<STR_LIT:w>" ) <EOL> sourceDirInfo = tarfile . TarInfo ( config [ '<STR_LIT>' ] ) <EOL> sourceDirInfo . type = tarfile . DIRTYPE <EOL> sourceDirInfo . mode = <NUM_LIT:0> <NUM_LIT> <EOL> tarballHandle . addfile ( sourceDirInfo ) <EOL> tapFileBase = os . path . basename ( config [ '<STR_LIT>' ] ) <EOL> initFileInfo = tarfile . TarInfo ( <EOL> os . path . join ( <EOL> config [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' % config [ '<STR_LIT>' ] , <EOL> ) <EOL> ) <EOL> initFileInfo . type = tarfile . REGTYPE <EOL> initFileInfo . mode = <NUM_LIT:0> <NUM_LIT> <EOL> initFileRealData = initFileData % { <EOL> '<STR_LIT>' : tapFileBase , <EOL> '<STR_LIT>' : config [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : config [ '<STR_LIT>' ] , <EOL> } <EOL> initFileInfo . size = len ( initFileRealData ) <EOL> tarballHandle . addfile ( initFileInfo , StringIO ( initFileRealData ) ) <EOL> tapFileHandle = open ( config [ '<STR_LIT>' ] , '<STR_LIT:rb>' ) <EOL> tapFileInfo = tarballHandle . gettarinfo ( <EOL> arcname = os . path . join ( config [ '<STR_LIT>' ] , tapFileBase ) , <EOL> fileobj = tapFileHandle , <EOL> ) <EOL> tapFileInfo . mode = <NUM_LIT:0> <NUM_LIT> <EOL> tarballHandle . addfile ( tapFileInfo , tapFileHandle ) <EOL> tarballHandle . close ( ) <EOL> log . msg ( format = "<STR_LIT>" , <EOL> tarballPath = tarballPath ) <EOL> specName = "<STR_LIT>" % ( config [ '<STR_LIT>' ] , ) <EOL> specPath = os . path . join ( buildDir , "<STR_LIT>" , specName ) <EOL> specHandle = open ( specPath , "<STR_LIT:w>" ) <EOL> specFileRealData = specFileData % { <EOL> '<STR_LIT:description>' : config [ '<STR_LIT:description>' ] , <EOL> '<STR_LIT>' : config [ '<STR_LIT>' ] , <EOL> '<STR_LIT:version>' : config [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : tarballName , <EOL> '<STR_LIT>' : tapFileBase , <EOL> '<STR_LIT:date>' : time . strftime ( '<STR_LIT>' , time . localtime ( time . time ( ) ) ) , <EOL> '<STR_LIT>' : config [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : config [ '<STR_LIT>' ] , <EOL> } <EOL> specHandle . write ( specFileRealData ) <EOL> specHandle . close ( ) <EOL> log . msg ( format = "<STR_LIT>" , <EOL> specPath = specPath ) <EOL> return specPath <EOL> def run ( options = None ) : <EOL> try : <EOL> config = MyOptions ( ) <EOL> config . parseOptions ( options ) <EOL> except usage . error , ue : <EOL> sys . exit ( "<STR_LIT>" % ( sys . argv [ <NUM_LIT:0> ] , ue ) ) <EOL> tmpDir = makeBuildDir ( ) <EOL> specPath = setupBuildFiles ( tmpDir , config ) <EOL> job = subprocess . Popen ( [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" % ( tmpDir , ) , <EOL> "<STR_LIT>" , specPath , <EOL> ] , stdout = subprocess . PIPE , stderr = subprocess . STDOUT ) <EOL> stdout , _ = job . communicate ( ) <EOL> if job . returncode != <NUM_LIT:0> : <EOL> print stdout <EOL> rpmPath = glob . glob ( os . path . join ( tmpDir , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:*>' ) ) [ <NUM_LIT:0> ] <EOL> srpmPath = glob . glob ( os . path . join ( tmpDir , '<STR_LIT>' , '<STR_LIT:*>' ) ) [ <NUM_LIT:0> ] <EOL> if not config [ '<STR_LIT>' ] : <EOL> print '<STR_LIT>' % os . path . basename ( rpmPath ) <EOL> shutil . copy ( rpmPath , '<STR_LIT:.>' ) <EOL> if not config [ '<STR_LIT>' ] : <EOL> print '<STR_LIT>' % os . path . basename ( srpmPath ) <EOL> shutil . copy ( srpmPath , '<STR_LIT:.>' ) <EOL> shutil . rmtree ( tmpDir ) <EOL> return [ os . path . basename ( rpmPath ) , os . path . basename ( srpmPath ) ] </s>
