Skip to content

Instantly share code, notes, and snippets.

@perifer
Created December 21, 2011 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perifer/1505330 to your computer and use it in GitHub Desktop.
Save perifer/1505330 to your computer and use it in GitHub Desktop.
import os
import re
from fabric.api import *
from urlparse import urlparse
def task(project):
try:
# User can set their project directory with
# export PROJECT_DIR= in their shell
projects_dir = os.environ['PROJECT_DIR']
except KeyError:
# Default to ~/Projects
projects_dir = os.environ['HOME'] + '/Projects'
# Find the project directory based on project name.
# Match by ignoring the domain suffix that can vary.
r = re.compile(r'%s\..*$' % project)
for dir in os.listdir(projects_dir):
if r.match(dir):
project_dir = dir
break
git_repo = os.path.join(projects_dir, project_dir, 'public_html')
with lcd(git_repo):
ssh_settings = local('git config --get remote.live.url', True)
# Work around limitation in urlparse
ssh_settings = ssh_settings.replace('ssh://', 'http://')
# Parse the uri
ssh_settings = urlparse(ssh_settings)
# Set our host info that fabric uses to connect
env.user = ssh_settings.username
env.host_string = ssh_settings.hostname
# Do things on the remote host
run('ls')
import subprocess
proc = subprocess.Popen(["ssh", "aegir@skane.com", "php"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
f = open('info.php', 'r');
result = proc.communicate(f.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment