forked from openlp/openlp
fixed setup.py
This commit is contained in:
parent
1b447c4590
commit
1e8ad4ab7e
@ -1 +1 @@
|
|||||||
2.1.0-bzr2141
|
2.0.1-bzr2233
|
51
setup.py
51
setup.py
@ -27,12 +27,15 @@
|
|||||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
from setuptools import setup, find_packages
|
|
||||||
import re
|
import re
|
||||||
|
from setuptools import setup, find_packages
|
||||||
|
from subprocess import Popen, PIPE
|
||||||
|
|
||||||
|
|
||||||
VERSION_FILE = 'openlp/.version'
|
VERSION_FILE = 'openlp/.version'
|
||||||
SPLIT_ALPHA_DIGITS = re.compile(r'(\d+|\D+)')
|
SPLIT_ALPHA_DIGITS = re.compile(r'(\d+|\D+)')
|
||||||
|
|
||||||
|
|
||||||
def try_int(s):
|
def try_int(s):
|
||||||
"""
|
"""
|
||||||
Convert string s to an integer if possible. Fail silently and return
|
Convert string s to an integer if possible. Fail silently and return
|
||||||
@ -46,6 +49,7 @@ def try_int(s):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
def natural_sort_key(s):
|
def natural_sort_key(s):
|
||||||
"""
|
"""
|
||||||
Return a tuple by which s is sorted.
|
Return a tuple by which s is sorted.
|
||||||
@ -55,6 +59,7 @@ def natural_sort_key(s):
|
|||||||
"""
|
"""
|
||||||
return map(try_int, SPLIT_ALPHA_DIGITS.findall(s))
|
return map(try_int, SPLIT_ALPHA_DIGITS.findall(s))
|
||||||
|
|
||||||
|
|
||||||
def natural_compare(a, b):
|
def natural_compare(a, b):
|
||||||
"""
|
"""
|
||||||
Compare two strings naturally and return the result.
|
Compare two strings naturally and return the result.
|
||||||
@ -67,6 +72,7 @@ def natural_compare(a, b):
|
|||||||
"""
|
"""
|
||||||
return cmp(natural_sort_key(a), natural_sort_key(b))
|
return cmp(natural_sort_key(a), natural_sort_key(b))
|
||||||
|
|
||||||
|
|
||||||
def natural_sort(seq, compare=natural_compare):
|
def natural_sort(seq, compare=natural_compare):
|
||||||
"""
|
"""
|
||||||
Returns a copy of seq, sorted by natural string sort.
|
Returns a copy of seq, sorted by natural string sort.
|
||||||
@ -77,28 +83,27 @@ def natural_sort(seq, compare=natural_compare):
|
|||||||
return temp
|
return temp
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Try to import Bazaar
|
bzr = Popen((u'bzr', u'tags', u'--sort', u'time'), stdout=PIPE)
|
||||||
from bzrlib.branch import Branch
|
output, error = bzr.communicate()
|
||||||
b = Branch.open_containing('.')[0]
|
code = bzr.wait()
|
||||||
b.lock_read()
|
if code != 0:
|
||||||
try:
|
raise Exception(u'Error running bzr tags')
|
||||||
# Get the branch's latest revision number.
|
lines = output.splitlines()
|
||||||
revno = b.revno()
|
if not lines:
|
||||||
# Convert said revision number into a bzr revision id.
|
tag = u'0.0.0'
|
||||||
revision_id = b.dotted_revno_to_revision_id((revno,))
|
revision = u'0'
|
||||||
# Get a dict of tags, with the revision id as the key.
|
else:
|
||||||
tags = b.tags.get_reverse_tag_dict()
|
tag, revision = lines[-1].split()
|
||||||
# Check if the latest
|
bzr = Popen((u'bzr', u'log', u'--line', u'-r', u'-1'), stdout=PIPE)
|
||||||
if revision_id in tags:
|
output, error = bzr.communicate()
|
||||||
version = u'%s' % tags[revision_id][0]
|
code = bzr.wait()
|
||||||
else:
|
if code != 0:
|
||||||
version = '%s-bzr%s' % \
|
raise Exception(u'Error running bzr log')
|
||||||
(natural_sort(b.tags.get_tag_dict().keys())[-1], revno)
|
latest = output.split(u':')[0]
|
||||||
ver_file = open(VERSION_FILE, u'w')
|
version = latest == revision and tag or u'%s-bzr%s' % (tag, latest)
|
||||||
ver_file.write(version)
|
ver_file = open(VERSION_FILE, u'w')
|
||||||
ver_file.close()
|
ver_file.write(version)
|
||||||
finally:
|
ver_file.close()
|
||||||
b.unlock()
|
|
||||||
except:
|
except:
|
||||||
ver_file = open(VERSION_FILE, u'r')
|
ver_file = open(VERSION_FILE, u'r')
|
||||||
version = ver_file.read().strip()
|
version = ver_file.read().strip()
|
||||||
|
Loading…
Reference in New Issue
Block a user