In bootstrap, little beautifying of socInstaller.py.
This commit is contained in:
parent
1e21651e1e
commit
c9db432c48
|
@ -124,23 +124,42 @@ class Command ( object ):
|
||||||
print '[WARNING] Command.__init__(): <fdLog> is neither None or a file.'
|
print '[WARNING] Command.__init__(): <fdLog> is neither None or a file.'
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def _argumentsToStr ( self, arguments ):
|
||||||
|
s = ''
|
||||||
|
for argument in arguments:
|
||||||
|
if argument.find(' ') >= 0: s += ' "' + argument + '"'
|
||||||
|
else: s += ' ' + argument
|
||||||
|
return s
|
||||||
|
|
||||||
|
def log ( self, text ):
|
||||||
|
print text[:-1]
|
||||||
|
sys.stdout.flush()
|
||||||
|
sys.stderr.flush()
|
||||||
|
if isinstance(self.fdLog,file):
|
||||||
|
self.fdLog.write( text )
|
||||||
|
self.fdLog.flush()
|
||||||
|
return
|
||||||
|
|
||||||
def execute ( self ):
|
def execute ( self ):
|
||||||
|
global conf
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
|
homeDir = os.environ['HOME']
|
||||||
|
workDir = os.getcwd()
|
||||||
|
if homeDir.startswith(homeDir):
|
||||||
|
workDir = '~' + workDir[ len(homeDir) : ]
|
||||||
|
prompt = '%s@%s:%s$' % (os.environ['USER'],conf.masterHost,workDir)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
self.log( '%s%s\n' % (prompt,self._argumentsToStr(self.arguments)) )
|
||||||
child = subprocess.Popen( self.arguments, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
|
child = subprocess.Popen( self.arguments, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
line = child.stdout.readline()
|
line = child.stdout.readline()
|
||||||
if not line: break
|
if not line: break
|
||||||
|
|
||||||
print line[:-1]
|
self.log( line )
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
if isinstance(self.fdLog,file):
|
|
||||||
self.fdLog.write( line )
|
|
||||||
self.fdLog.flush()
|
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
raise BadBinary( self.arguments[0] )
|
raise BadBinary( self.arguments[0] )
|
||||||
|
|
||||||
|
@ -161,10 +180,11 @@ class GitRepository ( object ):
|
||||||
localRepo = localRepo[:-4]
|
localRepo = localRepo[:-4]
|
||||||
return localRepo
|
return localRepo
|
||||||
|
|
||||||
def __init__ ( self, url, cloneDir ):
|
def __init__ ( self, url, cloneDir, fdLog=None ):
|
||||||
self.url = url
|
self.url = url
|
||||||
self.cloneDir = cloneDir
|
self.cloneDir = cloneDir
|
||||||
self.localRepo = GitRepository.getLocalRepository( url )
|
self.localRepo = GitRepository.getLocalRepository( url )
|
||||||
|
self.fdLog = fdLog
|
||||||
return
|
return
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -177,20 +197,21 @@ class GitRepository ( object ):
|
||||||
return
|
return
|
||||||
|
|
||||||
def clone ( self ):
|
def clone ( self ):
|
||||||
|
print 'Clone/pull from:', self.url
|
||||||
if not os.path.isdir(self.cloneDir):
|
if not os.path.isdir(self.cloneDir):
|
||||||
os.makedirs( self.cloneDir )
|
os.makedirs( self.cloneDir )
|
||||||
|
|
||||||
if not os.path.isdir(self.localRepoDir):
|
if not os.path.isdir(self.localRepoDir):
|
||||||
os.chdir( self.cloneDir )
|
os.chdir( self.cloneDir )
|
||||||
Command( [ 'git', 'clone', self.url ] ).execute()
|
Command( [ 'git', 'clone', self.url ], self.fdLog ).execute()
|
||||||
else:
|
else:
|
||||||
os.chdir( self.localRepoDir )
|
os.chdir( self.localRepoDir )
|
||||||
Command( [ 'git', 'pull' ] ).execute()
|
Command( [ 'git', 'pull' ], self.fdLog ).execute()
|
||||||
return
|
return
|
||||||
|
|
||||||
def checkout ( self, branch ):
|
def checkout ( self, branch ):
|
||||||
os.chdir( self.localRepoDir )
|
os.chdir( self.localRepoDir )
|
||||||
Command( [ 'git', 'checkout', branch ] ).execute()
|
Command( [ 'git', 'checkout', branch ], self.fdLog ).execute()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@ -366,7 +387,10 @@ class Report ( object ):
|
||||||
fd.close()
|
fd.close()
|
||||||
self.mainText += ' <%s>\n' % logFile
|
self.mainText += ' <%s>\n' % logFile
|
||||||
|
|
||||||
self.attachements.append( MIMEApplication(tailLines) )
|
attachement = MIMEApplication(tailLines)
|
||||||
|
attachement.add_header( 'Content-Disposition', 'attachment', filename=os.path.basename(logFile) )
|
||||||
|
|
||||||
|
self.attachements.append( attachement )
|
||||||
return
|
return
|
||||||
|
|
||||||
def send ( self ):
|
def send ( self ):
|
||||||
|
@ -413,9 +437,9 @@ try:
|
||||||
gitSupports = []
|
gitSupports = []
|
||||||
for supportRepo in conf.supportRepos:
|
for supportRepo in conf.supportRepos:
|
||||||
gitSupports.append( GitRepository( supportRepo, conf.srcDir+'/support' ) )
|
gitSupports.append( GitRepository( supportRepo, conf.srcDir+'/support' ) )
|
||||||
gitCoriolis = GitRepository( conf.coriolisRepo, conf.srcDir )
|
gitCoriolis = GitRepository( conf.coriolisRepo, conf.srcDir, conf.fds['build'] )
|
||||||
gitChams = GitRepository( conf.chamsRepo , conf.srcDir )
|
gitChams = GitRepository( conf.chamsRepo , conf.srcDir, conf.fds['build'] )
|
||||||
gitBenchs = GitRepository( conf.benchsRepo , conf.srcDir )
|
gitBenchs = GitRepository( conf.benchsRepo , conf.srcDir, conf.fds['build'] )
|
||||||
|
|
||||||
if conf.doGit:
|
if conf.doGit:
|
||||||
for gitSupport in gitSupports:
|
for gitSupport in gitSupports:
|
||||||
|
|
Loading…
Reference in New Issue