bzr -> git

This commit is contained in:
Gustavo Carneiro
2015-07-09 21:53:04 +01:00
parent ff58c918a5
commit 3cbc515e49
3 changed files with 7 additions and 83 deletions
+1 -2
View File
@@ -1,8 +1,7 @@
#!/bin/sh
export BZR_PLUGIN_PATH=$(dirname $0)/bzr-plugins
ChangeLog=$(dirname $0)/ChangeLog
chmod u+w $ChangeLog 2> /dev/null
bzr log -v --log-format 'gnu' > $ChangeLog
git log > $ChangeLog
chmod a-w $ChangeLog
+3 -3
View File
@@ -33,7 +33,7 @@ if 'PYTHONPATH' in os.environ:
os.environ['PYTHONPATH'] = os.pathsep.join([os.getcwd(), os.environ['PYTHONPATH']])
else:
os.environ['PYTHONPATH'] = os.getcwd()
# http://coreygoldberg.blogspot.com/2009/07/python-zip-directories-recursively.html
def zipper(dir, zip_file, archive_main_folder=None):
@@ -66,10 +66,10 @@ def options(opt):
optgrp = opt.add_option_group("PyBindGen Options")
if os.path.isdir(".bzr"):
if os.path.isdir(".git"):
optgrp.add_option('--generate-version',
help=('Generate a new pybindgen/version.py file from version control'
' introspection. Only works from a bzr checkout tree, and is'
' introspection. Only works from a git checkout tree, and is'
' meant to be used by pybindgen developers only.'),
action="store_true", default=False,
dest='generate_version')
+3 -78
View File
@@ -4,91 +4,16 @@ import subprocess
import re
def _get_version_from_bzr_lib(path):
import bzrlib.tag, bzrlib.branch
fullpath = os.path.abspath(path)
if sys.platform == 'win32':
fullpath = fullpath.replace('\\', '/')
fullpath = '/' + fullpath
branch = bzrlib.branch.Branch.open('file://' + fullpath)
tags = bzrlib.tag.BasicTags(branch)
#print "Getting version information from bzr branch..."
branch.lock_read()
try:
history = branch.iter_merge_sorted_revisions(direction="reverse")
version = None
extra_version = []
for revid, depth, revno, end_of_merge in history:
for tag_name, tag_revid in tags.get_tag_dict().iteritems():
#print tag_revid, "<==>", revid
if tag_revid == revid:
#print "%s matches tag %s" % (revid, tag_name)
version = [int(s) for s in tag_name.split('.')]
## if the current revision does not match the last
## tag, we append current revno to the version
if tag_revid != branch.last_revision():
extra_version = [branch.revno()]
break
if version:
break
finally:
branch.unlock()
assert version is not None
_version = version + extra_version
return _version
def _get_version_from_bzr_command(path):
# get most recent tag first
most_recent_tag = None
proc = subprocess.Popen(['bzr', 'log', '--short'], stdout=subprocess.PIPE)
reg = re.compile('{([0-9]+)\.([0-9]+)\.([0-9]+)}')
for line in proc.stdout:
result = reg.search(line)
if result is not None:
most_recent_tag = [int(result.group(1)), int(result.group(2)), int(result.group(3))]
break
proc.stdout.close()
proc.wait()
assert most_recent_tag is not None
# get most recent revno
most_recent_revno = None
proc = subprocess.Popen(['bzr', 'revno'], stdout=subprocess.PIPE)
most_recent_revno = int(proc.stdout.read().strip())
proc.wait()
version = most_recent_tag + [most_recent_revno]
return version
_version = None
def get_version_from_bzr(path):
global _version
if _version is not None:
return _version
try:
import bzrlib.tag, bzrlib.branch
except ImportError:
return _get_version_from_bzr_command(path)
else:
return _get_version_from_bzr_lib(path)
def get_version(path=None):
filename = os.path.join(os.path.dirname(__file__), 'pybindgen', 'version.py')
if os.path.exists(filename):
# Read the version.py from the version file
with open(filename, "rt") as versionpy:
version_data = versionpy.read().strip().split("\n")[0]
version = eval(version_data.split("=", 1)[1])
version_str = '.'.join(str(x) for x in version)
version_str = eval(version_data.split("=", 1)[1]).strip()
#print version_str
return version_str
if path is None:
path = os.path.dirname(__file__)
try:
return '.'.join([str(x) for x in get_version_from_bzr(path)])
except ImportError:
return 'unknown'
return 'unknown'
def generate_version_py(force=False, path=None):
"""generates pybindgen/version.py, unless it already exists"""
@@ -99,7 +24,7 @@ def generate_version_py(force=False, path=None):
if path is None:
path = os.path.dirname(__file__)
version = get_version_from_bzr(path)
version = subprocess.check_output("git describe --tags".split(' ')).strip()
dest = open(filename, 'w')
if isinstance(version, list):
dest.write('__version__ = %r\n' % (version,))