Use subprocess instead of os.popen

This commit is contained in:
Stein Magnus Jodal 2011-01-26 00:04:23 +01:00
parent 11edbc160b
commit 242f27f943

View File

@ -1,30 +1,27 @@
import os
import sys
if not (2, 6) <= sys.version_info < (3,):
sys.exit(u'Mopidy requires Python >= 2.6, < 3')
from subprocess import PIPE, Popen
VERSION = (0, 4, 0)
def is_in_git_repo():
git_dir = os.path.abspath(os.path.join(
os.path.dirname(__file__), '../.git'))
return os.path.exists(git_dir)
def get_git_version():
if not is_in_git_repo():
return None
git_version = os.popen('git describe').read().strip()
if git_version.startswith('v'):
git_version = git_version[1:]
return git_version
process = Popen(['git', 'describe'], stdout=PIPE)
if process.wait() != 0:
raise Exception|('Execution of "git describe" failed')
version = process.stdout.read().strip()
if version.startswith('v'):
version = version[1:]
return version
def get_plain_version():
return '.'.join(map(str, VERSION))
def get_version():
if is_in_git_repo():
try:
return get_git_version()
else:
except Exception:
return get_plain_version()
class MopidyException(Exception):