@@ -60,16 +60,16 @@ def repo_name(url):
60
60
""" )
61
61
62
62
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"""
65
65
json_dict = {}
66
66
if exists (filename ):
67
67
with open (filename , "r" ) as clone_sources :
68
68
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 }
71
70
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 )
73
73
74
74
75
75
def clone_jenkins_groovy (destination , credentials , url , commitish ):
@@ -151,8 +151,7 @@ def apply_patchqueue(base_repo, pq_repo, pq_dir):
151
151
152
152
def clone_all (args , pin , nodetached = False ):
153
153
"""
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.
156
155
"""
157
156
# The following assumes that the pin file does not use any
158
157
# rpm macro in its fields. We can enable them by using
@@ -171,7 +170,7 @@ def clone_all(args, pin, nodetached=False):
171
170
for gath in gathered )
172
171
173
172
if gathered :
174
- print ('echo "Clones for %s" ' % basename (pin .linkpath ))
173
+ print ('\n Clones for %s' % basename (pin .linkpath ))
175
174
176
175
# this is suboptimal but the sets are very small
177
176
if any (commitish1 != commitish2
@@ -181,24 +180,34 @@ def clone_all(args, pin, nodetached=False):
181
180
sys .exit ("error: cloning two git repositories with the same "
182
181
"name but different commitish is not supported." )
183
182
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 )
195
207
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
202
211
203
212
204
213
def assemble_patchqueue (args , pin ):
@@ -340,8 +349,10 @@ def main(argv=None):
340
349
for pinpath in args .pins :
341
350
pin = Link (pinpath )
342
351
343
- if args .clone or args . jenkins :
352
+ if args .clone :
344
353
clone_all (args , pin )
354
+ if args .jenkins :
355
+ clone_jenkins (args , pin )
345
356
else :
346
357
if "PatchQueue0" in pin .patchqueue_sources :
347
358
if "Archive0" in pin .archives :
0 commit comments