From b345a1ff7b2dc924b5ec172081f1a88dca0bbe39 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Wed, 13 Nov 2013 10:41:56 -0800 Subject: [PATCH] set project name with .wakatime-project file --- wakatime/project.py | 2 ++ wakatime/projects/wakatime.py | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 wakatime/projects/wakatime.py diff --git a/wakatime/project.py b/wakatime/project.py index 783f2cb..e27a219 100644 --- a/wakatime/project.py +++ b/wakatime/project.py @@ -12,6 +12,7 @@ import logging import os +from .projects.wakatime import WakaTime from .projects.git import Git from .projects.mercurial import Mercurial from .projects.subversion import Subversion @@ -20,6 +21,7 @@ from .projects.subversion import Subversion log = logging.getLogger(__name__) PLUGINS = [ + WakaTime, Git, Mercurial, Subversion, diff --git a/wakatime/projects/wakatime.py b/wakatime/projects/wakatime.py new file mode 100644 index 0000000..1dd92ef --- /dev/null +++ b/wakatime/projects/wakatime.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +""" + wakatime.projects.wakatime + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Information from a .wakatime-project file about the project for + a given file. + + :copyright: (c) 2013 Alan Hamlett. + :license: BSD, see LICENSE for more details. +""" + +import logging +import os + +from .base import BaseProject + + +log = logging.getLogger(__name__) + + +class WakaTime(BaseProject): + + def process(self): + self.config = self._find_config(self.path) + if self.config: + return True + return False + + def name(self): + project_name = None + try: + with open(self.config) as fh: + project_name = fh.readline().strip() + except IOError as e: + log.exception("Exception:") + return project_name + + def branch(self): + return None + + def _find_config(self, path): + path = os.path.realpath(path) + if os.path.isfile(path): + path = os.path.split(path)[0] + if os.path.isfile(os.path.join(path, '.wakatime-project')): + return os.path.join(path, '.wakatime-project') + split_path = os.path.split(path) + if split_path[1] == '': + return None + return self._find_config(split_path[0])