1. lakin.wecker
  2. baste

Commits

lakin.wecker  committed 7cc146d

updating the mercurial and subversion repository commands to ensure that the repository is the correct type before running an up command. Also updating the python_dependency command to better do symlinks.

  • Participants
  • Parent commits 0ad5497
  • Branches default

Comments (0)

Files changed (1)

File baste/__init__.py

View file
  • Ignore whitespace
             baste_env.run(cmd)
 
 #-------------------------------------------------------------------------------
+class RepositoryMismatch(RuntimeError):
+    """
+    Indicates that the repository that is being updated is of a different type.
+    """
+
+#-------------------------------------------------------------------------------
 class Subversion(Repository):
     """Represents a subversion repository."""
     #---------------------------------------------------------------------------
         return "svn co %s %s" % (self.url, self.directory)
 
     #---------------------------------------------------------------------------
+    def _ensure_subversion(self):
+        dot_svn = os.path.join(self.directory, ".svn")
+        if os.path.exists(self.directory) and not os.path.exists(dot_svn):
+            raise RepositoryMismatch(
+                    ("%s is not an svn checkout. "
+                    "Double check you have no uncommitted/unpushed changes "
+                    "and then remove this directory and fab up again.") % self.directory
+                )
+
+    #---------------------------------------------------------------------------
     def update_command(self):
+        self._ensure_subversion()
         return "svn up %s" % (self.directory)
 
     #---------------------------------------------------------------------------
     def status_command(self):
+        self._ensure_subversion()
         return "svn st %s" % (self.directory)
 
     #---------------------------------------------------------------------------
     def diff_command(self):
+        self._ensure_subversion()
         return "svn diff %s" % (self.directory)
 
 #-------------------------------------------------------------------------------
         return "hg clone %s %s" % (self.url, self.directory)
 
     #---------------------------------------------------------------------------
+    def _ensure_mercurial(self):
+        dot_hg = os.path.join(self.directory, ".hg")
+        if os.path.exists(self.directory) and not os.path.exists(dot_hg):
+            raise RepositoryMismatch(
+                    ("%s is not an hg clone. "
+                    "Double check you have no uncommitted/unpushed changes "
+                    "and then remove this directory and fab up again.") % self.directory
+                )
+    #---------------------------------------------------------------------------
     def update_command(self):
+        self._ensure_mercurial()
         return "hg -R %s pull -u" % (self.directory)
 
     #---------------------------------------------------------------------------
     def status_command(self):
+        self._ensure_mercurial()
         return "hg -R %s status" % (self.directory)
 
     #---------------------------------------------------------------------------
     def diff_command(self):
+        self._ensure_mercurial()
         return "hg -R %s diff" % (self.directory)
 
 #-------------------------------------------------------------------------------
 #-------------------------------------------------------------------------------
 def python_dependency(package, python_version, dir=None):
     """Adds the given package as a dependency for the given python version."""
+
+    # Figure out the directory we'll be symlinking to.
     if dir is None:
-        dir = package
+        base_dir = project_relative(package)
+        if os.path.exists(os.path.join(base_dir, "__init__.py")):
+            dir = base_dir
+        elif os.path.exists(os.path.join(base_dir, package, "__init__.py")):
+            dir = os.path.join(base_dir, package)
+
     symlink = "env/lib/%s/%s" % (python_version, package)
     symlink = project_relative(symlink)
-    python_path = os.path.abspath(dir)
+    python_path = dir
     create_symbolic_link = "ln -s %s %s" % (python_path, symlink)
     print(colors.green("[install] ") + package)
     with hide('running'):