2013-11-14 02:05:44 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
2017-11-06 03:52:23 +00:00
|
|
|
wakatime.projects.projectfile
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2013-11-14 02:05:44 +00:00
|
|
|
|
|
|
|
Information from a .wakatime-project file about the project for
|
2013-12-13 15:37:01 +00:00
|
|
|
a given file. First line of .wakatime-project sets the project
|
|
|
|
name. Second line sets the current branch name.
|
2013-11-14 02:05:44 +00:00
|
|
|
|
|
|
|
:copyright: (c) 2013 Alan Hamlett.
|
|
|
|
:license: BSD, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
2015-08-25 07:51:01 +00:00
|
|
|
import sys
|
2013-11-14 02:05:44 +00:00
|
|
|
|
|
|
|
from .base import BaseProject
|
2014-09-30 16:23:17 +00:00
|
|
|
from ..compat import u, open
|
2018-01-05 07:35:46 +00:00
|
|
|
from ..utils import find_project_file
|
2013-11-14 02:05:44 +00:00
|
|
|
|
|
|
|
|
2014-07-25 09:45:35 +00:00
|
|
|
log = logging.getLogger('WakaTime')
|
2013-11-14 02:05:44 +00:00
|
|
|
|
|
|
|
|
2017-11-06 03:52:23 +00:00
|
|
|
class ProjectFile(BaseProject):
|
2013-11-14 02:05:44 +00:00
|
|
|
|
|
|
|
def process(self):
|
2018-01-05 07:35:46 +00:00
|
|
|
self.config = find_project_file(self.path)
|
2013-12-13 15:37:01 +00:00
|
|
|
self._project_name = None
|
|
|
|
self._project_branch = None
|
|
|
|
|
2013-11-14 02:05:44 +00:00
|
|
|
if self.config:
|
2013-12-13 15:37:01 +00:00
|
|
|
|
|
|
|
try:
|
2014-09-30 16:23:17 +00:00
|
|
|
with open(self.config, 'r', encoding='utf-8') as fh:
|
2018-01-05 07:35:46 +00:00
|
|
|
self._project_name = u(fh.readline().strip()) or None
|
|
|
|
self._project_branch = u(fh.readline().strip()) or None
|
2015-09-08 04:29:53 +00:00
|
|
|
except UnicodeDecodeError: # pragma: nocover
|
2015-08-25 07:51:01 +00:00
|
|
|
try:
|
|
|
|
with open(self.config, 'r', encoding=sys.getfilesystemencoding()) as fh:
|
2018-01-05 07:35:46 +00:00
|
|
|
self._project_name = u(fh.readline().strip()) or None
|
|
|
|
self._project_branch = u(fh.readline().strip()) or None
|
2015-08-25 07:51:01 +00:00
|
|
|
except:
|
2016-09-02 08:47:21 +00:00
|
|
|
log.traceback(logging.WARNING)
|
2015-09-08 04:29:53 +00:00
|
|
|
except IOError: # pragma: nocover
|
2016-09-02 08:47:21 +00:00
|
|
|
log.traceback(logging.WARNING)
|
2013-12-13 15:37:01 +00:00
|
|
|
|
2013-11-14 02:05:44 +00:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def name(self):
|
2013-12-13 15:37:01 +00:00
|
|
|
return self._project_name
|
2013-11-14 02:05:44 +00:00
|
|
|
|
|
|
|
def branch(self):
|
2013-12-13 15:37:01 +00:00
|
|
|
return self._project_branch
|