Use an explicit command to trnasition instead of relying a post checkout hook

This commit is contained in:
Kovid Goyal 2014-04-18 13:42:51 +05:30
parent 8faaa8bbf5
commit 4dd02d449c

View File

@ -11,29 +11,11 @@ import os, subprocess, sys, shutil
prev_rev, current_rev, flags = [x.decode('utf-8') if isinstance(x, bytes) else x for x in sys.argv[1:]] prev_rev, current_rev, flags = [x.decode('utf-8') if isinstance(x, bytes) else x for x in sys.argv[1:]]
def get_branch_name(rev): def get_branch_name(rev):
return subprocess.check_output(['git', 'name-rev', '--name-only', rev]).decode('utf-8').strip() return subprocess.check_output(['git', 'name-rev', '--name-only', rev]).decode('utf-8').strip()
base = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
os.chdir(base)
if flags == '1': # A branch checkout if flags == '1': # A branch checkout
base = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
os.chdir(base)
prev_branch, cur_branch = map(get_branch_name, (prev_rev, current_rev)) prev_branch, cur_branch = map(get_branch_name, (prev_rev, current_rev))
is_qt5_transition = 'qt5' in (prev_branch, cur_branch)
print ('Transitioning from', prev_branch, 'to', cur_branch)
if is_qt5_transition:
# Remove compiled .ui files as they must be re-generated
for dirpath, dirnames, filenames in os.walk('.'):
for f in filenames:
if f.endswith('_ui.py'):
os.remove(os.path.join(dirpath, f))
# Rebuild PyQt extensions
if not os.path.exists('.git/rebase-merge'): # Dont rebuild if we are rebasing
for ext in ('progress_indicator',):
extdir = os.path.join('build', 'pyqt', ext)
if os.path.exists(extdir):
shutil.rmtree(extdir)
subprocess.check_call(['python', 'setup.py', 'build', '--only', ext])
subprocess.check_call(['python', 'setup.py', 'gui', '--summary']) subprocess.check_call(['python', 'setup.py', 'gui', '--summary'])
@ -43,11 +25,43 @@ if flags == '1': # A branch checkout
fpath = os.path.join(dirpath, f) fpath = os.path.join(dirpath, f)
if f.endswith('.pyc'): if f.endswith('.pyc'):
os.remove(fpath) os.remove(fpath)
elif cur_branch == 'qt5' and f.endswith('.py') and 'qtcurve' not in fpath and (b'PyQt' + b'4') in open(fpath, 'rb').read():
red = ('\033[%dm'%31).encode('ascii') elif flags in ('master', 'qt5'):
reset = ('\033[%dm'%31).encode('ascii') cur_branch = get_branch_name('HEAD')
sys.stdout.write(red) next_branch = flags
print ('\nPyQt' + '4 present in:', fpath) if cur_branch == next_branch:
sys.stdout.write(reset) print ('Already on branch', next_branch, file=sys.stderr)
raise SystemExit(1)
is_qt5_transition = 'qt5' in (next_branch, cur_branch)
print ('Transitioning from', cur_branch, 'to', next_branch)
if is_qt5_transition:
# Remove compiled .ui files as they must be re-generated
for dirpath, dirnames, filenames in os.walk('.'):
for f in filenames:
if f.endswith('_ui.py'):
os.remove(os.path.join(dirpath, f))
subprocess.check_call(['git', 'checkout', next_branch])
if is_qt5_transition:
# Rebuild PyQt extensions
if not os.path.exists('.git/rebase-merge'): # Dont rebuild if we are rebasing
for ext in ('progress_indicator',):
extdir = os.path.join('build', 'pyqt', ext)
if os.path.exists(extdir):
shutil.rmtree(extdir)
subprocess.check_call(['python', 'setup.py', 'build', '--only', ext])
if next_branch == 'qt5':
for dirpath, dirnames, filenames in os.walk('.'):
for f in filenames:
fpath = os.path.join(dirpath, f)
if f.endswith('.py') and 'qtcurve' not in fpath and (b'PyQt' + b'4') in open(fpath, 'rb').read():
red = ('\033[%dm'%31).encode('ascii')
reset = ('\033[%dm'%31).encode('ascii')
sys.stdout.write(red)
print ('\nPyQt' + '4 present in:', fpath)
sys.stdout.write(reset)