From: Salim Fadhley Date: Fri, 31 May 2013 23:11:33 +0000 (+0100) Subject: New datetime behavior for builds as requested. X-Git-Tag: v0.2.23~235 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c933eea973d48d220e635882f02afa2eaedea399;p=tools%2Fpython-jenkinsapi.git New datetime behavior for builds as requested. --- diff --git a/jenkinsapi/build.py b/jenkinsapi/build.py index 74e0df9..6a94095 100644 --- a/jenkinsapi/build.py +++ b/jenkinsapi/build.py @@ -1,10 +1,12 @@ +import time import urlparse import urllib2 +import datetime from jenkinsapi.artifact import Artifact from jenkinsapi import config from jenkinsapi.jenkinsbase import JenkinsBase -from jenkinsapi.exceptions import NoResults, FailedNoResults -from jenkinsapi.constants import STATUS_FAIL, STATUS_ABORTED, RESULTSTATUS_FAILURE, STATUS_SUCCESS +from jenkinsapi.exceptions import NoResults +from jenkinsapi.constants import STATUS_SUCCESS from jenkinsapi.result_set import ResultSet from time import sleep @@ -261,7 +263,8 @@ class Build(JenkinsBase): return all_actions def get_timestamp(self): - return self._data['timestamp'] + # Java timestamps are given in miliseconds since the epoch start! + return datetime.datetime(*time.localtime(self._data['timestamp']/1000.0)[:6]) def stop(self): """ diff --git a/jenkinsapi/jenkinsbase.py b/jenkinsapi/jenkinsbase.py index 0e67644..18137f8 100644 --- a/jenkinsapi/jenkinsbase.py +++ b/jenkinsapi/jenkinsbase.py @@ -72,8 +72,7 @@ class JenkinsBase(object): except urllib2.HTTPError, e: if e.code == 404: raise - log.warn("Error reading %s" % url) - log.exception(e) + log.exception("Error reading %s" % url) raise return result @@ -81,9 +80,8 @@ class JenkinsBase(object): try: urlopen = self.get_jenkins_obj().get_opener() result = urlopen(url, data=content).read().strip() - except urllib2.HTTPError, e: - log.warn("Error post data %s" % url) - log.exception(e) + except urllib2.HTTPError: + log.exception("Error post data %s" % url) raise return result @@ -93,8 +91,7 @@ class JenkinsBase(object): if params: stream = fn_urlopen( url, urllib.urlencode(params) ) else: stream = fn_urlopen( url ) html_result = stream.read() - except urllib2.HTTPError, e: - log.debug( "Error reading %s" % url ) - log.exception(e) + except urllib2.HTTPError: + log.exception("Error reading %s" % url) raise return html_result diff --git a/jenkinsapi_tests/unittests/test_build.py b/jenkinsapi_tests/unittests/test_build.py index 980698c..9b37837 100644 --- a/jenkinsapi_tests/unittests/test_build.py +++ b/jenkinsapi_tests/unittests/test_build.py @@ -27,7 +27,7 @@ class TestTimestamps(unittest.TestCase): 'url': 'http://localhost:8080/job/foo/1/'} @mock.patch.object(Build, '_poll') - def testTimestamp(self, _poll): + def test_timestamp(self, _poll): _poll.return_value = self.DATA j = mock.MagicMock() diff --git a/setup.py b/setup.py index ac26af0..7f47eb4 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup import os PROJECT_ROOT, _ = os.path.split(__file__) -VERSION = REVISION = '0.1.14' +VERSION = REVISION = '0.1.15' PROJECT_NAME = 'JenkinsAPI' PROJECT_AUTHORS = "Salim Fadhley, Ramon van Alteren, Ruslan Lutsenko" PROJECT_EMAILS = 'salimfadhley@gmail.com, ramon@vanalteren.nl, ruslan.lutcenko@gmail.com' @@ -22,10 +22,12 @@ setup(name=PROJECT_NAME.lower(), version=VERSION, author=PROJECT_AUTHORS, author_email=PROJECT_EMAILS, - packages=["jenkinsapi", 'jenkinsapi.utils', 'jenkinsapi.command_line'], + packages=['jenkinsapi', 'jenkinsapi.utils', 'jenkinsapi.command_line', 'jenkinsapi_tests'], zip_safe=True, include_package_data=False, install_requires=[], + test_suite='jenkinsapi_tests', + tests_require=['mock', 'nose'], extras_require={ 'kerberos': ['kerberos'] },