2013-11-14 08:52:00 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
wakatime.projects.projectmap
|
2013-12-13 13:46:39 +00:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2013-11-14 08:52:00 +00:00
|
|
|
|
2013-12-13 14:02:44 +00:00
|
|
|
Use the ~/.wakatime.cfg file to set custom project names by
|
|
|
|
recursively matching folder paths.
|
|
|
|
Project maps go under the [projectmap] config section.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
[projectmap]
|
|
|
|
/home/user/projects/foo = new project name
|
|
|
|
/home/user/projects/bar = project2
|
|
|
|
|
|
|
|
Will result in file `/home/user/projects/foo/src/main.c` to have
|
|
|
|
project name `new project name`.
|
2013-11-14 08:52:00 +00:00
|
|
|
|
2013-12-13 13:46:39 +00:00
|
|
|
:copyright: (c) 2013 Alan Hamlett.
|
2013-11-14 08:52:00 +00:00
|
|
|
:license: BSD, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
|
|
|
|
from .base import BaseProject
|
|
|
|
|
|
|
|
|
2014-07-25 07:59:25 +00:00
|
|
|
log = logging.getLogger('WakaTime')
|
2013-11-14 08:52:00 +00:00
|
|
|
|
|
|
|
|
2014-01-16 00:41:35 +00:00
|
|
|
# str is unicode in Python3
|
|
|
|
try:
|
|
|
|
unicode
|
|
|
|
except NameError:
|
|
|
|
unicode = str
|
|
|
|
|
|
|
|
|
2013-11-14 08:52:00 +00:00
|
|
|
class ProjectMap(BaseProject):
|
2013-12-13 13:46:39 +00:00
|
|
|
|
2013-11-14 08:52:00 +00:00
|
|
|
def process(self):
|
2013-12-13 13:46:39 +00:00
|
|
|
if not self._configs:
|
2013-12-12 09:09:14 +00:00
|
|
|
return False
|
2013-11-14 08:52:00 +00:00
|
|
|
|
2013-12-13 13:46:39 +00:00
|
|
|
self.project = self._find_project(self.path)
|
|
|
|
|
|
|
|
return self.project is not None
|
2013-12-12 09:09:14 +00:00
|
|
|
|
2013-12-13 13:46:39 +00:00
|
|
|
def _find_project(self, path):
|
|
|
|
path = os.path.realpath(path)
|
|
|
|
if os.path.isfile(path):
|
|
|
|
path = os.path.split(path)[0]
|
2013-12-12 09:09:14 +00:00
|
|
|
|
2013-12-13 13:46:39 +00:00
|
|
|
if self._configs.get(path.lower()):
|
|
|
|
return self._configs.get(path.lower())
|
|
|
|
if self._configs.get('%s/' % path.lower()):
|
|
|
|
return self._configs.get('%s/' % path.lower())
|
|
|
|
if self._configs.get('%s\\' % path.lower()):
|
|
|
|
return self._configs.get('%s\\' % path.lower())
|
|
|
|
|
|
|
|
split_path = os.path.split(path)
|
|
|
|
if split_path[1] == '':
|
|
|
|
return None
|
|
|
|
return self._find_project(split_path[0])
|
2013-11-14 08:52:00 +00:00
|
|
|
|
|
|
|
def branch(self):
|
|
|
|
return None
|
|
|
|
|
|
|
|
def name(self):
|
2013-12-13 13:46:39 +00:00
|
|
|
if self.project:
|
|
|
|
return unicode(self.project)
|
|
|
|
return None
|