Commits

lakin.wecker  committed f9fbd50 Merge

merging witht he deployment stuff I did on a different machine.

  • Participants
  • Parent commits cbb3834, 36a70aa

Comments (0)

Files changed (1)

File baste/__init__.py

 """
 from __future__ import with_statement
 
+import datetime
 import os.path
 
 from fabric.api import (
         hide,
         lcd,
         local,
+        run,
         settings,
     )
 from fabric import colors
+from fabric.contrib.project import rsync_project
 
 try:
     from collections import OrderedDict
     'python_dependency',
     'Repository',
     'RsyncMedia',
+    'RsyncDeployment',
     'StatusCommand',
     'Subversion',
 ]
         """
         local("rsync --progress -avz --exclude=\".svn/*\" --exclude=\".svn\" -e ssh %s:%s %s" % (self.host, self.remote_directory, self.local_directory))
 
+REPO_EXCLUDES = ['.svn', '.git', '.hg', '.hgignore', 'fabfile.py', '*.pyc', 'env']
+#-------------------------------------------------------------------------------
+class RsyncDeployment(object):
+    """
+    An rsync deployment consists of a single steps:
+        1. the local_directory is rsync'ed to the remote_directory/source
+        2. an cp command will be run that cps remote_directory/source to
+           remote_directory/<current_date_time>
+        3. a remote command is run to symlink remote_directory/current to
+           remote_directory/<current_date_time>
+        4. It is then up to the caller to run the command to reload the server
+
+    Please note that this command WILL delete files on the remote_director/source
+    """
+    #---------------------------------------------------------------------------
+    def __init__(self, remote_directory, local_directory):
+        self.remote_directory = remote_directory
+        self.local_directory = local_directory
+
+    #---------------------------------------------------------------------------
+    def __call__(self):
+        """
+        Uses the psql command to give someone a shell within the db.
+        """
+        source_directory = os.path.join(self.remote_directory, "source")
+        current_symlink = os.path.join(self.remote_directory, "current")
+        tmp_symlink = os.path.join(self.remote_directory, "current_tmp")
+        date_directory = os.path.join(
+                self.remote_directory,
+                datetime.datetime.now().strftime("%Y-%m-%dT%H%M%S")
+            )
+        rsync_project(
+                remote_dir=source_directory,
+                local_dir=self.local_directory,
+                exclude=REPO_EXCLUDES,
+                delete=True,
+            )
+        run("cp -r %s %s" % (source_directory, date_directory))
+        run("ln -sf %s %s; mv -Tf %s %s" % (date_directory, tmp_symlink, tmp_symlink, current_symlink))
+
+
 #-------------------------------------------------------------------------------
 class UbuntuPgCreateDbAndUser(object):
     #---------------------------------------------------------------------------