From 242f27f943a107bf7dd2a472f08a71a8382f6467 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Wed, 26 Jan 2011 00:04:23 +0100 Subject: [PATCH] Use subprocess instead of os.popen --- mopidy/__init__.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/mopidy/__init__.py b/mopidy/__init__.py index 4bb4609b..cbf1c757 100644 --- a/mopidy/__init__.py +++ b/mopidy/__init__.py @@ -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):