Merge "[scm] Update helpers import to common style"

This commit is contained in:
Zuul 2018-07-25 02:47:49 +00:00 committed by Gerrit Code Review
commit b30a825e9b
1 changed files with 102 additions and 58 deletions

View File

@ -42,7 +42,7 @@ import xml.etree.ElementTree as XML
from jenkins_jobs.errors import InvalidAttributeError
from jenkins_jobs.errors import JenkinsJobsException
import jenkins_jobs.modules.base
from jenkins_jobs.modules.helpers import convert_mapping_to_xml
import jenkins_jobs.modules.helpers as helpers
def git(registry, xml_parent, data):
@ -249,8 +249,8 @@ def git(registry, xml_parent, data):
if 'url' in remoteParams:
remoteURL = remoteParams['url']
else:
raise JenkinsJobsException('Must specify a url for git remote \"' +
remoteName + '"')
raise JenkinsJobsException(
'Must specify a url for git remote \"' + remoteName + '"')
XML.SubElement(huser, 'url').text = remoteURL
if 'credentials-id' in remoteParams:
credentialsId = remoteParams['credentials-id']
@ -384,8 +384,10 @@ def git(registry, xml_parent, data):
clo = XML.SubElement(exts_node, impl_prefix + 'CloneOption')
clone_mapping = [
('shallow-clone', 'shallow', False),
('depth', 'depth', 1)]
convert_mapping_to_xml(clo, data, clone_mapping, fail_required=True)
('depth', 'depth', 1),
]
helpers.convert_mapping_to_xml(
clo, data, clone_mapping, fail_required=True)
if 'do-not-fetch-tags' in data:
XML.SubElement(clo, 'noTags').text = str(
data.get('do-not-fetch-tags', False)).lower()
@ -568,9 +570,11 @@ def cvs(registry, xml_parent, data):
repo_tag = XML.SubElement(repos_tag, prefix + 'CvsRepository')
compression_level = repo.get('compression-level', '-1')
repo_mapping = [('root', 'cvsRoot', None),
('', 'compressionLevel', int(compression_level), range(-1, 10))]
convert_mapping_to_xml(repo_tag,
repo_mapping = [
('root', 'cvsRoot', None),
('', 'compressionLevel', int(compression_level), range(-1, 10)),
]
helpers.convert_mapping_to_xml(repo_tag,
repo, repo_mapping, fail_required=True)
items_tag = XML.SubElement(repo_tag, 'repositoryItems')
@ -584,15 +588,18 @@ def cvs(registry, xml_parent, data):
'Location').format(prefix, valid_loc_types[loc_type])
loc_tag = XML.SubElement(item_tag, 'location',
{'class': loc_class})
mapping = [('type', 'locationType', 'HEAD')]
convert_mapping_to_xml(
mapping = [
('type', 'locationType', 'HEAD'),
]
helpers.convert_mapping_to_xml(
loc_tag, location, mapping, fail_required=True)
if loc_type != 'HEAD':
mapping = [
('name', 'locationName', ''),
('use-head', 'useHeadIfNotFound', False)]
convert_mapping_to_xml(
('use-head', 'useHeadIfNotFound', False),
]
helpers.convert_mapping_to_xml(
loc_tag, location, mapping, fail_required=True)
modules = location.get('modules')
@ -601,8 +608,9 @@ def cvs(registry, xml_parent, data):
module_tag = XML.SubElement(modules_tag, prefix + 'CvsModule')
mapping = [
('remote', 'remoteName', None),
('local-name', 'localName', '')]
convert_mapping_to_xml(
('local-name', 'localName', ''),
]
helpers.convert_mapping_to_xml(
module_tag, module, mapping, fail_required=True)
excluded = repo.get('excluded-regions', [])
@ -618,8 +626,9 @@ def cvs(registry, xml_parent, data):
('skip-changelog', 'skipChangeLog', False),
('show-all-output', 'disableCvsQuiet', False),
('clean-checkout', 'cleanOnFailedUpdate', False),
('clean-copy', 'forceCleanCopy', False)]
convert_mapping_to_xml(cvs, data, mappings, fail_required=True)
('clean-copy', 'forceCleanCopy', False),
]
helpers.convert_mapping_to_xml(cvs, data, mappings, fail_required=True)
def repo(registry, xml_parent, data):
@ -682,7 +691,7 @@ def repo(registry, xml_parent, data):
('trace', 'trace', False),
('show-all-changes', 'showAllChanges', False),
]
convert_mapping_to_xml(scm, data, mapping, fail_required=True)
helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
optional_mapping = [
# option, xml name, default value
@ -694,7 +703,8 @@ def repo(registry, xml_parent, data):
('mirror-dir', 'mirrorDir', None),
('local-manifest', 'localManifest', None),
]
convert_mapping_to_xml(scm, data, optional_mapping, fail_required=False)
helpers.convert_mapping_to_xml(
scm, data, optional_mapping, fail_required=False)
# ignore-projects does not follow the same pattern of the other parameters,
# so process it here:
@ -732,8 +742,9 @@ def store(registry, xml_parent, data):
{'class': '{0}.StoreSCM'.format(namespace)})
mapping = [
('script', 'scriptName', None),
('repository', 'repositoryName', None)]
convert_mapping_to_xml(scm, data, mapping, fail_required=True)
('repository', 'repositoryName', None),
]
helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
pundle_specs = data.get('pundles', [])
if not pundle_specs:
@ -747,16 +758,19 @@ def store(registry, xml_parent, data):
pundle_name = pundle_spec[pundle_type]
mapping = [
('', 'name', pundle_name),
('', 'pundleType', pundle_type.upper(), valid_pundle_types)]
convert_mapping_to_xml(pundle, data, mapping, fail_required=True)
('', 'pundleType', pundle_type.upper(), valid_pundle_types),
]
helpers.convert_mapping_to_xml(
pundle, data, mapping, fail_required=True)
generate_parcel = 'parcel-builder-file' in data
mapping_optional = [
('version-regex', 'versionRegex', None),
('minimum-blessing', 'minimumBlessingLevel', None),
('', 'generateParcelBuilderInputFile', generate_parcel),
('parcel-builder-file', 'parcelBuilderInputFilename', None)]
convert_mapping_to_xml(scm,
('parcel-builder-file', 'parcelBuilderInputFilename', None),
]
helpers.convert_mapping_to_xml(scm,
data, mapping_optional, fail_required=False)
@ -826,8 +840,11 @@ def svn(registry, xml_parent, data):
if 'viewvc-url' in data:
browser = XML.SubElement(
scm, 'browser', {'class': 'hudson.scm.browsers.ViewSVN'})
mapping = [('viewvc-url', 'url', None)]
convert_mapping_to_xml(browser, data, mapping, fail_required=True)
mapping = [
('viewvc-url', 'url', None),
]
helpers.convert_mapping_to_xml(
browser, data, mapping, fail_required=True)
locations = XML.SubElement(scm, 'locations')
def populate_repo_xml(parent, data):
@ -835,15 +852,18 @@ def svn(registry, xml_parent, data):
'hudson.scm.SubversionSCM_-ModuleLocation')
mapping = [
('url', 'remote', None),
('basedir', 'local', '.')]
convert_mapping_to_xml(module, data, mapping, fail_required=True)
('basedir', 'local', '.'),
]
helpers.convert_mapping_to_xml(
module, data, mapping, fail_required=True)
repo_depths = ['infinity', 'empty', 'files', 'immediates', 'unknown']
mapping_optional = [
('credentials-id', 'credentialsId', None),
('repo-depth', 'depthOption', 'infinity', repo_depths),
('ignore-externals', 'ignoreExternalsOption', False)]
convert_mapping_to_xml(module, data,
('ignore-externals', 'ignoreExternalsOption', False),
]
helpers.convert_mapping_to_xml(module, data,
mapping_optional, fail_required=False)
if 'repos' in data:
@ -992,7 +1012,7 @@ def tfs(registry, xml_parent, data):
('login', 'userName', ''),
('use-update', 'useUpdate', True),
]
convert_mapping_to_xml(tfs, data, mapping, fail_required=True)
helpers.convert_mapping_to_xml(tfs, data, mapping, fail_required=True)
store = data.get('web-access', None)
if isinstance(store, list):
@ -1036,8 +1056,10 @@ def workspace(registry, xml_parent, data):
mapping = [
('parent-job', 'parentJobName', ''),
('', 'criteria', criteria, criteria_list)]
convert_mapping_to_xml(workspace, data, mapping, fail_required=True)
('', 'criteria', criteria, criteria_list),
]
helpers.convert_mapping_to_xml(
workspace, data, mapping, fail_required=True)
def hg(self, xml_parent, data):
@ -1099,16 +1121,20 @@ def hg(self, xml_parent, data):
scm = XML.SubElement(xml_parent, 'scm', {'class':
'hudson.plugins.mercurial.MercurialSCM'})
mapping = [('url', 'source', None)]
convert_mapping_to_xml(scm, data, mapping, fail_required=True)
mapping = [
('url', 'source', None),
]
helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
mapping_optional = [
('credentials-id', 'credentialsId', None),
('revision-type', 'revisionType', 'branch', revision_type_dict),
('revision', 'revision', 'default'),
('subdir', 'subdir', None),
('clean', 'clean', False)]
convert_mapping_to_xml(scm, data, mapping_optional, fail_required=False)
('clean', 'clean', False),
]
helpers.convert_mapping_to_xml(
scm, data, mapping_optional, fail_required=False)
modules = data.get('modules', '')
if isinstance(modules, list):
@ -1121,8 +1147,10 @@ def hg(self, xml_parent, data):
bc = XML.SubElement(scm, 'browser',
{'class': 'hudson.plugins.mercurial.browser.' +
browserdict[browser]})
mapping = [('browser-url', 'url', None, browserdict[browser])]
convert_mapping_to_xml(bc, data, mapping, fail_required=True)
mapping = [
('browser-url', 'url', None, browserdict[browser]),
]
helpers.convert_mapping_to_xml(bc, data, mapping, fail_required=True)
def openshift_img_streams(registry, xml_parent, data):
@ -1177,7 +1205,7 @@ def openshift_img_streams(registry, xml_parent, data):
("auth-token", 'authToken', ''),
("verbose", 'verbose', False),
]
convert_mapping_to_xml(scm, data, mapping, fail_required=True)
helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
def bzr(registry, xml_parent, data):
@ -1216,7 +1244,8 @@ def bzr(registry, xml_parent, data):
]
scm_element = XML.SubElement(
xml_parent, 'scm', {'class': 'hudson.plugins.bazaar.BazaarSCM'})
convert_mapping_to_xml(scm_element, data, mapping, fail_required=True)
helpers.convert_mapping_to_xml(
scm_element, data, mapping, fail_required=True)
browser_name_to_class = {
'loggerhead': 'Loggerhead',
@ -1233,12 +1262,17 @@ def bzr(registry, xml_parent, data):
'browser',
{'class': 'hudson.plugins.bazaar.browsers.{0}'.format(
browser_name_to_class[browser])})
mapping = [('browser-url', 'url', None)]
convert_mapping_to_xml(browser_element, data, mapping, fail_required=True)
mapping = [
('browser-url', 'url', None),
]
helpers.convert_mapping_to_xml(
browser_element, data, mapping, fail_required=True)
if browser == 'opengrok':
mapping = [('opengrok-root-module', 'rootModule', None)]
convert_mapping_to_xml(browser_element,
mapping = [
('opengrok-root-module', 'rootModule', None),
]
helpers.convert_mapping_to_xml(browser_element,
data, mapping, fail_required=True)
@ -1266,10 +1300,15 @@ def url(registry, xml_parent, data):
for data_url in data['url-list']:
url_tuple = XML.SubElement(
urls, 'hudson.plugins.URLSCM.URLSCM_-URLTuple')
mapping = [('', 'urlString', data_url)]
convert_mapping_to_xml(url_tuple, data, mapping, fail_required=True)
mapping = [('clear-workspace', 'clearWorkspace', False)]
convert_mapping_to_xml(scm, data, mapping, fail_required=True)
mapping = [
('', 'urlString', data_url),
]
helpers.convert_mapping_to_xml(
url_tuple, data, mapping, fail_required=True)
mapping = [
('clear-workspace', 'clearWorkspace', False),
]
helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
def dimensions(registry, xml_parent, data):
@ -1347,7 +1386,7 @@ def dimensions(registry, xml_parent, data):
('maintain-timestamp', 'canJobNoTouch', False),
('slave-checkout', 'forceAsSlave', False),
]
convert_mapping_to_xml(scm, data, mapping, fail_required=True)
helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
# Folders to monitor. Default '/'
folders = XML.SubElement(scm, 'folders')
@ -1372,7 +1411,8 @@ def dimensions(registry, xml_parent, data):
('timezone', 'jobTimeZone', None),
('web-url', 'jobWebUrl', None),
]
convert_mapping_to_xml(scm, data, optional_mapping, fail_required=False)
helpers.convert_mapping_to_xml(
scm, data, optional_mapping, fail_required=False)
def accurev(registry, xml_parent, data):
@ -1421,7 +1461,7 @@ def accurev(registry, xml_parent, data):
('build-from-snapshot', 'useSnapshot', False),
('do-not-pop-content', 'dontPopContent', False),
]
convert_mapping_to_xml(scm, data, mapping, fail_required=True)
helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
additional_mapping = [
('workspace', 'workspace', None),
@ -1431,7 +1471,8 @@ def accurev(registry, xml_parent, data):
('filter-poll-scm', 'filterForPollSCM', None),
('snapshot-name-format', 'snapshotNameFormat', None),
]
convert_mapping_to_xml(scm, data, additional_mapping, fail_required=False)
helpers.convert_mapping_to_xml(
scm, data, additional_mapping, fail_required=False)
class SCM(jenkins_jobs.modules.base.Base):
@ -1486,11 +1527,14 @@ class PipelineSCM(jenkins_jobs.modules.base.Base):
raise JenkinsJobsException("'scm' missing or empty")
elif scms_count == 1:
self.registry.dispatch('scm', definition_parent, scms[0])
mapping = [('script-path', 'scriptPath', 'Jenkinsfile'),
('lightweight-checkout', 'lightweight', None,
[True, False])]
convert_mapping_to_xml(definition_parent, pipeline_dict,
mapping, fail_required=False)
mapping = [
('script-path', 'scriptPath', 'Jenkinsfile'),
('lightweight-checkout', 'lightweight', None,
[True, False]),
]
helpers.convert_mapping_to_xml(
definition_parent, pipeline_dict, mapping,
fail_required=False)
else:
raise JenkinsJobsException('Only one SCM can be specified '
'as pipeline-scm')