Beispiel #1
0
 def run(self):
     check_for_path(self.getPath(), "No directory specified!")
     mApp().debugN(self, 2, 'deleting directory "{0}"'.format(self.getPath()))
     try:
         rmtree(str(self.getPath()))
         return 0
     except (OSError, IOError) as e:
         error = 'error deleting directory "{0}": {1}'.format(self.getPath(), str(e))
         self._setStdErr(error.encode())
         mApp().debug(self, error)
         return 1
Beispiel #2
0
	def tearDown( self ):
		MomTestCase.tearDown( self )

		# make sure config content stayed the same
		if self.DatabaseChecksum:
			self.assertEqual( self.DatabaseChecksum, md5sum( self._getSimpleCiDatabaseFilename() ),
					"Database changed during tests run." )

		os.chdir( self.CurrentDirectory )
		removeDirectories = glob.glob( "make-o-matic*" )
		removeDirectories.extend( glob.glob( "builds" ) )
		removeDirectories.append( self._getSimpleCiDataDir( SimpleCITests.TestInstanceName ) )
		for directory in removeDirectories:
			rmtree( directory )
Beispiel #3
0
	def setup( self ):
		mode = mApp().getSettings().get( Settings.ScriptRunMode )
		if mode == Settings.RunMode_Build:
			baseDir = self.getBaseDir()
			if os.path.isdir( baseDir ):
				moveOldDirectories = mApp().getSettings().get( Settings.BuildMoveOldDirectories )
				if moveOldDirectories:
					mApp().debug( self, 'stale base directory exists, moving it.' )
					stats = os.stat( baseDir )
					mtime = time.localtime( stats[8] )
					extension = time.strftime( "%Y-%m-%d-%H-%M-%S", mtime )
					newFolderBaseName = '{0}-{1}'.format( baseDir, extension )
					newFolder = newFolderBaseName
					maxIterations = 1000
					for index in range( maxIterations ):
						if not os.path.isdir( newFolder ):
							break
						newFolder = newFolderBaseName + '__{0}'.format( index + 1 )
					if os.path.isdir( newFolder ):
						raise MomError( "{0} old build directories exist, this can't be happening :-(".format( maxIterations ) )
					try:
						shutil.move( baseDir, newFolder )
					except ( OSError, shutil.Error ) as o:
						raise ConfigurationError( 'Cannot move existing build folder at "{0}" to "{1}": {2}'
							.format( baseDir, newFolder, str( o ) ) )
					mApp().debugN( self, 2, 'moved to "{0}".'.format( newFolder ) )
				else:
					try:
						rmtree( baseDir )
					except ( OSError, shutil.Error ) as o:
						raise ConfigurationError( 'Cannot remove existing build folder at "{0}": {1}'
							.format( baseDir, str( o ) ) )
			try:
				os.makedirs( baseDir )
			except ( OSError, IOError ) as e:
				raise ConfigurationError( 'Cannot create required base directory "{0}" for {1}: {2}!'
										.format( baseDir, self.getName(), e ) )
			os.chdir( baseDir )
			try:
				os.makedirs( self.getLogDir() )
			except ( OSError, IOError )as e:
				raise ConfigurationError( 'Cannot create build log directory "{0}" for {1}: {2}!'
					.format( self.getLogDir(), self.getName(), e ) )
			try:
				os.makedirs( self.getPackagesDir() )
			except ( OSError, IOError )as e:
				raise ConfigurationError( 'Cannot create build packages directory "{0}" for {1}: {2}!'
					.format( self.getLogDir(), self.getName(), e ) )
		super( Build, self ).setup()
	def tearDown( self ):
		MomTestCase.tearDown( self )
		rmtree( "make-o-matic" )
Beispiel #5
0
	def performBuild( self, buildInfo ):
		"""Start a build process for a new revision. baseDir is the directory where all builds go. To build 
		different revisions and build types under it, subdirectories have to be used."""
		buildType = buildInfo.getBuildType().lower()
		# Under windows we have the problem that paths need to be short, so take only 7 digists of the git hash
		# this is also done for svn revision numbers, but these should not be so long
		if sys.platform == 'win32':
			rev = buildInfo.getRevision()[0:7]
		else:
			rev = buildInfo.getRevision()
		name = make_foldername_from_string( buildInfo.getProjectName() )
		# find suitable names for the different build dirs:
		baseDir = os.path.join( os.getcwd(), 'builds' )
		buildRoot = mApp().getSettings().get( Settings.SimpleCIBuildDirectory, required = False ) or baseDir
		subfolder = make_foldername_from_string( rev )
		directory = os.path.normpath( os.path.join( buildRoot, name, buildType, subfolder ) )
		# prepare build directory:
		if os.path.isdir( directory ):
			mApp().debug( self, 'found remainders of a previous build, nuking it...' )
			try:
				rmtree( directory )
				mApp().debug( self, '...that was good!' )
			except ( OSError, IOError ) as e:
				raise ConfigurationError( 'Remnants of a previous build exist at "{0}" and cannot be deleted, bad. Reason: {1}.'
					.format( directory, e ) )
		try:
			os.makedirs( directory )
		except ( OSError, IOError )as e:
			raise ConfigurationError( 'Cannot create required build directory "{0}"!'.format( directory ) )
		mApp().message( self, 'starting build job for project "{0}" at revision {1}.'
					.format( buildInfo.getProjectName(), rev ) )
		with EnvironmentSaver():
			os.chdir( directory )
			extend_debug_prefix( buildInfo.getProjectName() )
			iface = BuildScriptInterface( os.path.abspath( buildInfo.getBuildScript() ) )
			runner = iface.executeBuildInfo( buildInfo )
			try:
				with open( 'buildscript.log', 'w' ) as f:
					text = runner.getStdOutAsString()
					f.write( text.decode() )
			except Exception as e:
				mApp().message( self, 'Problem! saving the build script output failed during handling an exception! {0}'
					.format( e ) )
			if runner.getReturnCode() != 0:
				mApp().message( self, 'build failed for project "{0}" at revision {1}'.format( buildInfo.getProjectName(), rev ) )
				# FIXME send out email reports on configuration or MOM errors
				mApp().message( self, 'exit code {0}'.format( runner.getReturnCode() ) )
				print( """\
-->   ____        _ _     _   _____     _ _          _ 
-->  | __ ) _   _(_) | __| | |  ___|_ _(_) | ___  __| |
-->  |  _ \| | | | | |/ _` | | |_ / _` | | |/ _ \/ _` |
-->  | |_) | |_| | | | (_| | |  _| (_| | | |  __/ (_| |
-->  |____/ \__,_|_|_|\__,_| |_|  \__,_|_|_|\___|\__,_|
--> 
""" )
				return False
			else:
				mApp().message( self, 'build succeeded for project "{0}" at revision {1}'.format( buildInfo.getProjectName(), rev ) )
				print( """\
-->   _         _ _    _      _
-->  | |__ _  _(_) |__| |  __| |___ _ _  ___
-->  | '_ \ || | | / _` | / _` / _ \ ' \/ -_)
-->  |_.__/\_,_|_|_\__,_| \__,_\___/_||_\___|
--> 
""" )
				return True
	def tearDown( self ):
		MomTestCase.tearDown( self )
		removeDirectories = glob.glob( "make-o-matic*" )
		for directory in removeDirectories:
			rmtree( directory )
	def tearDown( self ):
		MomTestCase.tearDown( self )
		os.chdir( self.cwd )
		rmtree( "xmlreporttestbuild" )