Browse Source

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

Zuul 9 months ago
parent
commit
b30a825e9b
1 changed files with 102 additions and 58 deletions
  1. 102
    58
      jenkins_jobs/modules/scm.py

+ 102
- 58
jenkins_jobs/modules/scm.py View File

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

Loading…
Cancel
Save