Commits

Steve Losh committed 2a11876

guts: Implement grabbing for Mercurial sources! Yay!

  • Participants
  • Parent commits ff5745f

Comments (0)

Files changed (4)

lib/gorilla/guts/catalog.py

     def scripts(self):
         return self.module.__dict__.get('scripts', [])
     
+    @property
+    def sources(self):
+        return self.module.__dict__.get('sources', [])
+    
 
 def all_cards():
     """Return a generator for all Cards in the catalog."""

lib/gorilla/guts/cli.py

             ui.write('Already present, retrieving updates ...\n')
         else:
             ui.write('Not present, downloading a full copy ...\n')
+        
+        shelf.grab()
     
 
 _options_grab = {

lib/gorilla/guts/repo.py

+import subprocess
+
 class MercurialRepo(object):
-    pass
+    def __init__(self, path, sources):
+        self.path = path
+        self.sources = sources['hg']
+    
+    def clone(self):
+        command = ['hg', 'clone', self.sources[0], self.path, '--noupdate']
+        
+        rc = subprocess.call(command, shell=False)
+        return rc == 0
+    
+    def pull(self):
+        command = ['hg', 'pull', '-R', self.path, self.sources[0]]
+        
+        rc = subprocess.call(command, shell=False)
+        return rc == 0
+    

lib/gorilla/guts/shelf.py

 import os
 from gorilla.guts import util
 from gorilla.guts.catalog import Card
+from gorilla.guts.repo import MercurialRepo
 
 
 class Shelf(object):
     def __init__(self, card):
         self.card = card
         self.path = os.path.join(util.SHELF_PATH, self.card.name)
+        
+        if not self.vcs:
+            Repo = MercurialRepo
+        elif self.vcs == 'hg':
+            Repo = MercurialRepo
+        elif self.vcs == 'git':
+            # Repo = GitRepo
+            pass
+        elif self.vcs == 'static':
+            # Repo = StaticRepo
+            pass
+        
+        self.repo = Repo(path=self.path, sources=self.card.sources)
+    
     
     @property
     def present(self):
         return os.path.isdir(self.path)
     
+    
     @property
     def vcs(self):
         if not self.present:
         else:
             return 'static'
     
+    
     @property
     def installed(self):
         packages = [os.path.join(util.LIB_PATH, p) for p in self.card.packages]
         
         return packages_installed and scripts_installed
     
+    
+    def grab(self):
+        """Download the latest version of the package (clone if necessary).
+        
+        This does *not* update the working directory if the shelf is already
+        present at the start.
+        
+        """
+        if not os.path.exists(util.SHELF_PATH):
+            os.mkdir(util.SHELF_PATH)
+        
+        if not self.present:
+            self.repo.clone()
+        else:
+            self.repo.pull()
+