From: Anton V. Yanchenko Date: Wed, 30 May 2012 12:06:50 +0000 (+0400) Subject: fixed error in Job.is_running in case when there is no any builds of this job X-Git-Tag: v0.2.23~293^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5624dc62ec59319d1e422c386f850184c016847c;p=tools%2Fpython-jenkinsapi.git fixed error in Job.is_running in case when there is no any builds of this job --- diff --git a/jenkinsapi/job.py b/jenkinsapi/job.py index 210bab8..8a8fa20 100644 --- a/jenkinsapi/job.py +++ b/jenkinsapi/job.py @@ -146,11 +146,19 @@ class Job(JenkinsBase): def get_last_build( self ): """ - Get the last good build + Get the last build """ bn = self.get_last_buildnumber() return self.get_build( bn ) + def get_last_build_or_none(self): + """ + Get the last build or None if there is no builds + """ + bn = self.get_last_buildnumber() + if bn is not None: + return self.get_build(bn) + def get_last_completed_build( self ): """ Get the last build regardless of status @@ -192,10 +200,12 @@ class Job(JenkinsBase): def is_running(self): self.poll() try: - return self.get_last_build().is_running() + build = self.get_last_build_or_none() + if build is not None: + return build.is_running() except NoBuildData: log.info("No build info available for %s, assuming not running." % str(self) ) - return False + return False def get_config(self): '''Returns the config.xml from the job'''