297ebb902b
- force projects to return unicode names and branches, or None - refactor ProjectMap to set project name from cfg file - pass configs to find_project() as dict from plugin's cfg section - clean up git project class updates to config file: - rename ~/.wakatime.conf to ~/.wakatime.cfg - better error handling while parsing and getting configs - no longer need to set defaults when parsing config file - use configparser for python3 when python2 import fails
81 lines
2.1 KiB
Python
81 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
wakatime.projects.subversion
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
Information about the svn project for a given file.
|
|
|
|
:copyright: (c) 2013 Alan Hamlett.
|
|
:license: BSD, see LICENSE for more details.
|
|
"""
|
|
|
|
import logging
|
|
import os
|
|
import platform
|
|
from subprocess import Popen, PIPE
|
|
|
|
from .base import BaseProject
|
|
try:
|
|
from collections import OrderedDict
|
|
except ImportError:
|
|
from ..packages.ordereddict import OrderedDict
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
class Subversion(BaseProject):
|
|
|
|
def process(self):
|
|
return self._find_project_base(self.path)
|
|
|
|
def name(self):
|
|
return unicode(self.info['Repository Root'].split('/')[-1])
|
|
|
|
def branch(self):
|
|
if self.base:
|
|
unicode(os.path.basename(self.base))
|
|
return None
|
|
|
|
def _get_info(self, path):
|
|
info = OrderedDict()
|
|
stdout = None
|
|
try:
|
|
stdout, stderr = Popen([
|
|
'svn', 'info', os.path.realpath(path)
|
|
], stdout=PIPE, stderr=PIPE).communicate()
|
|
except OSError:
|
|
pass
|
|
else:
|
|
if stdout:
|
|
interesting = [
|
|
'Repository Root',
|
|
'Repository UUID',
|
|
'URL',
|
|
]
|
|
for line in stdout.splitlines():
|
|
if isinstance(line, bytes):
|
|
line = bytes.decode(line)
|
|
line = line.split(': ', 1)
|
|
if line[0] in interesting:
|
|
info[line[0]] = line[1]
|
|
return info
|
|
|
|
def _find_project_base(self, path, found=False):
|
|
if platform.system() == 'Windows':
|
|
return False
|
|
path = os.path.realpath(path)
|
|
if os.path.isfile(path):
|
|
path = os.path.split(path)[0]
|
|
info = self._get_info(path)
|
|
if len(info) > 0:
|
|
found = True
|
|
self.base = path
|
|
self.info = info
|
|
elif found:
|
|
return True
|
|
split_path = os.path.split(path)
|
|
if split_path[1] == '':
|
|
return found
|
|
return self._find_project_base(split_path[0], found)
|
|
|