diff options
Diffstat (limited to 'libbe/storage')
-rw-r--r-- | libbe/storage/http.py | 6 | ||||
-rw-r--r-- | libbe/storage/util/config.py | 4 | ||||
-rw-r--r-- | libbe/storage/vcs/base.py | 95 | ||||
-rw-r--r-- | libbe/storage/vcs/bzr.py | 53 | ||||
-rw-r--r-- | libbe/storage/vcs/hg.py | 17 |
5 files changed, 110 insertions, 65 deletions
diff --git a/libbe/storage/http.py b/libbe/storage/http.py index f7af3e7..c2bb65b 100644 --- a/libbe/storage/http.py +++ b/libbe/storage/http.py @@ -335,14 +335,14 @@ if TESTING == True: class GetPostUrlTestCase (unittest.TestCase): """Test cases for get_post_url()""" def test_get(self): - url = 'http://bugseverywhere.org/be/show/HomePage' + url = 'http://bugseverywhere.org/' page,final_url,info = get_post_url(url=url) self.failUnless(final_url == url, 'Redirect?\n Expected: "%s"\n Got: "%s"' % (url, final_url)) def test_get_redirect(self): - url = 'http://bugseverywhere.org' - expected = 'http://bugseverywhere.org/be/show/HomePage' + url = 'http://physics.drexel.edu/~wking/code/be/redirect' + expected = 'http://physics.drexel.edu/~wking/' page,final_url,info = get_post_url(url=url) self.failUnless(final_url == expected, 'Redirect?\n Expected: "%s"\n Got: "%s"' diff --git a/libbe/storage/util/config.py b/libbe/storage/util/config.py index 714d4e7..d138bf4 100644 --- a/libbe/storage/util/config.py +++ b/libbe/storage/util/config.py @@ -31,10 +31,10 @@ if libbe.TESTING == True: import doctest -default_encoding = libbe.util.encoding.get_filesystem_encoding() +default_encoding = libbe.util.encoding.get_text_file_encoding() """Default filesystem encoding. -Initialized with :func:`libbe.util.encoding.get_filesystem_encoding`. +Initialized with :func:`libbe.util.encoding.get_text_file_encoding`. """ def path(): diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py index d377398..eaaf2d8 100644 --- a/libbe/storage/vcs/base.py +++ b/libbe/storage/vcs/base.py @@ -199,7 +199,7 @@ class CachedPathID (object): >>> dir.cleanup() """ def __init__(self, encoding=None): - self.encoding = libbe.util.encoding.get_filesystem_encoding() + self.encoding = libbe.util.encoding.get_text_file_encoding() self._spacer_dirs = ['.be', 'bugs', 'comments'] def root(self, path): @@ -350,7 +350,7 @@ class VCS (libbe.storage.base.VersionedStorage): def __init__(self, *args, **kwargs): if 'encoding' not in kwargs: - kwargs['encoding'] = libbe.util.encoding.get_filesystem_encoding() + kwargs['encoding'] = libbe.util.encoding.get_text_file_encoding() libbe.storage.base.VersionedStorage.__init__(self, *args, **kwargs) self.versioned = False self.interspersed_vcs_files = False @@ -521,6 +521,97 @@ class VCS (libbe.storage.base.VersionedStorage): self._version = self._vcs_version() return self._version + def version_cmp(self, *args): + """Compare the installed VCS version `V_i` with another version + `V_o` (given in `*args`). Returns + + === =============== + 1 if `V_i > V_o` + 0 if `V_i == V_o` + -1 if `V_i < V_o` + === =============== + + Examples + -------- + + >>> v = VCS(repo='.') + >>> v._version = '2.3.1 (release)' + >>> v.version_cmp(2,3,1) + 0 + >>> v.version_cmp(2,3,2) + -1 + >>> v.version_cmp(2,3,'a',5) + 1 + >>> v.version_cmp(2,3,0) + 1 + >>> v.version_cmp(2,3,1,'a',5) + 1 + >>> v.version_cmp(2,3,1,1) + -1 + >>> v.version_cmp(3) + -1 + >>> v._version = '2.0.0pre2' + >>> v._parsed_version = None + >>> v.version_cmp(3) + -1 + >>> v.version_cmp(2,0,1) + -1 + >>> v.version_cmp(2,0,0,'pre',1) + 1 + >>> v.version_cmp(2,0,0,'pre',2) + 0 + >>> v.version_cmp(2,0,0,'pre',3) + -1 + >>> v.version_cmp(2,0,0,'a',3) + 1 + >>> v.version_cmp(2,0,0,'rc',1) + -1 + """ + if not hasattr(self, '_parsed_version') \ + or self._parsed_version == None: + num_part = self.version().split(' ')[0] + self._parsed_version = [] + for num in num_part.split('.'): + try: + self._parsed_version.append(int(num)) + except ValueError, e: + # bzr version number might contain non-numerical tags + splitter = re.compile(r'[\D]') # Match non-digits + splits = splitter.split(num) + # if len(tag) > 1 some splits will be empty; remove + splits = filter(lambda s: s != '', splits) + tag_starti = len(splits[0]) + num_starti = num.find(splits[1], tag_starti) + tag = num[tag_starti:num_starti] + self._parsed_version.append(int(splits[0])) + self._parsed_version.append(tag) + self._parsed_version.append(int(splits[1])) + for current,other in zip(self._parsed_version, args): + if type(current) != type (other): + # one of them is a pre-release string + if type(current) != types.IntType: + return -1 + else: + return 1 + c = cmp(current,other) + if c != 0: + return c + # see if one is longer than the other + verlen = len(self._parsed_version) + arglen = len(args) + if verlen == arglen: + return 0 + elif verlen > arglen: + if type(self._parsed_version[arglen]) != types.IntType: + return -1 # self is a prerelease + else: + return 1 + else: + if type(args[verlen]) != types.IntType: + return 1 # args is a prerelease + else: + return -1 + def installed(self): if self.version() != None: return True diff --git a/libbe/storage/vcs/bzr.py b/libbe/storage/vcs/bzr.py index 0a4275b..865df6b 100644 --- a/libbe/storage/vcs/bzr.py +++ b/libbe/storage/vcs/bzr.py @@ -3,6 +3,7 @@ # Chris Ball <cjb@laptop.org> # Gianluca Montecchi <gian@grys.it> # Marien Zwart <marien.zwart@gmail.com> +# Michel Alexandre Salim <salimma@fedoraproject.org> # W. Trevor King <wking@drexel.edu> # # This file is part of Bugs Everywhere. @@ -40,7 +41,6 @@ import re import shutil import StringIO import sys -import types import libbe import base @@ -68,57 +68,6 @@ class Bzr(base.VCS): return None return bzrlib.__version__ - def version_cmp(self, *args): - """Compare the installed Bazaar version `V_i` with another version - `V_o` (given in `*args`). Returns - - === =============== - 1 if `V_i > V_o` - 0 if `V_i == V_o` - -1 if `V_i < V_o` - === =============== - - Examples - -------- - - >>> b = Bzr(repo='.') - >>> b._version = '2.3.1 (release)' - >>> b.version_cmp(2,3,1) - 0 - >>> b.version_cmp(2,3,2) - -1 - >>> b.version_cmp(2,3,0) - 1 - >>> b.version_cmp(3) - -1 - >>> b._version = '2.0.0pre2' - >>> b._parsed_version = None - >>> b.version_cmp(3) - -1 - >>> b.version_cmp(2,0,1) - Traceback (most recent call last): - ... - NotImplementedError: Cannot parse non-integer portion "0pre2" of Bzr version "2.0.0pre2" - """ - if not hasattr(self, '_parsed_version') \ - or self._parsed_version == None: - num_part = self.version().split(' ')[0] - self._parsed_version = [] - for num in num_part.split('.'): - try: - self._parsed_version.append(int(num)) - except ValueError, e: - self._parsed_version.append(num) - for current,other in zip(self._parsed_version, args): - if type(current) != types.IntType: - raise NotImplementedError( - 'Cannot parse non-integer portion "%s" of Bzr version "%s"' - % (current, self.version())) - c = cmp(current,other) - if c != 0: - return c - return 0 - def _vcs_get_user_id(self): # excerpted from bzrlib.builtins.cmd_whoami.run() try: diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index d2274ee..eade02e 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -3,6 +3,7 @@ # Chris Ball <cjb@laptop.org> # Gianluca Montecchi <gian@grys.it> # Marien Zwart <marien.zwart@gmail.com> +# Phil Schumm <philschumm@gmail.com> # W. Trevor King <wking@drexel.edu> # # This file is part of Bugs Everywhere. @@ -83,14 +84,18 @@ class Hg(base.VCS): assert len(kwargs) == 1, kwargs fullargs = ['--cwd', kwargs['cwd']] fullargs.extend(args) - stdout = sys.stdout - tmp_stdout = StringIO.StringIO() - sys.stdout = tmp_stdout cwd = os.getcwd() - mercurial.dispatch.dispatch(fullargs) + output = StringIO.StringIO() + if self.version_cmp(1,9) >= 0: + req = mercurial.dispatch.request(fullargs, fout=output) + mercurial.dispatch.dispatch(req) + else: + stdout = sys.stdout + sys.stdout = output + mercurial.dispatch.dispatch(fullargs) + sys.stdout = stdout os.chdir(cwd) - sys.stdout = stdout - return tmp_stdout.getvalue().rstrip('\n') + return output.getvalue().rstrip('\n') def _vcs_get_user_id(self): output = self._u_invoke_client( |