Commits

Brent Tubbs committed 13525c8

_write_file now uses sudo by default

Comments (0)

Files changed (1)

     env.local_root = silk.lib.get_root(os.getcwd())
     env.config = silk.lib.get_site_config(env.local_root)
     env.dts = datetime.datetime.now().strftime(DTS_FORMAT)
-    
+
     if len(env.roles) == 1:
         env.config.update(silk.lib.get_role_config(env.roles[0]))
     env.site = env.config['site']
     if 'gunicorn' in env.config:
         env.config['bind'] = env.config['gunicorn'].get('bind', env.default_bind)
     else:
-        env.config['bind'] = env.default_bind 
+        env.config['bind'] = env.default_bind
 
 _set_vars()
 
 # END UGLY MAGIC
 
 def _tmpfile():
-    """Generates a random filename on the remote host.  Useful for dumping
-    stdout to a file that you want to download or read later.  Assumes the
-    remote host has a /tmp directory."""
+    """Generates a random filename in /tmp.  Useful for dumping stdout to a
+    file that you want to download or read later.  Assumes the remote host has
+    a /tmp directory."""
     chars = "abcdefghijklmnopqrstuvwxyz1234567890"
     length = 20
     randompart = "".join([random.choice(chars) for x in xrange(20)])
     Return information about this deployment, to be written as the "blame"
     section in the site.yaml file.
     """
-    return {'deployed_by': env.user, 
+    return {'deployed_by': env.user,
             'deployed_from': os.uname()[1],
-            'deployed_at': datetime.datetime.now(), 
+            'deployed_at': datetime.datetime.now(),
             'deployed_role': env.roles[0]}
 
-def _write_file(path, contents, use_sudo=False, chown=None):
+def _write_file(path, contents, use_sudo=True, chown=None):
     file_name = _tmpfile()
     file = open(file_name, 'w')
     file.write(contents)
 def returns_good_status():
     """Makes an HTTP request to '/' on the site and returns True if it gets
     back a status in the 200, 300, or 400 ranges.
-    
+
     You can only use this as a standalone silk command if your site has a
     hard-configured 'bind'."""
     _yellow("Making http request to site to ensure upness.")
 def _is_this_site(name):
     """Return True if 'name' matches our site name (old style Silk deployment
     naming' or matches our name + timestamp pattern."""
-    
+
     site_pattern = re.compile('%s_\d{8}_\d{6}' % env.site)
     return (name == env.site) or (re.match(site_pattern, name) is not None)
 
     cmd = "virtualenv --no-site-packages %s %s" % (pyversion, env.envdir)
     sudo(cmd)
 
-# TODO: Add a means of cleaning out old pybundles.  
+# TODO: Add a means of cleaning out old pybundles.
 def install_bundle():
     """Push the pybundle to the remote host and install it into the virtualenv"""
     reqs_file = os.path.join(env.local_root, 'requirements.txt')
             archive_folder = silk.lib.get_local_archive_dir()
             if not os.path.isdir(archive_folder):
                 os.makedirs(archive_folder)
-            
+
             pypi = env.config.get('pypi', 'http://pypi.python.org/pypi')
             local('pip bundle %s -r %s -i %s' % (pybundle, reqs_file, pypi))
         _green("PUSHING PYBUNDLE %s" % pybundle)
         put(pybundle, remote_pybundle, use_sudo=True)
-    
+
     _green("INSTALLING PYBUNDLE")
     sudo('%s/bin/pip install %s' % (env.envdir, remote_pybundle))
 
 
     ##silk starts up supervisord on the new site
     start_process()
-    # checks that the new site is running (by using supervisorctl) 
+    # checks that the new site is running (by using supervisorctl)
     if _is_running(env.deployment):
         _green("Site is running.  Proceeding with nginx switch.")
         # if the site's running fine, then silk configures nginx to forward requests
-        # to the new site 
+        # to the new site
         configure_nginx()
         switch_nginx()
         stop_other_versions()