#
# BusyB, an automated build utility.
#
# Copyright (C) 1997-2003
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
import time
import os
from busybee.BusyBException import BusyBException
from busybee.BuildStatusRecord import BuildStatusRecord
from busybee.HTMLWriter import HTMLWriter
from busybee.IncrementalFile import IncrementalFile
from busybee.LogSweeper import LogSweeper
from busybee.LogIndexCompiler import LogIndexCompiler
from busybee.LogDirManager import *
from busybee import SymbolManager
from busybee.Util import *
from Description import Description
from LogDir import LogDir
from KeepLogs import KeepLogs
from Base import Base
class Project(Base):
def __init__(self):
Base.__init__(self)
self.description = Description("Project")
self.count = 1
self.logDir = LogDir()
self.debug = 0
self.nLogsKeep = KeepLogs()
def setKeepLogs(self, n):
self.nLogsKeep = n
def setDebug(self):
self.debug = 1
def setLogDir(self, logDir):
self.logDir = logDir
def setTrigger(self, t ):
self.trigger = t
def setBuild(self, b):
self.build = b
def process( self ):
logger = self.openMainLogFile()
self.setLogger( logger )
logger.writeln()
logger.timeStamp( "New BusyB project build started." )
SymbolManager.getInstance().setSymbol( "LogDir", self.logDir.getAbsPath() )
self.build.setLogger(logger)
self.trigger.setLogger(logger)
self.preProcess()
self.trigger.process()
self.postProcess()
def openMainLogFile(self):
logPath = os.path.join( self.logDir.getAbsPath(), "log.html" )
if os.path.exists( logPath ):
logger = HTMLWriter( IncrementalFile(logPath))
else:
logger = HTMLWriter( IncrementalFile(logPath), self.getDescription().getText())
return logger
def invoke( self, reason ):
logger = self.getLogger()
timeStamp = time.localtime()
desc = self.getDescription().getText()
buildDirName = buildName(timeStamp)
buildDirPath = os.path.join( self.logDir.getAbsPath(), buildDirName )
os.mkdir(buildDirPath)
SymbolManager.getInstance().setSymbol( "BuildDir", buildDirPath)
SymbolManager.getInstance().setSymbol( "BuildStarted", formatTime(timeStamp))
buildLogFile = os.path.join( buildDirPath, "index.html" )
buildLog = HTMLWriter(open(buildLogFile, "w"), self.build.getDescription().getText() )
buildLog.rule()
buildLog.timeStamp( "Build triggered by: " + str(reason) )
record = BuildStatusRecord(desc, timeStamp, "OK")
try:
try:
self.build.setLogger(buildLog)
self.build.setLogDir(buildDirPath)
self.build.process()
logger.timeStamp( " OK" )
except BusyBException, e:
logger.writeln()
logger.timeStamp( "Build failed: " + str(e) )
record.status = str(e)
finally:
record.dump( os.path.join( buildDirPath, 'status.dat' ))
buildLog.close()
LogSweeper(self.logDir, self.nLogsKeep.getN()).sweep()
LogIndexCompiler(self.logDir, self.getDescription().getText()).compile()
self.count = self.count + 1
|