Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

Commit ae58791

Browse files
author
Simon Rowe
committed
clone: Jenkins form should only process terminal resource
When the --jenkins argument is given the output should only contain the final repository, e.g. the patchqueue. Refactor to simplify the Jenkins vs clone usecases. Signed-off-by: Simon Rowe <simon.rowe@eu.citrix.com>
1 parent ba2a2d8 commit ae58791

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

planex/cmd/clone.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ def repo_name(url):
6060
""")
6161

6262

63-
def clone_jenkins_json(filename, gathered):
64-
"""Print json file containing repositories to clone"""
63+
def clone_jenkins_json(filename, url, commitish):
64+
"""Print JSON file containing repositories to clone"""
6565
json_dict = {}
6666
if exists(filename):
6767
with open(filename, "r") as clone_sources:
6868
json_dict.update(json.load(clone_sources))
69-
for url, commitish in gathered:
70-
json_dict[repo_name(url)] = {'URL': url, 'commitish': commitish}
69+
json_dict[repo_name(url)] = {'URL': url, 'commitish': commitish}
7170
with open(filename, "w") as clone_sources:
72-
clone_sources.write(json.dumps(json_dict))
71+
clone_sources.write(json.dumps(json_dict, indent=2, sort_keys=True))
72+
print(file=clone_sources)
7373

7474

7575
def clone_jenkins_groovy(destination, credentials, url, commitish):
@@ -151,8 +151,7 @@ def apply_patchqueue(base_repo, pq_repo, pq_dir):
151151

152152
def clone_all(args, pin, nodetached=False):
153153
"""
154-
If [args.jenkins] prints the clone string for jenkins else
155-
it clones all the clonable sources into [args.repos].
154+
Clone all the resources described by a pin.
156155
"""
157156
# The following assumes that the pin file does not use any
158157
# rpm macro in its fields. We can enable them by using
@@ -171,7 +170,7 @@ def clone_all(args, pin, nodetached=False):
171170
for gath in gathered)
172171

173172
if gathered:
174-
print('echo "Clones for %s"' % basename(pin.linkpath))
173+
print('\nClones for %s' % basename(pin.linkpath))
175174

176175
# this is suboptimal but the sets are very small
177176
if any(commitish1 != commitish2
@@ -181,24 +180,34 @@ def clone_all(args, pin, nodetached=False):
181180
sys.exit("error: cloning two git repositories with the same "
182181
"name but different commitish is not supported.")
183182

184-
if args.jenkins and args.credentials is None:
185-
clone_jenkins_json(args.output, gathered)
186-
else:
187-
for url, commitish in gathered:
188-
print('echo "Cloning %s#%s"' % (url, commitish))
189-
if args.jenkins and args.credentials:
190-
if args.jenkins and args.credentials:
191-
clone_jenkins_groovy(args.repos,
192-
args.credentials,
193-
url,
194-
commitish)
183+
for url, commitish in gathered:
184+
print('Cloning %s#%s' % (url, commitish))
185+
util.makedirs(args.repos)
186+
try:
187+
clone(url, args.repos, commitish, nodetached)
188+
except git.GitCommandError as gce:
189+
print(gce.stderr)
190+
191+
192+
def clone_jenkins(args, pin):
193+
"""
194+
Generate either a JSON object or a Groovy fragment that describes
195+
the terminal resource of a pin.
196+
"""
197+
for resource in (pin.patchqueue_sources, pin.archives, pin.sources):
198+
if resource:
199+
url = resource.values()[0]['URL']
200+
commitish = resource.values()[0]['commitish']
201+
202+
if args.credentials:
203+
# output Groovy fragment
204+
print('echo "Cloning %s#%s"' % (url, commitish))
205+
clone_jenkins_groovy(args.repos, args.credentials, url,
206+
commitish)
195207
else:
196-
# clone is assumed for all other flags
197-
util.makedirs(args.repos)
198-
try:
199-
clone(url, args.repos, commitish, nodetached)
200-
except git.GitCommandError as gce:
201-
print(gce.stderr)
208+
# output JSON object
209+
clone_jenkins_json(args.output, url, commitish)
210+
break
202211

203212

204213
def assemble_patchqueue(args, pin):
@@ -340,8 +349,10 @@ def main(argv=None):
340349
for pinpath in args.pins:
341350
pin = Link(pinpath)
342351

343-
if args.clone or args.jenkins:
352+
if args.clone:
344353
clone_all(args, pin)
354+
if args.jenkins:
355+
clone_jenkins(args, pin)
345356
else:
346357
if "PatchQueue0" in pin.patchqueue_sources:
347358
if "Archive0" in pin.archives:

0 commit comments

Comments
 (0)