Morpheus / Mbed OS mbed-Client-Morpheus-hg

Dependencies:   mbed-os

Revision:
42:58b35941ebd0
Parent:
41:59e9d808ee05
Child:
43:8a4a902a0654
--- a/neo.py	Wed Mar 30 15:34:56 2016 -0500
+++ b/neo.py	Wed Mar 30 16:10:42 2016 -0500
@@ -85,11 +85,15 @@
 @scm('hg')
 @staticclass
 class Hg(object):
-    exclude = '.hg/exclude'
-
     def clone(url, name=None, hash=None):
         popen(['hg', 'clone', url, name] + (['-u', hash] if hash else []))
 
+        # add exclude file
+        with cd(name):
+            with open('.hg/hgrc', 'a') as f:
+                f.write('[ui]\n')
+                f.write('ignore.local = .hg/exclude\n')
+
     def add(file): popen(['hg', 'add', file])
     def remove(file):
         popen(['hg', 'rm', '-f', file])
@@ -107,11 +111,30 @@
     def hash(): return pquery(['hg', 'id', '-i']).strip().strip('+')
     def dirty(): return pquery(['hg', 'status', '-q'])
 
+    def ignore(regex):
+        exclude = '.hg/exclude'
+        with open(exclude, 'a') as f:
+            f.write(regex + '\n')
+
+    def unignore(regex):
+        exclude = '.hg/exclude'
+        if not os.path.isfile(exclude):
+            return
+
+        with open(exclude) as f:
+            lines = f.read().splitlines()
+
+        if regex not in lines:
+            return
+
+        lines.remove(regex)
+
+        with open(exclude, 'w') as f:
+            f.write('\n'.join(lines) + '\n')
+
 @scm('git')
 @staticclass
 class Git(object):
-    exclude = '.git/info/exclude'
-
     def clone(url, name=None, hash=None):
         popen(['git', 'clone', url, name])
         if hash:
@@ -131,8 +154,25 @@
     def dirty(): return pquery(['git', 'diff', '--name-only', 'HEAD'])
 
     def ignore(regex):
-        with open('.git/info/exclude', 'a') as f:
-            f.write(regex)
+        exclude = '.git/info/exclude'
+        with open(exclude, 'a') as f:
+            f.write(regex + '\n')
+
+    def unignore(regex):
+        exclude = '.git/info/exclude'
+        if not os.path.isfile(exclude):
+            return
+
+        with open(exclude) as f:
+            lines = f.read().splitlines()
+
+        if regex not in lines:
+            return
+
+        lines.remove(regex)
+
+        with open(exclude, 'w') as f:
+            f.write('\n'.join(lines) + '\n')
 
 
 # Repository object
@@ -240,7 +280,7 @@
     with cd(repo.path):
         for lib in repo.libs:
             import_(lib.url, lib.path)
-            #repo.scm.ignore(lib.path)
+            repo.scm.ignore(lib.path[len(repo.path)+1:])
 
         if (not os.path.isfile('mbed_settings.py') and 
             os.path.isfile('mbed-os/tools/settings.py')):
@@ -253,6 +293,7 @@
     repo = Repo.fromrepo()
     for lib in repo.libs:
         import_(lib.url, lib.path)
+        repo.scm.ignore(lib.path[len(repo.path)+1:])
 
 # Install/uninstall command
 @subcommand('add', 'url', 'name?',
@@ -262,11 +303,11 @@
 
     lib = Repo.fromurl(url, path)
     import_(lib.url, lib.path)
+    repo.scm.ignore(lib.path[len(repo.path)+1:])
     lib.synch()
 
     lib.write()
     repo.scm.add(lib.lib)
-    #repo.scm.ignore(lib.path)
 
 @subcommand('remove', 'path',
     help='remove a library from the current repository folder')
@@ -276,6 +317,7 @@
 
     repo.scm.remove(lib.lib)
     shutil.rmtree(lib.path)
+    repo.scm.unignore(lib.path[len(repo.path)+1:])
 
 # Publish command
 @subcommand('publish',
@@ -317,15 +359,17 @@
                     sys.exit(1)
 
             shutil.rmtree(lib.path)
+            repo.scm.unignore(lib.path[len(repo.path)+1:])
 
     repo.synch()
 
     for lib in repo.libs:
-        if os.path.isdir(lib.path):
+        if not os.path.isdir(lib.path):
+            import_(lib.url, lib.path)
+            repo.scm.ignore(lib.path[len(repo.path)+1:])
+        else:
             with cd(lib.path):
                 update(lib.hash)
-        else:
-            import_(lib.url, lib.path)
 
 # Synch command
 @subcommand('synch',