From fb0a113eff8a0ee6ea9983ce682bf752cd04e851 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Fri, 10 Aug 2012 16:45:00 -0700 Subject: [PATCH] Add tox.ini and pep8, pyflakes cleanup. Change-Id: I4d6312e92dffd596ae58e55c837e3db3ea7d1c52 Reviewed-on: https://review.openstack.org/11198 Reviewed-by: Monty Taylor Approved: James E. Blair Tested-by: Jenkins --- .gitignore | 1 + jenkins_jobs/builder.py | 107 +++++++++++++------------- jenkins_jobs/modules/builders.py | 17 ++-- jenkins_jobs/modules/logrotate.py | 2 +- jenkins_jobs/modules/project_maven.py | 1 + jenkins_jobs/modules/properties.py | 11 ++- jenkins_jobs/modules/publishers.py | 68 +++++----------- jenkins_jobs/modules/scm.py | 11 +-- jenkins_jobs/modules/triggers.py | 18 +++-- jenkins_jobs/modules/wrappers.py | 3 +- jenkins_jobs/modules/zuul.py | 1 + setup.py | 2 +- tox.ini | 16 ++++ 13 files changed, 135 insertions(+), 123 deletions(-) create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index e54e9a92f..456cf3ada 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.pyc *.egg-info config +.tox diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py index f789ea9e7..153898938 100644 --- a/jenkins_jobs/builder.py +++ b/jenkins_jobs/builder.py @@ -21,15 +21,9 @@ import yaml import xml.etree.ElementTree as XML from xml.dom import minidom import jenkins -import ConfigParser -from StringIO import StringIO import re -import pkgutil import pkg_resources -import pprint -import sys -class JenkinsJobsException(Exception): pass class YamlParser(object): def __init__(self): @@ -115,11 +109,16 @@ class YamlParser(object): def gen_xml(self, xml, data): XML.SubElement(xml, 'actions') description = XML.SubElement(xml, 'description') - description.text = "THIS JOB IS MANAGED BY PUPPET AND WILL BE OVERWRITTEN.\n\n\ -DON'T EDIT THIS JOB THROUGH THE WEB\n\n\ -If you would like to make changes to this job, please see:\n\n\ -https://github.com/openstack/openstack-ci-puppet\n\n\ -In modules/jenkins_jobs" + description.text = """THIS JOB IS MANAGED BY PUPPET \ +AND WILL BE OVERWRITTEN. + +DON'T EDIT THIS JOB THROUGH THE WEB + +If you would like to make changes to this job, please see: + +https://github.com/openstack/openstack-ci-puppet + +In modules/jenkins_jobs""" XML.SubElement(xml, 'keepDependencies').text = 'false' if data.get('disabled'): XML.SubElement(xml, 'disabled').text = 'true' @@ -138,8 +137,6 @@ In modules/jenkins_jobs" class ModuleRegistry(object): - # TODO: make this extensible - def __init__(self): self.modules = [] self.handlers = {} @@ -160,6 +157,7 @@ class ModuleRegistry(object): def getHandler(self, category, name): return self.handlers[category][name] + class XmlJob(object): def __init__(self, xml, name): self.xml = xml @@ -168,61 +166,65 @@ class XmlJob(object): def md5(self): return hashlib.md5(self.output()).hexdigest() - # Pretty printing ideas from http://stackoverflow.com/questions/749796/pretty-printing-xml-in-python + # Pretty printing ideas from + # http://stackoverflow.com/questions/749796/pretty-printing-xml-in-python pretty_text_re = re.compile('>\n\s+([^<>\s].*?)\n\s+\g<1> - - FTP: - - - - docs.openstack.org - true - - - - openstack-identity-api/target/docbkx/webhelp/api/openstack-identity-service/2.0/** - **/*.xml,**/null* - openstack-identity-api/target/docbkx/webhelp - false - false - false - false - - - false - false - - - false - false - false - - - - - """ outer_ftp = XML.SubElement(xml_parent, 'jenkins.plugins.publish__over__ftp.BapFtpPublisherPlugin') XML.SubElement(outer_ftp, 'consolePrefix').text = 'FTP: ' @@ -168,7 +137,8 @@ def ftp(parser, xml_parent, data): XML.SubElement(ftp, 'verbose').text = 'true' transfers = XML.SubElement(ftp, 'transfers') - ftp_transfers = XML.SubElement(transfers, 'jenkins.plugins.publish__over__ftp.BapFtpTransfer') + ftp_transfers = XML.SubElement(transfers, + 'jenkins.plugins.publish__over__ftp.BapFtpTransfer') XML.SubElement(ftp_transfers, 'remoteDirectory').text = data['target'] XML.SubElement(ftp_transfers, 'sourceFiles').text = data['source'] XML.SubElement(ftp_transfers, 'excludes').text = data['excludes'] @@ -187,6 +157,7 @@ def ftp(parser, xml_parent, data): {'class': 'jenkins.plugins.publish_over_ftp.BapFtpPublisherPlugin', 'reference': '../..'}) + # Jenkins Job module for coverage publishers # To use you add the following into your YAML: # publisher: @@ -211,14 +182,16 @@ def _pep8_add_entry(xml_parent, name): XML.SubElement(tconfig, 'usePattern').text = 'false' XML.SubElement(tconfig, 'pattern') + # Jenkins Job module for pep8 publishers # No additional YAML needed def pep8(parser, xml_parent, data): violations = XML.SubElement(xml_parent, - 'hudson.plugins.violations.ViolationsPublisher') + 'hudson.plugins.violations.ViolationsPublisher') config = XML.SubElement(violations, 'config') - suppressions = XML.SubElement(config, 'suppressions', {'class':'tree-set'}) + suppressions = XML.SubElement(config, 'suppressions', + {'class': 'tree-set'}) XML.SubElement(suppressions, 'no-comparator') configs = XML.SubElement(config, 'typeConfigs') XML.SubElement(configs, 'no-comparator') @@ -254,6 +227,7 @@ def pep8(parser, xml_parent, data): XML.SubElement(config, 'fauxProjectPath') XML.SubElement(config, 'encoding').text = 'default' + # Jenkins Job module for generic scp publishing # To use you add the following into your YAML: # publish: @@ -276,6 +250,7 @@ def scp(parser, xml_parent, data): else: XML.SubElement(entry, 'keepHierarchy').text = 'false' + class Publishers(jenkins_jobs.modules.base.Base): sequence = 70 @@ -285,6 +260,3 @@ class Publishers(jenkins_jobs.modules.base.Base): for action in data.get('publishers', []): self._dispatch('publisher', 'publishers', parser, publishers, action) - - - diff --git a/jenkins_jobs/modules/scm.py b/jenkins_jobs/modules/scm.py index 470ce7de0..607a97c53 100644 --- a/jenkins_jobs/modules/scm.py +++ b/jenkins_jobs/modules/scm.py @@ -22,9 +22,10 @@ import xml.etree.ElementTree as XML import jenkins_jobs.modules.base + def git(self, xml_parent, data): scm = XML.SubElement(xml_parent, - 'scm',{'class':'hudson.plugins.git.GitSCM'}) + 'scm', {'class': 'hudson.plugins.git.GitSCM'}) XML.SubElement(scm, 'configVersion').text = '2' user = XML.SubElement(scm, 'userRemoteConfigs') huser = XML.SubElement(user, 'hudson.plugins.git.UserRemoteConfig') @@ -46,9 +47,9 @@ def git(self, xml_parent, data): XML.SubElement(scm, 'pruneBranches').text = 'false' XML.SubElement(scm, 'remotePoll').text = 'false' XML.SubElement(scm, 'buildChooser', - {'class':'hudson.plugins.git.util.DefaultBuildChooser'}) + {'class': 'hudson.plugins.git.util.DefaultBuildChooser'}) XML.SubElement(scm, 'gitTool').text = 'Default' - XML.SubElement(scm, 'submoduleCfg', {'class':'list'}) + XML.SubElement(scm, 'submoduleCfg', {'class': 'list'}) XML.SubElement(scm, 'relativeTargetDir') XML.SubElement(scm, 'reference') XML.SubElement(scm, 'excludedRegions') @@ -58,6 +59,7 @@ def git(self, xml_parent, data): XML.SubElement(scm, 'skipTag').text = 'false' XML.SubElement(scm, 'scmName') + class SCM(jenkins_jobs.modules.base.Base): sequence = 30 @@ -68,5 +70,4 @@ class SCM(jenkins_jobs.modules.base.Base): self._dispatch('scm', 'scm', parser, xml_parent, scm) else: - XML.SubElement(xml_parent, 'scm', {'class':'hudson.scm.NullSCM'}) - + XML.SubElement(xml_parent, 'scm', {'class': 'hudson.scm.NullSCM'}) diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py index abaa2620a..00052900b 100644 --- a/jenkins_jobs/modules/triggers.py +++ b/jenkins_jobs/modules/triggers.py @@ -24,7 +24,11 @@ # overrideVotes: 'true' # gerritBuildSuccessfulVerifiedValue: 1 # gerritBuildFailedVerifiedValue: -1 -# failureMessage: 'This change was unable to be automatically merged with the current state of the repository. Please rebase your change and upload a new patchset.' +# +# failureMessage: 'This change was unable to be automatically merged +# with the current state of the repository. Please rebase your change +# and upload a new patchset.' +# # projects: # - projectCompareType: 'PLAIN' # projectPattern: 'openstack/nova' @@ -36,11 +40,13 @@ # branchPattern: '**' # ... # -# triggerApprovalCategory and triggerApprovalValue only required if triggerOnCommentAddedEvent: 'true' +# triggerApprovalCategory and triggerApprovalValue only required +# if triggerOnCommentAddedEvent: 'true' import xml.etree.ElementTree as XML import jenkins_jobs.modules.base + def gerrit(parser, xml_parent, data): projects = data['projects'] gtrig = XML.SubElement(xml_parent, @@ -71,7 +77,7 @@ def gerrit(parser, xml_parent, data): data['triggerOnCommentAddedEvent'] XML.SubElement(gtrig, 'triggerOnRefUpdatedEvent').text = \ data['triggerOnRefUpdatedEvent'] - if data.has_key('overrideVotes') and data['overrideVotes'] == 'true': + if 'overrideVotes' in data and data['overrideVotes'] == 'true': XML.SubElement(gtrig, 'gerritBuildSuccessfulVerifiedValue').text = \ str(data['gerritBuildSuccessfulVerifiedValue']) XML.SubElement(gtrig, 'gerritBuildFailedVerifiedValue').text = \ @@ -87,6 +93,7 @@ def gerrit(parser, xml_parent, data): XML.SubElement(gtrig, 'buildUnstableMessage') XML.SubElement(gtrig, 'customUrl') + # Jenkins Job module for scm polling triggers # To use add the following into your YAML: # trigger: @@ -98,6 +105,7 @@ def pollscm(parser, xml_parent, data): scmtrig = XML.SubElement(xml_parent, 'hudson.triggers.SCMTrigger') XML.SubElement(scmtrig, 'spec').text = data + # Jenkins Job module for timed triggers # To use add the following into your YAML: # trigger: @@ -109,6 +117,7 @@ def timed(parser, xml_parent, data): scmtrig = XML.SubElement(xml_parent, 'hudson.triggers.TimerTrigger') XML.SubElement(scmtrig, 'spec').text = data + class Triggers(jenkins_jobs.modules.base.Base): sequence = 50 @@ -117,8 +126,7 @@ class Triggers(jenkins_jobs.modules.base.Base): if not triggers: return - trig_e = XML.SubElement(xml_parent, 'triggers', {'class':'vector'}) + trig_e = XML.SubElement(xml_parent, 'triggers', {'class': 'vector'}) for trigger in triggers: self._dispatch('trigger', 'triggers', parser, trig_e, trigger) - diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index e15513edd..b8446f615 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -30,10 +30,12 @@ def timeout(parser, xml_parent, data): else: failbuild.text = 'false' + def timestamps(parser, xml_parent, data): XML.SubElement(xml_parent, 'hudson.plugins.timestamper.TimestamperBuildWrapper') + def ansicolor(parser, xml_parent, data): XML.SubElement(xml_parent, 'hudson.plugins.ansicolor.AnsiColorBuildWrapper') @@ -48,4 +50,3 @@ class Wrappers(jenkins_jobs.modules.base.Base): for wrap in data.get('wrappers', []): self._dispatch('wrapper', 'wrappers', parser, wrappers, wrap) - diff --git a/jenkins_jobs/modules/zuul.py b/jenkins_jobs/modules/zuul.py index c715387c6..130b189f3 100644 --- a/jenkins_jobs/modules/zuul.py +++ b/jenkins_jobs/modules/zuul.py @@ -55,6 +55,7 @@ ZUUL_NOTIFICATIONS = [ {'url': 'http://127.0.0.1:8001/jenkins_endpoint'}} ] + class Zuul(jenkins_jobs.modules.base.Base): sequence = 0 diff --git a/setup.py b/setup.py index 94876b7c3..465a434c8 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ setup(name='jenkins_job_builder', zip_safe=False, packages=find_packages(), - entry_points = { + entry_points={ 'jenkins_jobs.projects': [ 'freestyle=jenkins_jobs.modules.project_freestyle:Freestyle', 'maven=jenkins_jobs.modules.project_maven:Maven', diff --git a/tox.ini b/tox.ini new file mode 100644 index 000000000..db3b92e97 --- /dev/null +++ b/tox.ini @@ -0,0 +1,16 @@ +[tox] +envlist = pep8, pyflakes + +[tox:jenkins] +downloadcache = ~/cache/pip + +[testenv:pep8] +deps = pep8==1.2 +commands = pep8 --repeat --show-source --exclude=.venv,.tox,dist,doc,build . + +[testenv:pyflakes] +deps = pyflakes +commands = pyflakes jenkins_jobs jenkins-jobs setup.py + +[testenv:venv] +commands = {posargs}