2013-07-06 07:51:09 +00:00
|
|
|
# -*- 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
|
2013-07-10 03:11:49 +00:00
|
|
|
from subprocess import Popen, PIPE
|
2013-07-06 07:51:09 +00:00
|
|
|
|
|
|
|
from .base import BaseProject
|
2013-07-30 06:04:43 +00:00
|
|
|
try:
|
|
|
|
from collections import OrderedDict
|
|
|
|
except ImportError:
|
|
|
|
from ..packages.ordereddict import OrderedDict
|
2013-07-06 07:51:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class Subversion(BaseProject):
|
|
|
|
|
2013-07-10 03:11:49 +00:00
|
|
|
def process(self):
|
2013-07-20 21:42:19 +00:00
|
|
|
return self._find_project_base(self.path)
|
2013-07-10 03:11:49 +00:00
|
|
|
|
|
|
|
def name(self):
|
|
|
|
return self.info['Repository Root'].split('/')[-1]
|
|
|
|
|
2013-07-20 21:42:19 +00:00
|
|
|
def tags(self):
|
|
|
|
tags = []
|
|
|
|
if self.base:
|
|
|
|
tags.append(os.path.basename(self.base))
|
|
|
|
return tags
|
|
|
|
|
|
|
|
def _get_info(self, path):
|
2013-07-10 03:11:49 +00:00
|
|
|
info = OrderedDict()
|
|
|
|
stdout = None
|
|
|
|
try:
|
|
|
|
stdout, stderr = Popen([
|
2013-07-20 21:42:19 +00:00
|
|
|
'svn', 'info', os.path.realpath(path)
|
2013-07-10 08:33:36 +00:00
|
|
|
], stdout=PIPE, stderr=PIPE).communicate()
|
2013-07-10 03:11:49 +00:00
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
if stdout:
|
|
|
|
interesting = [
|
|
|
|
'Repository Root',
|
|
|
|
'Repository UUID',
|
|
|
|
'URL',
|
|
|
|
]
|
|
|
|
for line in stdout.splitlines():
|
2013-07-30 06:04:43 +00:00
|
|
|
if isinstance(line, bytes):
|
|
|
|
line = bytes.decode(line)
|
2013-07-10 03:11:49 +00:00
|
|
|
line = line.split(': ', 1)
|
|
|
|
if line[0] in interesting:
|
|
|
|
info[line[0]] = line[1]
|
|
|
|
return info
|
2013-07-06 07:51:09 +00:00
|
|
|
|
2013-07-20 21:42:19 +00:00
|
|
|
def _find_project_base(self, path, found=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)
|
|
|
|
|