Commits

Crispin Wellington  committed 42c9cf7

rewrite venv_cache to be RemoteCache object

  • Participants
  • Parent commits 26388d9
  • Branches virtualenv-caching

Comments (0)

Files changed (1)

File parcel/deploy/deploy.py

 import os.path
 
 from fabric.api import settings, run, cd, lcd, put, get, local, env, with_settings
-from fabric.contrib import files
 from fabric.colors import green
 
 from .. import versions
 from .. import distro
 from .. import tools
+from .. import cache
 from ..requirements import Requirements
 
 class Deployment(object):
 
         self.pkg_name = app_name.lower()
         self.root_path = os.path.join(self.base_path,"root")                    # where the final root fs is located
-        self.venv_cache = os.path.join(self.base_path,"venvs")                  # where we cache successfuly built venvs
+        self.venv_cache = cache.RemoteCache(os.path.join(self.base_path,"venvs"))                  # where we cache successfuly built venvs
 
         # the path the app will be installed into
         self.app_path = os.path.join(base,'%s-%s'%(self.pkg_name,self.version))
                 req = Requirements(reqfile)
                 sha = req.hash()
         
-                # are we cached?
-                if files.exists('{0.venv_cache}/{sha}'.format(self, sha=sha)):
-                    self._restore_venv(requirements)
+                if self.venv_cache.is_cached(sha):
+                    self._restore_venv(req)
 
                 else:
-                    # add the virtual env
-                    self._add_venv(requirements)
-
-                    # successful venv... lets cache by hardlink copy
-                    run('cp -Rl {0.venv_root} {0.venv_cache}/{sha}'.format(self, sha=sha))
+                    # if adding the venv works lets cache
+                    self.venv_cache.store(self._add_venv(req))
             else:
-                self._add_venv(requirements)
-                
+                self._add_venv(Requirements())
             
     def add_to_root_fs(self,localfile,remotepath):
         """Add a local file to the root package path.
         print self.build_path
         tools.rsync([self.path+'/'],self.build_path,rsync_ignore='.rsync-ignore')
 
-    def _add_venv(self,requirements="requirements.txt"):
+    def _add_venv(self,requirements=None):
         """Builds virtualenv on remote host and installs from requirements.txt.
         
         :param requirements: The name of the requirements.txt file relative to the path setting used in the constructor.
         """
+        if type(requirements) in (str,unicode):
+            requirements = Requirements(requirements)
+        else:
+            requirements = requirements or Requirements()
         self.venv_path = os.path.join(self.build_path, self.virtual)
         run('virtualenv %s'%(self.venv_path))
-        if requirements and os.path.exists(os.path.join(self.path, requirements)):
+        print "<<<",requirements,">>>"
+        if requirements.base:
             run('PIP_DOWNLOAD_CACHE="%s" %s install -r %s'%(
-                self.arch.pip_download_cache,
+                    self.arch.pip_download_cache,
 	            os.path.join(self.venv_path, 'bin/pip'),
-	            os.path.join(self.build_path, requirements))
-            )
+	        os.path.join(self.build_path, requirements.base)))
             
         # venv_root is final path
         self.venv_root = os.path.join(self.app_path, self.virtual)
         
         # and we have the virtualenv executable
         self.run_deps.append('python-virtualenv')
+
+        return self.venv_root