@@ -183,6 +183,8 @@ def process(self, repo_path, mode='add'):
183
183
* return (int): return code == 0 if no error and >0 if error
184
184
* (error) (str): error string if return>0
185
185
186
+ * (warnings) (list of str): warnings to install more CM repositories
187
+
186
188
"""
187
189
188
190
# Load clean file with repo paths
@@ -193,43 +195,71 @@ def process(self, repo_path, mode='add'):
193
195
194
196
modified = False
195
197
198
+ warnings = []
199
+
196
200
if mode == 'add' :
197
201
if repo_path not in paths :
198
- if len (paths )> 0 :
199
- # Load meta of the current repo
200
- path_to_repo_desc = os .path .join (repo_path , self .cfg ['file_meta_repo' ])
201
- r = utils .load_yaml_and_json (file_name_without_ext = path_to_repo_desc )
202
+ # Load meta of the current repo
203
+ path_to_repo_desc = os .path .join (repo_path , self .cfg ['file_meta_repo' ])
204
+
205
+ r = utils .load_yaml_and_json (file_name_without_ext = path_to_repo_desc )
206
+ if r ['return' ]> 0 : return r
207
+
208
+ meta = r ['meta' ]
209
+
210
+ alias = meta .get ('alias' , '' )
211
+ uid = meta .get ('uid' , '' )
212
+
213
+ deps_on_other_repos = meta .get ('deps' , {})
214
+
215
+ # Check that no repos exist with the same alias and/or uid
216
+ # (to avoid adding forks and original repos)
217
+
218
+ for path in paths :
219
+ path_to_existing_repo_desc = os .path .join (path , self .cfg ['file_meta_repo' ])
220
+ r = utils .load_yaml_and_json (file_name_without_ext = path_to_existing_repo_desc )
202
221
if r ['return' ]> 0 : return r
203
222
204
- meta = r ['meta' ]
223
+ existing_meta = r ['meta' ]
205
224
206
- alias = meta .get ('alias' , '' )
207
- uid = meta .get ('uid' , '' )
225
+ existing_alias = existing_meta .get ('alias' , '' )
226
+ existing_uid = existing_meta .get ('uid' , '' )
208
227
209
- # Check that no repos exist with the same alias and/or uid
210
- # (to avoid adding forks and original repos)
228
+ # Check if repository already exists under different name
229
+ exist = False
230
+ if alias != '' and existing_alias != '' and alias == existing_alias :
231
+ exist = True
211
232
212
- for path in paths :
213
- path_to_existing_repo_desc = os .path .join (path , self .cfg ['file_meta_repo' ])
214
- r = utils .load_yaml_and_json (file_name_without_ext = path_to_existing_repo_desc )
215
- if r ['return' ]> 0 : return r
233
+ if not exist and uid != '' and existing_uid != '' and uid == existing_uid :
234
+ exist = True
216
235
217
- existing_meta = r ['meta' ]
236
+ if exist :
237
+ return {'return' :1 , 'error' :'CM repository with the same alias "{}" and/or uid "{}" already exists in {}' .format (alias , uid , path )}
218
238
219
- existing_alias = existing_meta .get ('alias' , '' )
220
- existing_uid = existing_meta .get ('uid' , '' )
239
+ # Check if there is a conflict
240
+ if len (deps_on_other_repos )> 0 :
241
+ for d in deps_on_other_repos :
242
+ d_alias = d .get ('alias' , '' )
243
+ d_uid = d .get ('uid' , '' )
221
244
222
- exist = False
223
- if alias != '' and existing_alias != '' and alias == existing_alias :
224
- exist = True
245
+ r = utils . match_objects ( existing_uid , existing_alias , d_uid , d_alias )
246
+ if r [ 'return' ] > 0 : return r
247
+ match = r [ 'match' ]
225
248
226
- if not exist and uid != '' and existing_uid != '' and uid == existing_uid :
227
- exist = True
249
+ if match :
250
+ if d .get ('conflict' , False ):
251
+ return {'return' :1 , 'error' :'Can\' t install this repository because it conflicts with the already installed one ({}) - you may need to remove it to proceed (cm rm repo {} --all)' .format (d_alias ,d_alias )}
228
252
229
- if exist :
230
- return {'return' :1 , 'error' :'CM repository with the same alias "{}" and/or uid "{}" already exists in {}' .format (alias , uid , path )}
253
+ d ['matched' ] = True
231
254
255
+ break
232
256
257
+
258
+ # Check if has missing deps on other CM repos
259
+ for d in deps_on_other_repos :
260
+ if not d .get ('conflict' , False ) and not d .get ('matched' , False ):
261
+ warnings .append ('You must install extra CM repository: cm pull repo {}' .format (d ['alias' ]))
262
+
233
263
paths .append (repo_path )
234
264
modified = True
235
265
@@ -249,7 +279,12 @@ def process(self, repo_path, mode='add'):
249
279
# Reload repos
250
280
self .load (init = True )
251
281
252
- return {'return' :0 }
282
+ rr = {'return' :0 }
283
+
284
+ if len (warnings )> 0 :
285
+ rr ['warnings' ] = warnings
286
+
287
+ return rr
253
288
254
289
############################################################
255
290
def pull (self , alias , url = '' , branch = '' , checkout = '' , console = False , desc = '' , prefix = '' , depth = None ,
@@ -280,6 +315,8 @@ def pull(self, alias, url = '', branch = '', checkout = '', console = False, des
280
315
281
316
* (meta) (dict): meta of the CM repository
282
317
318
+ * (warnings) (list of str): warnings to install more CM repositories
319
+
283
320
"""
284
321
285
322
# Prepare path
@@ -500,14 +537,21 @@ def pull(self, alias, url = '', branch = '', checkout = '', console = False, des
500
537
r = self .process (path_to_repo , 'add' )
501
538
if r ['return' ]> 0 : return r
502
539
540
+ warnings = r .get ('warnings' , [])
541
+
503
542
# Go back to original directory
504
543
os .chdir (cur_dir )
505
544
506
545
if console :
507
546
print ('' )
508
547
print ('CM alias for this repository: {}' .format (alias ))
509
548
510
- return {'return' :0 , 'meta' :meta }
549
+ rr = {'return' :0 , 'meta' :meta }
550
+
551
+ if len (warnings )> 0 : rr ['warnings' ] = warnings
552
+
553
+ return rr
554
+
511
555
512
556
############################################################
513
557
def init (self , alias , uid , path = '' , console = False , desc = '' , prefix = '' , only_register = False ):
@@ -534,6 +578,8 @@ def init(self, alias, uid, path = '', console = False, desc = '', prefix = '', o
534
578
* path_to_repo_desc (str): path to repository description
535
579
* path_to_repo_with_prefix (str): path to repository with prefix (== path_to_repo if prefix == "")
536
580
581
+ * (warnings) (list of str): warnings to install more CM repositories
582
+
537
583
"""
538
584
539
585
# Prepare path
@@ -612,10 +658,16 @@ def init(self, alias, uid, path = '', console = False, desc = '', prefix = '', o
612
658
r = self .process (path_to_repo , 'add' )
613
659
if r ['return' ]> 0 : return r
614
660
615
- return {'return' :0 , 'meta' :meta ,
616
- 'path_to_repo' : path_to_repo ,
617
- 'path_to_repo_desc' : path_to_repo_desc ,
618
- 'path_to_repo_with_prefix' : path_to_repo_with_prefix }
661
+ warnings = r .get ('warnings' , [])
662
+
663
+ rr = {'return' :0 , 'meta' :meta ,
664
+ 'path_to_repo' : path_to_repo ,
665
+ 'path_to_repo_desc' : path_to_repo_desc ,
666
+ 'path_to_repo_with_prefix' : path_to_repo_with_prefix }
667
+
668
+ if len (warnings )> 0 : rr ['warnings' ] = warnings
669
+
670
+ return rr
619
671
620
672
############################################################
621
673
def delete (self , lst , remove_all = False , console = False , force = False ):
0 commit comments