Commits

ltnooy committed b2b2136

Adding pay_attention_confirm

Comments (0)

Files changed (1)

baste/__init__.py

 
 import datetime
 import os.path
+import string
+import random
 
 from fabric.api import (
         env,
         run as remote_run,
         settings,
         sudo as remote_sudo,
+        prompt
     )
 from fabric import colors
 from fabric.contrib.project import rsync_project
         self.url = url
 
     #---------------------------------------------------------------------------
-    def status(self):
-        baste_env.run(self.status_command())
+    def status(self, capture=False):
+        return baste_env.run(self.status_command(), capture)
 
     #---------------------------------------------------------------------------
     def update(self):
         """
         local_run("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']
+REPO_EXCLUDES = ['.svn', '.git', '.hg', '.hgignore', 'fabfile.py', '*.pyc', 'env', '.swp']
 #-------------------------------------------------------------------------------
 class RsyncDeployment(object):
     """
-    An rsync deployment consists of a single steps:
+    An rsync deployment consists of the following 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>
             baste_env.sudo("createuser --createdb --pwprompt --no-superuser --no-createrole %s" %
                     self.db_user, user="postgres")
             baste_env.sudo("createdb -O %s %s" % (self.db_user, self.db_name), user="postgres")
+
+
+#-------------------------------------------------------------------------------
+def pay_attention_confirm(question, yes=None):
+    """Ask a user a question, require a unique answer for confirmation."""
+
+    if yes is None:
+        yes = ''.join([random.choice(string.letters) for x in range(3)])
+        yes = yes.lower()
+
+    response = prompt('%s [(%s) y/n]' % (question, yes)) 
+    if response == yes:
+        return True
+    return False
+