Skip to content

Instantly share code, notes, and snippets.

@jollychang
Created August 17, 2011 10:10
Show Gist options
  • Save jollychang/1151254 to your computer and use it in GitHub Desktop.
Save jollychang/1151254 to your computer and use it in GitHub Desktop.
sync hg to svn by python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
import os, sys
pwd = os.path.dirname(os.path.realpath(__file__))
BASE_PATH = pwd + '/'
#BASE_PATH = '/Users/jollychang/Works/'
HG_FOLDER = 'hg_webtests'
SVN_FOLDER = 'svn_webtests'
HG_PATH = BASE_PATH + HG_FOLDER
SVN_PATH = BASE_PATH + SVN_FOLDER
HG_URL = 'http://hg/'
SVN_URL = 'http://svn'
def run_command(cmd):
p = subprocess.Popen(cmd, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return p.communicate()
def remove_folder(path):
stdout, stderr = run_command('rm -rf %s' % path)
if len(stderr) == 0:
print 'remove folder: ' + path
print stdout, stderr
if __name__ == "__main__":
remove_folder(HG_PATH)
print '-'*30
remove_folder(SVN_PATH)
print '-'*30
print 'hg clone'
run_command('hg clone -q %s %s' % (HG_URL, HG_PATH))
stdout, stderr = run_command("cd %s && hg head | grep 修改集 | sed -e 's/^修改集: //'" % HG_PATH)
cs = stdout
print 'Last Changeset is %s' % cs
print '-'*30
print 'svn checkout'
run_command('svn co -q %s %s' % (SVN_URL, SVN_PATH))
stdout, stderr = run_command("cd %s && svn info | grep Revision | sed -e 's/^Revision: //'" % SVN_PATH)
r = stdout
print 'Last Revision is %s' % r
print '-'*30
o, e = run_command('cd %s && svn st -q' % SVN_PATH)
if len(o) == len(e) == 0:
print 'There is nothing need to sync'
else:
print 'please svn commit manually'
commit_message = 'QA : #11580 sync test cases %s' % cs
print commit_message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment