Example #1
0
	def _checkMinimumMomVersion( self, minimumMomVersion ):
		'''Check if this make-o-matic copy is recent enough for this build script.

		If not, the function does not return, but instead exits the script with an error Message.'''

		if not minimumMomVersion:
			self.debug( self, 'No minimum make-o-matic version specified.' )
			return
		try:
			check_for_nonempty_string( minimumMomVersion, 'minimumMomVersion needs to be a version string like "0.5.5"' )
			minVersion = minimumMomVersion.split( '.' )
			version = self.getMomVersion().split( '.' )
			if len( version ) != 3 or len( minVersion ) != len( version ) :
				raise MomError( 'Version descriptions must be strings of 3 integer numbers, like "0.5.5"' )
			for position in range( len( version ) ):
				try:
					element = int( version[position] )
					minElement = int( minVersion[position] )
					if element < minElement:
						raise MomError( 'This build script requires make-o-matic ' + minimumMomVersion
											 + ', but this is only make-o-matic ' + self.getMomVersion() + ', aborting.' )
				except ValueError:
					raise MomError( 'Version descriptions must be strings of integer numbers, like "0.5.5"' )
		except MomException as  e:
			self.message( self, e.value )
			sys.exit( 1 )
Example #2
0
	def getBuildType( self ):
		buildType = self._getOptions().buildType
		if buildType:
			check_for_nonempty_string( buildType, 'The build type must be a single character!' )
			if len( buildType ) != 1:
				raise ConfigurationError( 'The build type must be a single character, not "{0}"'.format( buildType ) )
			buildType = buildType.lower()
		return buildType
Example #3
0
	def get( self, name, required = True, defaultValue = None ):
		check_for_nonempty_string( name, 'The setting name must be a nonempty string!' )
		try:
			return self.getSettings()[ name ]
		except KeyError:
			if required:
				raise ConfigurationError( 'The required setting "{0}" is undefined!'.format( name ) )
			else:
				return defaultValue
Example #4
0
	def getBuildStepEnabled( self, stepName, buildType ):
		'''Return whether a build step is enabled for a specified build type in the settings.'''
		check_for_nonempty_string( stepName, 'The step name needs to be a non-empty string!' )
		buildStepDescriptions = self.get( Settings.ProjectBuildSequence )
		for buildStepDescription in buildStepDescriptions:
			if buildStepDescription[0] == stepName:
				modes = buildStepDescription[1]
				return buildType in modes
		raise ConfigurationError( 'The specified build type "{0}" is undefined!'.format( buildType ) )
Example #5
0
	def addStep( self, newStep ):
		"""Add a newStep identified by identifier. If the identifier already exists, the new 
		command replaces the old one."""
		if not isinstance( newStep, Step ):
			raise MomError( 'only Step instances can be added to the queue' )
		check_for_nonempty_string( newStep.getName(), "Every step must have a name!" )
		if self.__hasStep( newStep.getName() ):
			raise MomError( 'A step with the name {0} already exists for this Instructions object!'.format( newStep.getName() ) )
		self.__steps.append( newStep )
Example #6
0
	def setBuildStepEnabled( self, stepName, buildType, yesNo ):
		'''Enable or disable the specified build step, for the specified build type, in the defaults.
		This method needs to be called before the Instructions object set up the build sequence (e.g., before 
		Instructions.setup() is called.'''
		check_for_nonempty_string( stepName, 'The step name needs to be a non-empty string!' )
		buildStepDescriptions = self.get( Settings.ProjectBuildSequence )
		for buildStepDescription in buildStepDescriptions:
			if buildStepDescription[0] == stepName:
				modes = buildStepDescription[1]
				modes = filter( lambda c: c not in buildType, modes )
				if yesNo:
					modes += buildType
				buildStepDescription[1] = modes
				mApp().debugN( self, 2, 'build step {0} is now enabled for the following build types: {1}'.format( stepName, modes ) )
				return
		raise ConfigurationError( 'The specified build type "{0}" is undefined!'.format( buildType ) )
Example #7
0
def getPathFromRegistry( key ):
	check_for_nonempty_string( key, "The registry key needs to be a non-empty string" )

	hkeystring, _, key = key.partition( os.path.sep )
	key, _, value = key.rpartition( os.path.sep )

	if hkeystring == "HKEY_CURRENT_USER":
		hkey = winreg.HKEY_CURRENT_USER #@UndefinedVariable
	elif hkeystring == "HKEY_LOCAL_MACHINE":
		hkey = winreg.HKEY_LOCAL_MACHINE #@UndefinedVariable
	else:
		raise ConfigurationError( "getPathFromRegistry currently only supports "
								 "HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE but "
								 "you requested {0}".format( hkeystring ) )
	try:
		with winreg.OpenKey( hkey, key ) as registrykey: #@UndefinedVariable
			registryvalue, _ = winreg.QueryValueEx( registrykey, value ) #@UndefinedVariable
			return str( registryvalue )
	except WindowsError: #@UndefinedVariable
		return None
Example #8
0
	def execute( self, instructions ):
		"""Execute the step"""
		check_for_nonempty_string( self.getName(), "Cannot execute a step with no name!" )
		self.setStatus( Step.Status.Started )
		if not self.isEnabled():
			self.setStatus( Step.Status.Skipped_Disabled )
			return True

		# (usually) abort if another step has failed for this Instructions object:
		if not instructions._stepsShouldExecute() and not self.getExecuteOnFailure():
			self.setStatus( Step.Status.Skipped_PreviousError )
			return True

		with self.getTimeKeeper():
			self._logEnvironment( instructions )

			logfileName = '{0}.log'.format( make_foldername_from_string( self.getName() ) )
			logfilePath = os.path.join( instructions.getLogDir(), logfileName )
			self.setLogfilePath( logfilePath )
			self.setResult( Step.Result.Success )

			# execute each action associated to this step
			for phase, actions in self._getPhases():
				if not actions:
					mApp().debugN( self, 3, 'phase "{0}" is empty (no actions registered)'.format( phase ) )
					continue

				mApp().debugN( self, 3, 'phase "{0}" has {1} actions registered, starting execution'.format( phase, len( actions ) ) )
				for action in actions:
					resultText = 'skipped'
					if self.getResult() != Step.Result.Failure or action.getIgnorePreviousFailure():
						result = action.executeAction( self.getLogfilePath() )
						resultText = 'successful' if result == 0 else 'failed'
						if result != 0:
							self.setResult( Step.Result.Failure )
					else:
						self.setStatus( Step.Status.Skipped_PreviousError )
					mApp().debugN( self, 3, '{0}: "{1}" {2}'.format( phase, action.getLogDescription(), resultText ) )
			self.setStatus( Step.Status.Finished )
			return self.getResult() != Step.Result.Failure
Example #9
0
	def _setVersionParameter( self, versionParameter ):
		check_for_nonempty_string( versionParameter, 'The make tool version parameter must be a non-empty string.' )
		self.__versionParameter = versionParameter
Example #10
0
	def _setCommand( self, command ):
		check_for_nonempty_string( command, 'The make tool command must be a non-empty string' )
		self.__command = command
Example #11
0
	def set( self, name, value ):
		check_for_nonempty_string( name, 'The setting name must be a nonempty string!' )
		self.getSettings()[ name ] = value
Example #12
0
	def _setCommand( self, command ):
		check_for_nonempty_string( command, "The command needs to be a non-empty string." )
		self.__command = command
Example #13
0
	def getBaseDir( self ):
		check_for_nonempty_string( self.__baseDir, 'basedir can only be queried after preFlightCheck!' )
		return self.__baseDir