detect project name and branch from mercurial revision control
This commit is contained in:
parent
e54f393721
commit
7697b54e8e
2 changed files with 30 additions and 6 deletions
|
@ -13,10 +13,6 @@ import logging
|
|||
import os
|
||||
|
||||
from .base import BaseProject
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
from ..packages.ordereddict import OrderedDict
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
|
|
@ -18,13 +18,41 @@ from .base import BaseProject
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# str is unicode in Python3
|
||||
try:
|
||||
unicode
|
||||
except NameError:
|
||||
unicode = str
|
||||
|
||||
|
||||
class Mercurial(BaseProject):
|
||||
|
||||
def process(self):
|
||||
return False
|
||||
self.configDir = self._find_hg_config_dir(self.path)
|
||||
return self.configDir is not None
|
||||
|
||||
def name(self):
|
||||
if self.configDir:
|
||||
return unicode(os.path.basename(os.path.dirname(self.configDir)))
|
||||
return None
|
||||
|
||||
def branch(self):
|
||||
return None
|
||||
if self.configDir:
|
||||
branch_file = os.path.join(self.configDir, 'branch')
|
||||
try:
|
||||
with open(branch_file) as fh:
|
||||
return unicode(fh.readline().strip().rsplit('/', 1)[-1])
|
||||
except IOError:
|
||||
pass
|
||||
return unicode('default')
|
||||
|
||||
def _find_hg_config_dir(self, path):
|
||||
path = os.path.realpath(path)
|
||||
if os.path.isfile(path):
|
||||
path = os.path.split(path)[0]
|
||||
if os.path.isdir(os.path.join(path, '.hg')):
|
||||
return os.path.join(path, '.hg')
|
||||
split_path = os.path.split(path)
|
||||
if split_path[1] == '':
|
||||
return None
|
||||
return self._find_hg_config_dir(split_path[0])
|
||||
|
|
Loading…
Reference in a new issue