Created
December 21, 2011 09:10
-
-
Save perifer/1505330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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