summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-07-25 02:47:49 +0000
committerGerrit Code Review <review@openstack.org>2018-07-25 02:47:49 +0000
commitb30a825e9b1c5c4e65273e73d55dba936280ea0f (patch)
tree103cc9a9d2310048bef0e1342b04f998b0711f1b
parent5546870ef203b5dfd1f6c32e27559d41a878c9b1 (diff)
parentbdb4509b06043dc09e272cc391ab96aa79f3a51e (diff)
Merge "[scm] Update helpers import to common style"
-rw-r--r--jenkins_jobs/modules/scm.py160
1 files changed, 102 insertions, 58 deletions
diff --git a/jenkins_jobs/modules/scm.py b/jenkins_jobs/modules/scm.py
index c82d106..dffbbdc 100644
--- a/jenkins_jobs/modules/scm.py
+++ b/jenkins_jobs/modules/scm.py
@@ -42,7 +42,7 @@ import xml.etree.ElementTree as XML
42from jenkins_jobs.errors import InvalidAttributeError 42from jenkins_jobs.errors import InvalidAttributeError
43from jenkins_jobs.errors import JenkinsJobsException 43from jenkins_jobs.errors import JenkinsJobsException
44import jenkins_jobs.modules.base 44import jenkins_jobs.modules.base
45from jenkins_jobs.modules.helpers import convert_mapping_to_xml 45import jenkins_jobs.modules.helpers as helpers
46 46
47 47
48def git(registry, xml_parent, data): 48def git(registry, xml_parent, data):
@@ -249,8 +249,8 @@ def git(registry, xml_parent, data):
249 if 'url' in remoteParams: 249 if 'url' in remoteParams:
250 remoteURL = remoteParams['url'] 250 remoteURL = remoteParams['url']
251 else: 251 else:
252 raise JenkinsJobsException('Must specify a url for git remote \"' + 252 raise JenkinsJobsException(
253 remoteName + '"') 253 'Must specify a url for git remote \"' + remoteName + '"')
254 XML.SubElement(huser, 'url').text = remoteURL 254 XML.SubElement(huser, 'url').text = remoteURL
255 if 'credentials-id' in remoteParams: 255 if 'credentials-id' in remoteParams:
256 credentialsId = remoteParams['credentials-id'] 256 credentialsId = remoteParams['credentials-id']
@@ -384,8 +384,10 @@ def git(registry, xml_parent, data):
384 clo = XML.SubElement(exts_node, impl_prefix + 'CloneOption') 384 clo = XML.SubElement(exts_node, impl_prefix + 'CloneOption')
385 clone_mapping = [ 385 clone_mapping = [
386 ('shallow-clone', 'shallow', False), 386 ('shallow-clone', 'shallow', False),
387 ('depth', 'depth', 1)] 387 ('depth', 'depth', 1),
388 convert_mapping_to_xml(clo, data, clone_mapping, fail_required=True) 388 ]
389 helpers.convert_mapping_to_xml(
390 clo, data, clone_mapping, fail_required=True)
389 if 'do-not-fetch-tags' in data: 391 if 'do-not-fetch-tags' in data:
390 XML.SubElement(clo, 'noTags').text = str( 392 XML.SubElement(clo, 'noTags').text = str(
391 data.get('do-not-fetch-tags', False)).lower() 393 data.get('do-not-fetch-tags', False)).lower()
@@ -568,9 +570,11 @@ def cvs(registry, xml_parent, data):
568 repo_tag = XML.SubElement(repos_tag, prefix + 'CvsRepository') 570 repo_tag = XML.SubElement(repos_tag, prefix + 'CvsRepository')
569 571
570 compression_level = repo.get('compression-level', '-1') 572 compression_level = repo.get('compression-level', '-1')
571 repo_mapping = [('root', 'cvsRoot', None), 573 repo_mapping = [
572 ('', 'compressionLevel', int(compression_level), range(-1, 10))] 574 ('root', 'cvsRoot', None),
573 convert_mapping_to_xml(repo_tag, 575 ('', 'compressionLevel', int(compression_level), range(-1, 10)),
576 ]
577 helpers.convert_mapping_to_xml(repo_tag,
574 repo, repo_mapping, fail_required=True) 578 repo, repo_mapping, fail_required=True)
575 579
576 items_tag = XML.SubElement(repo_tag, 'repositoryItems') 580 items_tag = XML.SubElement(repo_tag, 'repositoryItems')
@@ -584,15 +588,18 @@ def cvs(registry, xml_parent, data):
584 'Location').format(prefix, valid_loc_types[loc_type]) 588 'Location').format(prefix, valid_loc_types[loc_type])
585 loc_tag = XML.SubElement(item_tag, 'location', 589 loc_tag = XML.SubElement(item_tag, 'location',
586 {'class': loc_class}) 590 {'class': loc_class})
587 mapping = [('type', 'locationType', 'HEAD')] 591 mapping = [
588 convert_mapping_to_xml( 592 ('type', 'locationType', 'HEAD'),
593 ]
594 helpers.convert_mapping_to_xml(
589 loc_tag, location, mapping, fail_required=True) 595 loc_tag, location, mapping, fail_required=True)
590 596
591 if loc_type != 'HEAD': 597 if loc_type != 'HEAD':
592 mapping = [ 598 mapping = [
593 ('name', 'locationName', ''), 599 ('name', 'locationName', ''),
594 ('use-head', 'useHeadIfNotFound', False)] 600 ('use-head', 'useHeadIfNotFound', False),
595 convert_mapping_to_xml( 601 ]
602 helpers.convert_mapping_to_xml(
596 loc_tag, location, mapping, fail_required=True) 603 loc_tag, location, mapping, fail_required=True)
597 604
598 modules = location.get('modules') 605 modules = location.get('modules')
@@ -601,8 +608,9 @@ def cvs(registry, xml_parent, data):
601 module_tag = XML.SubElement(modules_tag, prefix + 'CvsModule') 608 module_tag = XML.SubElement(modules_tag, prefix + 'CvsModule')
602 mapping = [ 609 mapping = [
603 ('remote', 'remoteName', None), 610 ('remote', 'remoteName', None),
604 ('local-name', 'localName', '')] 611 ('local-name', 'localName', ''),
605 convert_mapping_to_xml( 612 ]
613 helpers.convert_mapping_to_xml(
606 module_tag, module, mapping, fail_required=True) 614 module_tag, module, mapping, fail_required=True)
607 615
608 excluded = repo.get('excluded-regions', []) 616 excluded = repo.get('excluded-regions', [])
@@ -618,8 +626,9 @@ def cvs(registry, xml_parent, data):
618 ('skip-changelog', 'skipChangeLog', False), 626 ('skip-changelog', 'skipChangeLog', False),
619 ('show-all-output', 'disableCvsQuiet', False), 627 ('show-all-output', 'disableCvsQuiet', False),
620 ('clean-checkout', 'cleanOnFailedUpdate', False), 628 ('clean-checkout', 'cleanOnFailedUpdate', False),
621 ('clean-copy', 'forceCleanCopy', False)] 629 ('clean-copy', 'forceCleanCopy', False),
622 convert_mapping_to_xml(cvs, data, mappings, fail_required=True) 630 ]
631 helpers.convert_mapping_to_xml(cvs, data, mappings, fail_required=True)
623 632
624 633
625def repo(registry, xml_parent, data): 634def repo(registry, xml_parent, data):
@@ -682,7 +691,7 @@ def repo(registry, xml_parent, data):
682 ('trace', 'trace', False), 691 ('trace', 'trace', False),
683 ('show-all-changes', 'showAllChanges', False), 692 ('show-all-changes', 'showAllChanges', False),
684 ] 693 ]
685 convert_mapping_to_xml(scm, data, mapping, fail_required=True) 694 helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
686 695
687 optional_mapping = [ 696 optional_mapping = [
688 # option, xml name, default value 697 # option, xml name, default value
@@ -694,7 +703,8 @@ def repo(registry, xml_parent, data):
694 ('mirror-dir', 'mirrorDir', None), 703 ('mirror-dir', 'mirrorDir', None),
695 ('local-manifest', 'localManifest', None), 704 ('local-manifest', 'localManifest', None),
696 ] 705 ]
697 convert_mapping_to_xml(scm, data, optional_mapping, fail_required=False) 706 helpers.convert_mapping_to_xml(
707 scm, data, optional_mapping, fail_required=False)
698 708
699 # ignore-projects does not follow the same pattern of the other parameters, 709 # ignore-projects does not follow the same pattern of the other parameters,
700 # so process it here: 710 # so process it here:
@@ -732,8 +742,9 @@ def store(registry, xml_parent, data):
732 {'class': '{0}.StoreSCM'.format(namespace)}) 742 {'class': '{0}.StoreSCM'.format(namespace)})
733 mapping = [ 743 mapping = [
734 ('script', 'scriptName', None), 744 ('script', 'scriptName', None),
735 ('repository', 'repositoryName', None)] 745 ('repository', 'repositoryName', None),
736 convert_mapping_to_xml(scm, data, mapping, fail_required=True) 746 ]
747 helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
737 748
738 pundle_specs = data.get('pundles', []) 749 pundle_specs = data.get('pundles', [])
739 if not pundle_specs: 750 if not pundle_specs:
@@ -747,16 +758,19 @@ def store(registry, xml_parent, data):
747 pundle_name = pundle_spec[pundle_type] 758 pundle_name = pundle_spec[pundle_type]
748 mapping = [ 759 mapping = [
749 ('', 'name', pundle_name), 760 ('', 'name', pundle_name),
750 ('', 'pundleType', pundle_type.upper(), valid_pundle_types)] 761 ('', 'pundleType', pundle_type.upper(), valid_pundle_types),
751 convert_mapping_to_xml(pundle, data, mapping, fail_required=True) 762 ]
763 helpers.convert_mapping_to_xml(
764 pundle, data, mapping, fail_required=True)
752 765
753 generate_parcel = 'parcel-builder-file' in data 766 generate_parcel = 'parcel-builder-file' in data
754 mapping_optional = [ 767 mapping_optional = [
755 ('version-regex', 'versionRegex', None), 768 ('version-regex', 'versionRegex', None),
756 ('minimum-blessing', 'minimumBlessingLevel', None), 769 ('minimum-blessing', 'minimumBlessingLevel', None),
757 ('', 'generateParcelBuilderInputFile', generate_parcel), 770 ('', 'generateParcelBuilderInputFile', generate_parcel),
758 ('parcel-builder-file', 'parcelBuilderInputFilename', None)] 771 ('parcel-builder-file', 'parcelBuilderInputFilename', None),
759 convert_mapping_to_xml(scm, 772 ]
773 helpers.convert_mapping_to_xml(scm,
760 data, mapping_optional, fail_required=False) 774 data, mapping_optional, fail_required=False)
761 775
762 776
@@ -826,8 +840,11 @@ def svn(registry, xml_parent, data):
826 if 'viewvc-url' in data: 840 if 'viewvc-url' in data:
827 browser = XML.SubElement( 841 browser = XML.SubElement(
828 scm, 'browser', {'class': 'hudson.scm.browsers.ViewSVN'}) 842 scm, 'browser', {'class': 'hudson.scm.browsers.ViewSVN'})
829 mapping = [('viewvc-url', 'url', None)] 843 mapping = [
830 convert_mapping_to_xml(browser, data, mapping, fail_required=True) 844 ('viewvc-url', 'url', None),
845 ]
846 helpers.convert_mapping_to_xml(
847 browser, data, mapping, fail_required=True)
831 locations = XML.SubElement(scm, 'locations') 848 locations = XML.SubElement(scm, 'locations')
832 849
833 def populate_repo_xml(parent, data): 850 def populate_repo_xml(parent, data):
@@ -835,15 +852,18 @@ def svn(registry, xml_parent, data):
835 'hudson.scm.SubversionSCM_-ModuleLocation') 852 'hudson.scm.SubversionSCM_-ModuleLocation')
836 mapping = [ 853 mapping = [
837 ('url', 'remote', None), 854 ('url', 'remote', None),
838 ('basedir', 'local', '.')] 855 ('basedir', 'local', '.'),
839 convert_mapping_to_xml(module, data, mapping, fail_required=True) 856 ]
857 helpers.convert_mapping_to_xml(
858 module, data, mapping, fail_required=True)
840 859
841 repo_depths = ['infinity', 'empty', 'files', 'immediates', 'unknown'] 860 repo_depths = ['infinity', 'empty', 'files', 'immediates', 'unknown']
842 mapping_optional = [ 861 mapping_optional = [
843 ('credentials-id', 'credentialsId', None), 862 ('credentials-id', 'credentialsId', None),
844 ('repo-depth', 'depthOption', 'infinity', repo_depths), 863 ('repo-depth', 'depthOption', 'infinity', repo_depths),
845 ('ignore-externals', 'ignoreExternalsOption', False)] 864 ('ignore-externals', 'ignoreExternalsOption', False),
846 convert_mapping_to_xml(module, data, 865 ]
866 helpers.convert_mapping_to_xml(module, data,
847 mapping_optional, fail_required=False) 867 mapping_optional, fail_required=False)
848 868
849 if 'repos' in data: 869 if 'repos' in data:
@@ -992,7 +1012,7 @@ def tfs(registry, xml_parent, data):
992 ('login', 'userName', ''), 1012 ('login', 'userName', ''),
993 ('use-update', 'useUpdate', True), 1013 ('use-update', 'useUpdate', True),
994 ] 1014 ]
995 convert_mapping_to_xml(tfs, data, mapping, fail_required=True) 1015 helpers.convert_mapping_to_xml(tfs, data, mapping, fail_required=True)
996 1016
997 store = data.get('web-access', None) 1017 store = data.get('web-access', None)
998 if isinstance(store, list): 1018 if isinstance(store, list):
@@ -1036,8 +1056,10 @@ def workspace(registry, xml_parent, data):
1036 1056
1037 mapping = [ 1057 mapping = [
1038 ('parent-job', 'parentJobName', ''), 1058 ('parent-job', 'parentJobName', ''),
1039 ('', 'criteria', criteria, criteria_list)] 1059 ('', 'criteria', criteria, criteria_list),
1040 convert_mapping_to_xml(workspace, data, mapping, fail_required=True) 1060 ]
1061 helpers.convert_mapping_to_xml(
1062 workspace, data, mapping, fail_required=True)
1041 1063
1042 1064
1043def hg(self, xml_parent, data): 1065def hg(self, xml_parent, data):
@@ -1099,16 +1121,20 @@ def hg(self, xml_parent, data):
1099 1121
1100 scm = XML.SubElement(xml_parent, 'scm', {'class': 1122 scm = XML.SubElement(xml_parent, 'scm', {'class':
1101 'hudson.plugins.mercurial.MercurialSCM'}) 1123 'hudson.plugins.mercurial.MercurialSCM'})
1102 mapping = [('url', 'source', None)] 1124 mapping = [
1103 convert_mapping_to_xml(scm, data, mapping, fail_required=True) 1125 ('url', 'source', None),
1126 ]
1127 helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
1104 1128
1105 mapping_optional = [ 1129 mapping_optional = [
1106 ('credentials-id', 'credentialsId', None), 1130 ('credentials-id', 'credentialsId', None),
1107 ('revision-type', 'revisionType', 'branch', revision_type_dict), 1131 ('revision-type', 'revisionType', 'branch', revision_type_dict),
1108 ('revision', 'revision', 'default'), 1132 ('revision', 'revision', 'default'),
1109 ('subdir', 'subdir', None), 1133 ('subdir', 'subdir', None),
1110 ('clean', 'clean', False)] 1134 ('clean', 'clean', False),
1111 convert_mapping_to_xml(scm, data, mapping_optional, fail_required=False) 1135 ]
1136 helpers.convert_mapping_to_xml(
1137 scm, data, mapping_optional, fail_required=False)
1112 1138
1113 modules = data.get('modules', '') 1139 modules = data.get('modules', '')
1114 if isinstance(modules, list): 1140 if isinstance(modules, list):
@@ -1121,8 +1147,10 @@ def hg(self, xml_parent, data):
1121 bc = XML.SubElement(scm, 'browser', 1147 bc = XML.SubElement(scm, 'browser',
1122 {'class': 'hudson.plugins.mercurial.browser.' + 1148 {'class': 'hudson.plugins.mercurial.browser.' +
1123 browserdict[browser]}) 1149 browserdict[browser]})
1124 mapping = [('browser-url', 'url', None, browserdict[browser])] 1150 mapping = [
1125 convert_mapping_to_xml(bc, data, mapping, fail_required=True) 1151 ('browser-url', 'url', None, browserdict[browser]),
1152 ]
1153 helpers.convert_mapping_to_xml(bc, data, mapping, fail_required=True)
1126 1154
1127 1155
1128def openshift_img_streams(registry, xml_parent, data): 1156def openshift_img_streams(registry, xml_parent, data):
@@ -1177,7 +1205,7 @@ def openshift_img_streams(registry, xml_parent, data):
1177 ("auth-token", 'authToken', ''), 1205 ("auth-token", 'authToken', ''),
1178 ("verbose", 'verbose', False), 1206 ("verbose", 'verbose', False),
1179 ] 1207 ]
1180 convert_mapping_to_xml(scm, data, mapping, fail_required=True) 1208 helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
1181 1209
1182 1210
1183def bzr(registry, xml_parent, data): 1211def bzr(registry, xml_parent, data):
@@ -1216,7 +1244,8 @@ def bzr(registry, xml_parent, data):
1216 ] 1244 ]
1217 scm_element = XML.SubElement( 1245 scm_element = XML.SubElement(
1218 xml_parent, 'scm', {'class': 'hudson.plugins.bazaar.BazaarSCM'}) 1246 xml_parent, 'scm', {'class': 'hudson.plugins.bazaar.BazaarSCM'})
1219 convert_mapping_to_xml(scm_element, data, mapping, fail_required=True) 1247 helpers.convert_mapping_to_xml(
1248 scm_element, data, mapping, fail_required=True)
1220 1249
1221 browser_name_to_class = { 1250 browser_name_to_class = {
1222 'loggerhead': 'Loggerhead', 1251 'loggerhead': 'Loggerhead',
@@ -1233,12 +1262,17 @@ def bzr(registry, xml_parent, data):
1233 'browser', 1262 'browser',
1234 {'class': 'hudson.plugins.bazaar.browsers.{0}'.format( 1263 {'class': 'hudson.plugins.bazaar.browsers.{0}'.format(
1235 browser_name_to_class[browser])}) 1264 browser_name_to_class[browser])})
1236 mapping = [('browser-url', 'url', None)] 1265 mapping = [
1237 convert_mapping_to_xml(browser_element, data, mapping, fail_required=True) 1266 ('browser-url', 'url', None),
1267 ]
1268 helpers.convert_mapping_to_xml(
1269 browser_element, data, mapping, fail_required=True)
1238 1270
1239 if browser == 'opengrok': 1271 if browser == 'opengrok':
1240 mapping = [('opengrok-root-module', 'rootModule', None)] 1272 mapping = [
1241 convert_mapping_to_xml(browser_element, 1273 ('opengrok-root-module', 'rootModule', None),
1274 ]
1275 helpers.convert_mapping_to_xml(browser_element,
1242 data, mapping, fail_required=True) 1276 data, mapping, fail_required=True)
1243 1277
1244 1278
@@ -1266,10 +1300,15 @@ def url(registry, xml_parent, data):
1266 for data_url in data['url-list']: 1300 for data_url in data['url-list']:
1267 url_tuple = XML.SubElement( 1301 url_tuple = XML.SubElement(
1268 urls, 'hudson.plugins.URLSCM.URLSCM_-URLTuple') 1302 urls, 'hudson.plugins.URLSCM.URLSCM_-URLTuple')
1269 mapping = [('', 'urlString', data_url)] 1303 mapping = [
1270 convert_mapping_to_xml(url_tuple, data, mapping, fail_required=True) 1304 ('', 'urlString', data_url),
1271 mapping = [('clear-workspace', 'clearWorkspace', False)] 1305 ]
1272 convert_mapping_to_xml(scm, data, mapping, fail_required=True) 1306 helpers.convert_mapping_to_xml(
1307 url_tuple, data, mapping, fail_required=True)
1308 mapping = [
1309 ('clear-workspace', 'clearWorkspace', False),
1310 ]
1311 helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
1273 1312
1274 1313
1275def dimensions(registry, xml_parent, data): 1314def dimensions(registry, xml_parent, data):
@@ -1347,7 +1386,7 @@ def dimensions(registry, xml_parent, data):
1347 ('maintain-timestamp', 'canJobNoTouch', False), 1386 ('maintain-timestamp', 'canJobNoTouch', False),
1348 ('slave-checkout', 'forceAsSlave', False), 1387 ('slave-checkout', 'forceAsSlave', False),
1349 ] 1388 ]
1350 convert_mapping_to_xml(scm, data, mapping, fail_required=True) 1389 helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
1351 1390
1352 # Folders to monitor. Default '/' 1391 # Folders to monitor. Default '/'
1353 folders = XML.SubElement(scm, 'folders') 1392 folders = XML.SubElement(scm, 'folders')
@@ -1372,7 +1411,8 @@ def dimensions(registry, xml_parent, data):
1372 ('timezone', 'jobTimeZone', None), 1411 ('timezone', 'jobTimeZone', None),
1373 ('web-url', 'jobWebUrl', None), 1412 ('web-url', 'jobWebUrl', None),
1374 ] 1413 ]
1375 convert_mapping_to_xml(scm, data, optional_mapping, fail_required=False) 1414 helpers.convert_mapping_to_xml(
1415 scm, data, optional_mapping, fail_required=False)
1376 1416
1377 1417
1378def accurev(registry, xml_parent, data): 1418def accurev(registry, xml_parent, data):
@@ -1421,7 +1461,7 @@ def accurev(registry, xml_parent, data):
1421 ('build-from-snapshot', 'useSnapshot', False), 1461 ('build-from-snapshot', 'useSnapshot', False),
1422 ('do-not-pop-content', 'dontPopContent', False), 1462 ('do-not-pop-content', 'dontPopContent', False),
1423 ] 1463 ]
1424 convert_mapping_to_xml(scm, data, mapping, fail_required=True) 1464 helpers.convert_mapping_to_xml(scm, data, mapping, fail_required=True)
1425 1465
1426 additional_mapping = [ 1466 additional_mapping = [
1427 ('workspace', 'workspace', None), 1467 ('workspace', 'workspace', None),
@@ -1431,7 +1471,8 @@ def accurev(registry, xml_parent, data):
1431 ('filter-poll-scm', 'filterForPollSCM', None), 1471 ('filter-poll-scm', 'filterForPollSCM', None),
1432 ('snapshot-name-format', 'snapshotNameFormat', None), 1472 ('snapshot-name-format', 'snapshotNameFormat', None),
1433 ] 1473 ]
1434 convert_mapping_to_xml(scm, data, additional_mapping, fail_required=False) 1474 helpers.convert_mapping_to_xml(
1475 scm, data, additional_mapping, fail_required=False)
1435 1476
1436 1477
1437class SCM(jenkins_jobs.modules.base.Base): 1478class SCM(jenkins_jobs.modules.base.Base):
@@ -1486,11 +1527,14 @@ class PipelineSCM(jenkins_jobs.modules.base.Base):
1486 raise JenkinsJobsException("'scm' missing or empty") 1527 raise JenkinsJobsException("'scm' missing or empty")
1487 elif scms_count == 1: 1528 elif scms_count == 1:
1488 self.registry.dispatch('scm', definition_parent, scms[0]) 1529 self.registry.dispatch('scm', definition_parent, scms[0])
1489 mapping = [('script-path', 'scriptPath', 'Jenkinsfile'), 1530 mapping = [
1490 ('lightweight-checkout', 'lightweight', None, 1531 ('script-path', 'scriptPath', 'Jenkinsfile'),
1491 [True, False])] 1532 ('lightweight-checkout', 'lightweight', None,
1492 convert_mapping_to_xml(definition_parent, pipeline_dict, 1533 [True, False]),
1493 mapping, fail_required=False) 1534 ]
1535 helpers.convert_mapping_to_xml(
1536 definition_parent, pipeline_dict, mapping,
1537 fail_required=False)
1494 else: 1538 else:
1495 raise JenkinsJobsException('Only one SCM can be specified ' 1539 raise JenkinsJobsException('Only one SCM can be specified '
1496 'as pipeline-scm') 1540 'as pipeline-scm')