--- a/hgrepo.py Tue Aug 11 19:12:30 2015 +0300 +++ b/hgrepo.py Sun Aug 16 10:59:22 2015 +0300 @@ -32,30 +32,26 @@ from configfile import Config class HgRepository (object): - def __init__ (self, reponame): - reponame = reponame.lower() + def __init__ (self, name): + name = name.lower() repoconfig = Config.get_node ('hg').get_node ('repos') - repoinfo = repoconfig.get_node (reponame) + repoinfo = repoconfig.get_node (name) if not repoinfo: - raise ValueError ('Unknown repository "%s"' % reponame) + raise ValueError ('Unknown repository "%s"' % name) - self.name = reponame + self.name = name self.published = not bool (repoinfo.get_value ('extrarepo', default=False)) self.url = repoinfo.get_value ('url') self.version = repoinfo.get_value ('version', default='') self.color = int (repoinfo.get_value ('colorcode', default=0)) if not self.url: - raise ValueError ('Repository %s has no url!' % reponame) + raise ValueError ('Repository %s has no url!' % name) def hg (self, *args): output = subprocess.check_output (['hg', '--cwd', self.name] + list (args)) - - if sys.version_info >= (3, 0): - output = output.decode ('utf-8', 'ignore') - - return output + return output.decode ('utf-8', 'ignore') def is_valid (self): return os.path.isdir (os.path.join (self.name, '.hg')) @@ -74,14 +70,17 @@ return result def get_commit_data (self, rev, **kvargs): - if not kvargs: - raise ValueError ('template arguments must be provided') + try: + if not kvargs: + raise ValueError ('template arguments must be provided') - separator = '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^' - template = self.split_template (kvargs, separator) - data = self.hg ('log', '--limit', '1', '--rev', rev, '--template', template) - data = data.split (separator) - return self.merge_template (data, kvargs) + separator = '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^' + template = self.split_template (kvargs, separator) + data = self.hg ('log', '--limit', '1', '--rev', rev, '--template', template) + data = data.split (separator) + return self.merge_template (data, kvargs) + except subprocess.CalledProcessError: + raise ValueError ('''couldn't find changeset %s in %s''' % (node, repo.name)) def incoming (self, maxcommits=0, **kvargs): if not kvargs: @@ -105,6 +104,6 @@ except subprocess.CalledProcessError: return [] - def clone(): - print ('Cloning %s...' % repo.name) - subprocess.call (['hg', 'clone', repo.url, repo.name]) \ No newline at end of file + def clone (self): + print ('Cloning %s from %s...' % (self.name, self.url)) + subprocess.call (['hg', 'clone', self.url, self.name]) \ No newline at end of file