Changeset cadd0b29698d…
Parent 9e6c172dbfa8…
by
Changes to one file · Browse files at cadd0b29698d Showing diff from parent 9e6c172dbfa8 Diff from another changeset...
@@ -159,10 +159,27 @@ (scripts, packages, data_files, extra) = setup_posix()
desc='TortoiseHg dialogs for Mercurial VCS'
+def runcmd(cmd, env):
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE, env=env)
+ out, err = p.communicate()
+ # If root is executing setup.py, but the repository is owned by
+ # another user (as in "sudo python setup.py install") we will get
+ # trust warnings since the .hg/hgrc file is untrusted. That is
+ # fine, we don't want to load it anyway.
+ err = [e for e in err.splitlines()
+ if not e.startswith('Not trusting file')]
+ if err:
+ return ''
+ return out
+
version = ''
-try:
- l = os.popen('hg -R . id -i -t').read().split()
+if os.path.isdir('.hg'):
+ env = os.environ
+ env.update({'HGRCPATH': '', 'LANGUAGE': 'C'})
+ cmd = ['hg', 'id', '-i', '-t']
+ l = runcmd(cmd, env).split()
while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
l.pop()
if len(l) > 1: # tag found
@@ -170,28 +187,38 @@ if l[0].endswith('+'): # propagate the dirty status to the tag
version += '+'
elif len(l) == 1: # no tag found
- cmd = 'hg parents --template {latesttag}+{latesttagdistance}-'
- version = os.popen(cmd).read() + l[0]
+ cmd = ['hg', 'parents', '--template',
+ '{latesttag}+{latesttagdistance}-']
+ version = runcmd(cmd, env) + l[0]
if version.endswith('+'):
version += time.strftime('%Y%m%d')
-except OSError:
- version = "unknown"
+elif os.path.exists('.hg_archival.txt'):
+ kw = dict([t.strip() for t in l.split(':', 1)]
+ for l in open('.hg_archival.txt'))
+ if 'tag' in kw:
+ version = kw['tag']
+ elif 'latesttag' in kw:
+ version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw
+ else:
+ version = kw.get('node', '')[:12]
-verfile = os.path.join('tortoisehg', 'util', '__version__.py')
-if version != 'unknown' or not os.path.exists(verfile):
- f = file(verfile, "w")
+if version:
+ f = open("tortoisehg/util/__version__.py", "w")
f.write('# this file is autogenerated by setup.py\n')
f.write('version = "%s"\n' % version)
f.close()
-else:
+
+try:
import tortoisehg.util.__version__
version = tortoisehg.util.__version__.version
+except ImportError:
+ version = 'unknown'
setup(name="tortoisehg",
version=version,
author='Steve Borho',
author_email='steve@borho.org',
- url='http://tortoisehg.bitbucket.org',
+ url='http://tortoisehg.org',
description=desc,
license='GNU GPL2',
scripts=scripts,
|
Loading...