From 8bd54a7427f94d512b5c0925f7e8452770e28667 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Wed, 5 Feb 2014 01:01:47 -0800 Subject: [PATCH] upgrade wakatime package to v1.0.0 for mercurial support --- packages/wakatime/HISTORY.rst | 6 ++++ packages/wakatime/wakatime/__init__.py | 2 +- packages/wakatime/wakatime/projects/git.py | 4 --- .../wakatime/wakatime/projects/mercurial.py | 32 +++++++++++++++++-- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/packages/wakatime/HISTORY.rst b/packages/wakatime/HISTORY.rst index 7cbd069..634b7b8 100644 --- a/packages/wakatime/HISTORY.rst +++ b/packages/wakatime/HISTORY.rst @@ -3,6 +3,12 @@ History ------- +1.0.0 (2014-02-05) +++++++++++++++++++ + +- detect project name and branch name from mercurial revision control + + 0.5.3 (2014-01-15) ++++++++++++++++++ diff --git a/packages/wakatime/wakatime/__init__.py b/packages/wakatime/wakatime/__init__.py index 2823b22..732c7db 100644 --- a/packages/wakatime/wakatime/__init__.py +++ b/packages/wakatime/wakatime/__init__.py @@ -13,7 +13,7 @@ from __future__ import print_function __title__ = 'wakatime' -__version__ = '0.5.3' +__version__ = '1.0.0' __author__ = 'Alan Hamlett' __license__ = 'BSD' __copyright__ = 'Copyright 2013 Alan Hamlett' diff --git a/packages/wakatime/wakatime/projects/git.py b/packages/wakatime/wakatime/projects/git.py index ae433d5..c8539a6 100644 --- a/packages/wakatime/wakatime/projects/git.py +++ b/packages/wakatime/wakatime/projects/git.py @@ -13,10 +13,6 @@ import logging import os from .base import BaseProject -try: - from collections import OrderedDict -except ImportError: - from ..packages.ordereddict import OrderedDict log = logging.getLogger(__name__) diff --git a/packages/wakatime/wakatime/projects/mercurial.py b/packages/wakatime/wakatime/projects/mercurial.py index 4e9ce96..f91ab71 100644 --- a/packages/wakatime/wakatime/projects/mercurial.py +++ b/packages/wakatime/wakatime/projects/mercurial.py @@ -18,13 +18,41 @@ from .base import BaseProject log = logging.getLogger(__name__) +# str is unicode in Python3 +try: + unicode +except NameError: + unicode = str + + class Mercurial(BaseProject): def process(self): - return False + self.configDir = self._find_hg_config_dir(self.path) + return self.configDir is not None def name(self): + if self.configDir: + return unicode(os.path.basename(os.path.dirname(self.configDir))) return None def branch(self): - return None + if self.configDir: + branch_file = os.path.join(self.configDir, 'branch') + try: + with open(branch_file) as fh: + return unicode(fh.readline().strip().rsplit('/', 1)[-1]) + except IOError: + pass + return unicode('default') + + def _find_hg_config_dir(self, path): + path = os.path.realpath(path) + if os.path.isfile(path): + path = os.path.split(path)[0] + if os.path.isdir(os.path.join(path, '.hg')): + return os.path.join(path, '.hg') + split_path = os.path.split(path) + if split_path[1] == '': + return None + return self._find_hg_config_dir(split_path[0])