Find file
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (43 sloc) 1.21 KB
import os
import subprocess as sp
import logging
for p in ('/usr/bin/git', '/usr/local/bin/git'):
if os.path.exists(p):
git_binary = p
def oneline(cmd):
p = sp.Popen(cmd.split(" "), stdout=sp.PIPE, close_fds=True, executable=git_binary)
return p.stdout.readline()
except OSError:
return "Couldn't find binary (probably)"
def sp_stdout(cmd):
p = sp.Popen(cmd.split(" "), stdout=sp.PIPE, close_fds=True)
yield p.stdout
except OSError:
raise StopIteration
def current_branch():
with sp_stdout('git branch') as branchout:
while True:
i = stdout.readline()
if i.startswith("*"):
return i[1:].strip()
return False
def update_git():
data = oneline("git pull")"Updated source to %s" % data)
return data
# TODO sanity check
def checkout_git(branch):
return oneline('git checkout %s' % branch)
def update_git_head():
return oneline('git reset --hard HEAD')
def version():
return oneline('git show --shortstat HEAD')[:16]
def log():
return ""
def clean_git():
def git(cmd):
return oneline("git %s" % cmd)