2013-07-08 05:38:01 +04: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 07:23:10 +04:00
|
|
|
from subprocess import Popen, PIPE
|
2013-07-08 05:38:01 +04:00
|
|
|
|
|
|
|
from .base import BaseProject
|
2013-07-10 07:23:10 +04:00
|
|
|
from ..packages.ordereddict import OrderedDict
|
2013-07-08 05:38:01 +04:00
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class Subversion(BaseProject):
|
|
|
|
|
2013-07-10 07:23:10 +04:00
|
|
|
def process(self):
|
|
|
|
self.info = self._get_info()
|
|
|
|
if 'Repository Root' in self.info:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def name(self):
|
|
|
|
return self.info['Repository Root'].split('/')[-1]
|
|
|
|
|
|
|
|
def _get_info(self):
|
|
|
|
info = OrderedDict()
|
|
|
|
stdout = None
|
|
|
|
try:
|
|
|
|
stdout, stderr = Popen([
|
|
|
|
'svn', 'info', os.path.realpath(self.path)
|
|
|
|
], stdout=PIPE).communicate()
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
if stdout:
|
|
|
|
interesting = [
|
|
|
|
'Repository Root',
|
|
|
|
'Repository UUID',
|
|
|
|
'URL',
|
|
|
|
]
|
|
|
|
for line in stdout.splitlines():
|
|
|
|
line = line.split(': ', 1)
|
|
|
|
if line[0] in interesting:
|
|
|
|
info[line[0]] = line[1]
|
|
|
|
return info
|
2013-07-08 05:38:01 +04:00
|
|
|
|
|
|
|
def tags(self):
|
|
|
|
tags = []
|
2013-07-10 07:23:10 +04:00
|
|
|
for key in self.info:
|
|
|
|
if key == 'Repository UUID':
|
|
|
|
tags.append(self.info[key])
|
|
|
|
if key == 'URL':
|
|
|
|
tags.append(os.path.dirname(self.info[key]))
|
2013-07-08 05:38:01 +04:00
|
|
|
return tags
|