Refactoring get_app_version
This commit is contained in:
parent
57854169f4
commit
c2986f3b14
@ -11,17 +11,10 @@ import subprocess
|
||||
def app_version():
|
||||
def minimal_env_cmd(cmd):
|
||||
# make minimal environment
|
||||
env = {}
|
||||
for k in ['SYSTEMROOT', 'PATH']:
|
||||
v = os.environ.get(k)
|
||||
if v is not None:
|
||||
env[k] = v
|
||||
env = {k: os.environ[k] for k in ['SYSTEMROOT', 'PATH'] if k in os.environ}
|
||||
env.update({'LANGUAGE': 'C', 'LANG': 'C', 'LC_ALL': 'C'})
|
||||
|
||||
env['LANGUAGE'] = 'C'
|
||||
env['LANG'] = 'C'
|
||||
env['LC_ALL'] = 'C'
|
||||
out = subprocess.Popen(
|
||||
cmd, stdout=subprocess.PIPE, env=env).communicate()[0]
|
||||
out = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env).communicate()[0]
|
||||
return out
|
||||
|
||||
subst_list = {
|
||||
@ -31,24 +24,21 @@ def app_version():
|
||||
}
|
||||
|
||||
if os.system("command -v git > /dev/null 2>&1") != 0:
|
||||
subst_list
|
||||
else:
|
||||
if call(["git", "branch"], stderr=STDOUT,
|
||||
stdout=open(os.devnull, 'w')) != 0:
|
||||
subst_list
|
||||
else:
|
||||
# version
|
||||
describe = minimal_env_cmd(["git", "describe", "--always"])
|
||||
return subst_list
|
||||
|
||||
if call(["git", "branch"], stderr=STDOUT, stdout=open(os.devnull, 'w')) != 0:
|
||||
return subst_list
|
||||
|
||||
describe = minimal_env_cmd(["git", "describe", "--tags", "--always"])
|
||||
git_revision = describe.strip().decode('ascii')
|
||||
# branch
|
||||
|
||||
branch = minimal_env_cmd(["git", "branch"])
|
||||
git_branch = branch.strip().decode('ascii').replace('* ', '')
|
||||
|
||||
subst_list = {
|
||||
"version": __version__,
|
||||
subst_list.update({
|
||||
"branch": git_branch,
|
||||
"commit": git_revision
|
||||
}
|
||||
})
|
||||
|
||||
return subst_list
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user