# HG changeset patch # User Steve Losh # Date 1254687922 14400 # Node ID d02c0ed2f109b86511b49ac12cd0b08451b7faba # Parent b5deba11fc17371787a0fe171ed477ef2a0cab86 Rename the API module. diff -r b5deba11fc17 -r d02c0ed2f109 review/api.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/review/api.py Sun Oct 04 16:25:22 2009 -0400 @@ -0,0 +1,61 @@ +from __future__ import with_statement + +'''The review data structures. +''' + +import os +from mercurial import hg + + +class PreexistingDatastore(Exception): + """Raised when trying to initialize a datastore when one seems to exist.""" + def __init__(self, committed): + super(PreexistingDatastore, self).__init__() + self.committed = committed + + + +def _parse_hgrf(repo): + """Parse the .hgreview file and return the data inside.""" + + data = {} + lines = [line for line in repo['tip']['.hgreview'] if line.strip()] + for line in lines: + label, _, path = [i.strip() for i in line.partition('=')] + if label == 'local': + data['lpath'] = path + elif label == 'remote': + data['rpath'] = path + + return data + + +class ReviewDatastore(dict): + '''The data store for all the reviews so far.''' + + def __init__(self, ui, repo, lpath=None, rpath=None, create=False): + if not create: + data = _parse_hgrf(repo) + self.lpath = data['lpath'] + self.rpath = data['rpath'] + else: + if '.hgreview' in repo['tip']: + raise PreexistingDatastore(True) + if os.path.exists(os.path.join(repo.root, '.hgreview')): + raise PreexistingDatastore(False) + self.lpath = lpath or '.review' + self.rpath = rpath or ('../%s-review' % os.path.basename(repo.root)) + + root = os.path.join(repo.root, self.lpath) + self.target = repo + self.repo = hg.repository(ui, root, create) + + if create: + hgrpath = os.path.join(repo.root, '.hgreview') + with open(hgrpath, 'w') as hgrf: + hgrf.write('local = %s\n' % self.lpath) + hgrf.write('remote = %s\n' % self.rpath) + repo.add(['.hgreview']) + + + diff -r b5deba11fc17 -r d02c0ed2f109 review/data.py --- a/review/data.py Sun Oct 04 16:12:09 2009 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -from __future__ import with_statement - -'''The review data structures. -''' - -import os -from mercurial import hg - - -class PreexistingDatastore(Exception): - """Raised when trying to initialize a datastore when one seems to exist.""" - def __init__(self, committed): - super(PreexistingDatastore, self).__init__() - self.committed = committed - - - -def _parse_hgrf(repo): - """Parse the .hgreview file and return the data inside.""" - - data = {} - lines = [line for line in repo['tip']['.hgreview'] if line.strip()] - for line in lines: - label, _, path = [i.strip() for i in line.partition('=')] - if label == 'local': - data['lpath'] = path - elif label == 'remote': - data['rpath'] = path - - return data - - -class ReviewDatastore(dict): - '''The data store for all the reviews so far.''' - - def __init__(self, ui, repo, lpath=None, rpath=None, create=False): - if not create: - data = _parse_hgrf(repo) - self.lpath = data['lpath'] - self.rpath = data['rpath'] - else: - if '.hgreview' in repo['tip']: - raise PreexistingDatastore(True) - if os.path.exists(os.path.join(repo.root, '.hgreview')): - raise PreexistingDatastore(False) - self.lpath = lpath or '.review' - self.rpath = rpath or ('../%s-review' % os.path.basename(repo.root)) - - root = os.path.join(repo.root, self.lpath) - self.target = repo - self.repo = hg.repository(ui, root, create) - - if create: - hgrpath = os.path.join(repo.root, '.hgreview') - with open(hgrpath, 'w') as hgrf: - hgrf.write('local = %s\n' % self.lpath) - hgrf.write('remote = %s\n' % self.rpath) - repo.add(['.hgreview']) - - - diff -r b5deba11fc17 -r d02c0ed2f109 review/extension_ui.py --- a/review/extension_ui.py Sun Oct 04 16:12:09 2009 -0400 +++ b/review/extension_ui.py Sun Oct 04 16:25:22 2009 -0400 @@ -1,7 +1,7 @@ '''The review extension's UI.''' import messages -from data import * +from api import * from mercurial import util def review(ui, repo, *fnames, **opts): @@ -20,6 +20,7 @@ else: raise util.Abort(messages.INIT_EXISTS_UNCOMMITTED) + cmdtable = { 'review': (review, [