def get_remote_url(repo_dir): """假定只有一个remote url,返回它""" cwd = os.getcwd() os.chdir(repo_dir) r = Popen(['git', 'remote', '-v'], stdout=PIPE).communicate()[0] os.chdir(cwd) remote_url = tsplit(r, ['\n', '\t', ' '])[1] return remote_url
def upload(remote='heroku'): if len(clint.args): remote = clint.args.get(0) #: Git remote collector. remotes = dict() # The current path to the application. app_path = os.getcwd() # Remember Git Remote git_snap = envoy.run('git remote -v').std_out.strip() for remote_line in git_snap.split('\n'): r = tsplit(remote_line, (' ', '\t')) r_name = r[0] r_path = r[1] remotes[r_name] = r_path if not remote in remotes: raise RuntimeError print 'Uploading {0} to {1}.'.format( app_path.split('/').pop(), remotes[remote] ) # Create a new upload directory. # mkdir_p('.abode/{0}'.format(remote)) repo_dir = tempfile.mkdtemp(prefix="abode-upload-{0}".format(remote)) # Copy everything into it. envoy.run('cp -R . {0}'.format(repo_dir)) # Move on in. os.chdir(repo_dir) envoy.run('git init') envoy.run('git add -A') envoy.run('git commit --no-message --allow-empty-message -m abode') # os.system('pwd') os.system('git push {0} master --force'.format(remotes[remote]))