Пример #1
0
	def run( self ):
		"""Executes the shell command. Needs a command to be set.

		\return 0 if minimum score is met, otherwise 1"""

		cmd = [ self._getPyLintChecker().getCommand() ]
		paths = self._getPyLintChecker().getCommandSearchPaths()

		args = [ ]
		if self._getPyLintChecker().getPyLintRcFile():
			args.append( '--rcfile={0}'.format( self._getPyLintChecker().getPyLintRcFile() ) )

		# Check if the source and output path exist, since this action will be executed even if there was an error before (since 
		# the source code can be checked even if, for example, a unit test failed)
		targetPath = os.path.dirname( str( self._getPyLintChecker().getHtmlOutputPath() ) )
		if not os.path.isdir( targetPath ) \
			or not os.path.isdir( str( self.getWorkingDirectory() ) ):
			self._getPyLintChecker().setReport( 'not executed because of previous failures' )
			return 0
		# First, run PyLint with parseable output, and retrieve the score and comment:
		parseableCommand = cmd + [ '--output-format=parseable' ] + args + self._getPyLintChecker().getModules()
		runner1 = RunCommand( parseableCommand, 1800, searchPaths = paths )
		runner1.run()
		if runner1.getReturnCode() >= 32:
			mApp().debugN( self, 2, 'error running pylint to produce the parseable report' )
			return 1

		# parse output
		self._getPyLintChecker().parsePyLintOutput( runner1.getStdOut() )

		# Second step, run pylint again, to produce the full HTML report:
		if self._getPyLintChecker().getHtmlOutputPath():
			htmlCommand = cmd + [ '--output-format=html' ] + args + self._getPyLintChecker().getModules()
			runner2 = RunCommand( htmlCommand )
			runner2.run()
			if runner2.getReturnCode() >= 32:
				mApp().debugN( self, 2, 'error running pylint to generate the HTML report' )
				return 1
			path = str( self._getPyLintChecker().getHtmlOutputPath() )
			try:
				with open( path, 'w' ) as file:
					file.write( runner2.getStdOut() )
				mApp().debugN( self, 2, 'pylint html report is at "{0}"'.format( path ) )
			except IOError as e:
				mApp().debug( self, 'ERROR saving pylint html report to "{0}": {1}'.format( path, e ) )
				return 1

		return ( 0 if self._getPyLintChecker().isScoreOkay() else 1 )
Пример #2
0
	def _retrieveRevisionInfo( self ):
		# check if specified revision is in cache. do not check for 'HEAD'
		if self.getRevision() in self.__revisionInfoCache:
			return self.__revisionInfoCache[self.getRevision()]

		info = RevisionInfo( "SvnRevisionInfo" )

		revisionParameter = ['-r', str( self.getRevision() )] if self.getRevision() else []
		cmd = [ self.getCommand(), '--non-interactive', 'log', '--xml', '--limit', '1', self.getUrl() ] + revisionParameter
		runner = RunCommand( cmd, searchPaths = self.getCommandSearchPaths() )
		runner.run()

		if runner.getReturnCode() == 0:
			xmldoc = minidom.parseString( runner.getStdOut().encode( "utf-8" ) )
			logentries = xmldoc.getElementsByTagName( 'logentry' )
			assert len( logentries ) == 1
			results = parse_log_entry( logentries[0] )
			( info.committerName, info.commitMessage, info.revision, info.commitTime, info.commitTimeReadable ) = results
			info.shortRevision = info.revision

			if self.getSCMUidMapper():
				email = self.getSCMUidMapper().getEmail( info.committerName )
				mApp().debugN( self, 5, "E-Mail address for {0} from SCM uid mapper: {1}".format( info.committerName, email ) )
				info.committerEmail = email

		# add to cache. do not add 'HEAD'
		if self.getRevision():
			self.__revisionInfoCache[self.getRevision()] = info

		return info
Пример #3
0
	def __getSummarizedDiffForRevision( self, url, revision ):
		previous = revision - 1
		cmd = [ self.getCommand(), 'diff', '--summarize', '-r', str( previous ) + ':' + str( revision ), url ]
		runner = RunCommand( cmd, 3600, searchPaths = self.getCommandSearchPaths() )
		runner.run()
		if runner.getReturnCode() != 0:
			# maybe the location did not exist earlier on: 
			mApp().debugN( self, 2, 'cannot retrieve summarized diff for revision "{0}"'.format( revision ) )
			return None
		else:
			return runner.getStdOut().encode( "utf-8" ).split( '\n' )
Пример #4
0
	def __getCurrentRevisionOfUrl( self, url ):
		cmd = [ self.getCommand(), '--non-interactive', 'log', '--xml', '--limit', '1', url ]
		runner = RunCommand( cmd, searchPaths = self.getCommandSearchPaths() )
		runner.run()

		if runner.getReturnCode() == 0:
			xmldoc = minidom.parseString( runner.getStdOut().encode( "utf-8" ) )
			logentries = xmldoc.getElementsByTagName( 'logentry' )
			assert len( logentries ) == 1
			result = parse_log_entry( logentries[0] )
			return result[2]
		else:
			raise ConfigurationError( 'cannot get log for "{0}"'.format( url ) )
Пример #5
0
	def __getXmlSvnLog( self, url, revision, cap ):
		cmd = [ self.getCommand(), '--non-interactive', 'log', '--xml' ]
		if revision == 0:
			cmd.extend( ['--limit', '1' ] )
		cmd.extend( ['-rHEAD:{0}'.format( str( revision ).strip() ), url ] )
		runner = RunCommand( cmd, 3600, searchPaths = self.getCommandSearchPaths() )
		runner.run()
		if runner.getReturnCode() == 0:
			return minidom.parseString( runner.getStdOut().encode( "utf-8" ) )
		elif runner.getTimedOut() == True:
			raise ConfigurationError( 'Getting svn log for "{0}" timed out.'.format( self.getUrl() ) )
		else:
			msg = runner.getStdErrAsString().strip()
			raise ConfigurationError( 'Getting svn log failed: "{0}"'.format( msg ) )
Пример #6
0
	def queryRevisionsSince( self, revision ):
		'''Execute the build script, and return the lines it outputs for "query revisions-since"'''

		cmd = [ sys.executable, self.getBuildScript(), 'print', 'revisions-since', str( revision ) ] + self.getParameters()
		runner = RunCommand( cmd, 1800 )
		runner.run()
		if runner.getReturnCode() != 0:
			msg = 'Cannot get revision list for build script "{0}", continuing with next project.'\
				.format( self.getBuildScript() )
			raise MomError( msg )

		output = runner.getStdOut()
		if not output:
			return []

		lines = output.decode().split( '\n' )
		return lines