@@ -243,20 +243,6 @@ def clone(url, path=None, depth=None, protocol=None):
243
243
except Exception as e :
244
244
error (e [1 ], e [0 ])
245
245
246
- def add (dest ):
247
- return True
248
-
249
- def remove (dest ):
250
- if os .path .isfile (dest ):
251
- os .remove (dest )
252
- return True
253
-
254
- def commit ():
255
- error ("mbed library builds do not support committing" )
256
-
257
- def publish (all = None ):
258
- return False
259
-
260
246
def fetch (url , rev ):
261
247
tmp_file = '.rev-' + rev + '.zip'
262
248
arch_dir = 'mbed-' + rev
@@ -379,10 +365,6 @@ def remove(dest):
379
365
popen ([hg_cmd , 'rm' , '-f' , dest ] + (['-v' ] if verbose else ['-q' ]))
380
366
except ProcessException :
381
367
pass
382
- try :
383
- os .remove (dest )
384
- except OSError :
385
- pass
386
368
387
369
def commit ():
388
370
popen ([hg_cmd , 'commit' ] + (['-v' ] if verbose else ['-q' ]))
@@ -552,10 +534,6 @@ def remove(dest):
552
534
popen ([git_cmd , 'rm' , '-f' , dest ] + ([] if verbose else ['-q' ]))
553
535
except ProcessException :
554
536
pass
555
- try :
556
- os .remove (dest )
557
- except OSError :
558
- pass
559
537
560
538
def commit ():
561
539
popen ([git_cmd , 'commit' , '-a' ] + (['-v' ] if verbose else ['-q' ]))
@@ -803,20 +781,26 @@ def fromlib(cls, lib=None):
803
781
@classmethod
804
782
def fromrepo (cls , path = None ):
805
783
repo = cls ()
784
+ repo .is_cwd = True
806
785
if path is None :
807
786
path = Repo .findrepo (os .getcwd ())
808
- if path is None :
809
- error (
810
- "Cannot find the program or library in the current path \" %s\" .\n "
811
- "Please change your working directory to a different location or use \" mbed new\" to create a new program." % os .getcwd (), 1 )
787
+ if path :
788
+ repo .is_cwd = False
789
+ else :
790
+ path = os .getcwd ()
791
+ warning (
792
+ "Could not find mbed program in current path. Assuming current dir.\n "
793
+ "You can fix this by calling \" mbed new .\" in the root of your program" )
812
794
813
795
repo .path = os .path .abspath (path )
814
796
repo .name = os .path .basename (repo .path )
815
797
816
798
repo .sync ()
817
799
818
- if repo .scm is None :
819
- error ("Current folder is not a supported repository" , - 1 )
800
+ if not repo .is_cwd and repo .scm is None :
801
+ warning (
802
+ "Program \" %s\" in \" %s\" does not use source control management.\n "
803
+ "To fix this you should use \" mbed new .\" in the root of your program." % (repo .name , repo .path ))
820
804
821
805
return repo
822
806
@@ -833,7 +817,7 @@ def findrepo(cls, path=None):
833
817
path = os .path .abspath (path or os .getcwd ())
834
818
835
819
while cd (path ):
836
- if Repo .isrepo (path ):
820
+ if os . path . isfile ( os . path . join ( path , Program . config_file )) or Repo .isrepo (path ):
837
821
return path
838
822
839
823
tpath = path
@@ -887,7 +871,7 @@ def sync(self):
887
871
if os .path .isdir (self .path ):
888
872
try :
889
873
self .scm = self .getscm ()
890
- if self .scm .name == 'bld' :
874
+ if self .scm and self . scm .name == 'bld' :
891
875
self .is_build = True
892
876
except ProcessException :
893
877
pass
@@ -931,8 +915,13 @@ def getrev(self, *args, **kwargs):
931
915
def add (self , * args , ** kwargs ):
932
916
return self .__scm_call ('add' , * args , ** kwargs )
933
917
934
- def remove (self , * args , ** kwargs ):
935
- return self .__scm_call ('remove' , * args , ** kwargs )
918
+ def remove (self , dest , * args , ** kwargs ):
919
+ if os .path .isfile (dest ):
920
+ try :
921
+ os .remove (dest )
922
+ except OSError :
923
+ pass
924
+ return self .__scm_call ('remove' , dest , * args , ** kwargs )
936
925
937
926
def ignores (self , * args , ** kwargs ):
938
927
return self .__scm_call ('ignores' , * args , ** kwargs )
@@ -1050,31 +1039,27 @@ class Program(object):
1050
1039
1051
1040
def __init__ (self , path = None , print_warning = False ):
1052
1041
path = os .path .abspath (path or os .getcwd ())
1053
-
1054
- self .path = os .getcwd ()
1042
+ self .path = path
1055
1043
self .is_cwd = True
1056
1044
1057
1045
while cd (path ):
1058
1046
tpath = path
1059
- if Repo . isrepo ( path ):
1047
+ if os . path . isfile ( os . path . join ( path , Program . config_file ) ):
1060
1048
self .path = path
1061
1049
self .is_cwd = False
1062
- self .is_repo = True
1050
+ break
1051
+
1063
1052
path = os .path .split (path )[0 ]
1064
1053
if tpath == path : # Reached root.
1065
1054
break
1066
1055
1067
1056
self .name = os .path .basename (self .path )
1068
1057
1069
1058
# is_cwd flag indicates that current dir is assumed to be root, not root repo
1070
- if self .is_cwd :
1071
- err = (
1059
+ if self .is_cwd and print_warning :
1060
+ warning (
1072
1061
"Could not find mbed program in current path. Assuming current dir.\n "
1073
- "You can fix this by calling \" mbed new .\" in the root dir of your program" )
1074
- if print_warning :
1075
- warning (err )
1076
- else :
1077
- error (err , 1 )
1062
+ "You can fix this by calling \" mbed new .\" in the root of your program" )
1078
1063
1079
1064
# Sets config value
1080
1065
def set_cfg (self , var , val ):
@@ -1110,6 +1095,9 @@ def get_cfg(self, var, default_val=None):
1110
1095
return m .group (2 )
1111
1096
return default_val
1112
1097
1098
+ def set_root (self ):
1099
+ return self .set_cfg ('ROOT' , '.' )
1100
+
1113
1101
# Gets mbed OS dir (unified)
1114
1102
def get_os_dir (self ):
1115
1103
if os .path .isdir (os .path .join (self .path , 'mbed-os' )):
@@ -1296,19 +1284,19 @@ def new(name, scm='git', depth=None, protocol=None):
1296
1284
cwd_root = os .path .abspath (d_path )
1297
1285
1298
1286
program = Program (d_path )
1287
+ program .set_root ()
1299
1288
if not program .get_os_dir ():
1300
1289
try :
1301
1290
with cd (d_path ):
1302
- add (mbed_os_url , depth = depth , protocol = protocol )
1291
+ add (mbed_os_url , depth = depth , protocol = protocol , top = False )
1303
1292
except Exception as e :
1304
1293
if os .path .isdir (os .path .join (d_path , 'mbed-os' )):
1305
1294
rmtree_readonly (os .path .join (d_path , 'mbed-os' ))
1306
1295
raise e
1307
1296
if d_path :
1308
1297
os .chdir (d_path )
1309
1298
1310
- program = Program (d_path )
1311
- program .post_action ()
1299
+ Program (d_path ).post_action ()
1312
1300
1313
1301
1314
1302
# Import command
@@ -1343,9 +1331,13 @@ def import_(url, path=None, ignore=False, depth=None, protocol=None, top=True):
1343
1331
for _ , scm in sorted_scms :
1344
1332
try :
1345
1333
scm .clone (repo .url , repo .path , depth = depth , protocol = protocol )
1334
+ repo .scm = scm
1335
+ repo .ignores ()
1336
+
1346
1337
with cd (repo .path ):
1338
+ Program (repo .path ).set_root ()
1347
1339
try :
1348
- scm .update (repo .rev , True )
1340
+ repo .update (repo .rev , True )
1349
1341
except ProcessException as e :
1350
1342
err = "Unable to update \" %s\" to %s" % (repo .name , repo .revtype (repo .rev , True ))
1351
1343
if depth :
@@ -1374,8 +1366,7 @@ def import_(url, path=None, ignore=False, depth=None, protocol=None, top=True):
1374
1366
deploy (ignore = ignore , depth = depth , protocol = protocol , top = False )
1375
1367
1376
1368
if top :
1377
- program = Program (repo .path )
1378
- program .post_action ()
1369
+ Program (repo .path ).post_action ()
1379
1370
1380
1371
1381
1372
# Deploy command
@@ -1398,8 +1389,7 @@ def deploy(ignore=False, depth=None, protocol=None, top=True):
1398
1389
repo .ignore (relpath (repo .path , lib .path ))
1399
1390
1400
1391
if top :
1401
- program = Program (repo .path )
1402
- program .post_action ()
1392
+ Program (repo .path ).post_action ()
1403
1393
1404
1394
1405
1395
# Add library command
@@ -1410,7 +1400,7 @@ def deploy(ignore=False, depth=None, protocol=None, top=True):
1410
1400
dict (name = '--depth' , nargs = '?' , help = 'Number of revisions to fetch from the remote repository. Default: all revisions.' ),
1411
1401
dict (name = '--protocol' , nargs = '?' , help = 'Transport protocol for the source control management. Supported: https, http, ssh, git. Default: inferred from URL.' ),
1412
1402
help = 'Add a library and its dependencies into the current %s or specified destination path.' % cwd_type )
1413
- def add (url , path = None , ignore = False , depth = None , protocol = None ):
1403
+ def add (url , path = None , ignore = False , depth = None , protocol = None , top = True ):
1414
1404
repo = Repo .fromrepo ()
1415
1405
1416
1406
lib = Repo .fromurl (url , path )
@@ -1421,6 +1411,9 @@ def add(url, path=None, ignore=False, depth=None, protocol=None):
1421
1411
lib .write ()
1422
1412
repo .add (lib .lib )
1423
1413
1414
+ if top :
1415
+ Program (repo .path ).post_action ()
1416
+
1424
1417
1425
1418
# Remove library
1426
1419
@subcommand ('remove' ,
@@ -1432,6 +1425,7 @@ def remove(path):
1432
1425
error ("Could not find library in path (%s)" % path , 1 )
1433
1426
1434
1427
lib = Repo .fromrepo (path )
1428
+ action ("Removing library \" %s\" in \" %s\" " % (lib .name , lib .path ))
1435
1429
rmtree_readonly (lib .path )
1436
1430
repo .remove (lib .lib )
1437
1431
repo .unignore (relpath (repo .path , lib .path ))
@@ -1569,8 +1563,7 @@ def update(rev=None, clean=False, force=False, ignore=False, top=True, depth=Non
1569
1563
update (lib .rev , clean , force , ignore = ignore , top = False )
1570
1564
1571
1565
if top :
1572
- program = Program (repo .path )
1573
- program .post_action ()
1566
+ Program (repo .path ).post_action ()
1574
1567
1575
1568
1576
1569
# Synch command
0 commit comments