d22951120189 webui

Changes to become Python 2.5 compatible
[view raw] [browse files]
author David Douard <david.douard@logilab.fr>
date Sat, 06 Feb 2010 13:30:55 +0100
parents 83f2e11a22be
children e5f1f96f7d75
branches/tags webui
files README review/api.py review/tests/test_init.py review/tests/util.py review/web_ui.py

Changes

--- a/README	Sat Feb 06 06:51:10 2010 -0500
+++ b/README	Sat Feb 06 13:30:55 2010 +0100
@@ -7,7 +7,7 @@
 Installing
 ==========
 
-`hg-review` requires Mercurial (probably 1.3.1+) and **Python 2.6+**.  Seriously, you need the latest version of Python.  I'm not going to rewrite `os.relpath()` to support older versions, sorry.
+`hg-review` requires Mercurial (probably 1.3.1+).
 
 Get it:
 
--- a/review/api.py	Sat Feb 06 06:51:10 2010 -0500
+++ b/review/api.py	Sat Feb 06 13:30:55 2010 +0100
@@ -9,6 +9,28 @@
 from mercurial import ui as _ui
 
 
+try:
+    from os.path import relpath
+except ImportError: # python < 2.6
+    from os.path import curdir, abspath, sep, commonprefix, pardir, join
+    def relpath(path, start=curdir):
+        """Return a relative version of a path"""
+
+        if not path:
+            raise ValueError("no path specified")
+
+        start_list = abspath(start).split(sep)
+        path_list = abspath(path).split(sep)
+
+        # Work out how much of the filepath is shared by start and path.
+        i = len(commonprefix([start_list, path_list]))
+
+        rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
+        if not rel_list:
+            return curdir
+        return join(*rel_list)
+
+
 DEFAULT_DATASTORE_DIRNAME = 'code-review'
 
 class PreexistingDatastore(Exception):
@@ -157,7 +179,7 @@
     
     """
     if repo:
-        p = os.path.relpath(os.path.realpath(p), start=repo.root)
+        p = relpath(os.path.realpath(p), start=repo.root)
     return '/'.join(_split_path_dammit(p))
 
 
--- a/review/tests/test_init.py	Sat Feb 06 06:51:10 2010 -0500
+++ b/review/tests/test_init.py	Sat Feb 06 13:30:55 2010 +0100
@@ -1,3 +1,4 @@
+from __future__ import with_statement
 from nose import *
 from util import *
 from .. import messages
--- a/review/tests/util.py	Sat Feb 06 06:51:10 2010 -0500
+++ b/review/tests/util.py	Sat Feb 06 13:30:55 2010 +0100
@@ -1,5 +1,5 @@
 """Utilities for writing unit tests for hg-review."""
-
+from __future__ import with_statement
 import os, shutil
 import sample_data
 from mercurial import cmdutil, commands, hg, ui
@@ -10,14 +10,15 @@
 def review(init=False, comment=False, signoff=False, yes=False, no=False,
     force=False, message='', rev='.', local_path='', remote_path='', lines='',
     files=None, unified='5', web=False):
-    
-    files = files if files else []
+
+    if not files:
+        files = []
     
     _ui.pushbuffer()
     extension_ui.review(_ui, get_sandbox_repo(), *files,
-        init=init, comment=comment, signoff=signoff, yes=yes, no=no, 
+        **dict(init=init, comment=comment, signoff=signoff, yes=yes, no=no, 
         force=force, message=message, rev=rev, local_path=local_path,
-        remote_path=remote_path, lines=lines, unified=unified, web=web)
+        remote_path=remote_path, lines=lines, unified=unified, web=web))
     output = _ui.popbuffer()
     
     print output
--- a/review/web_ui.py	Sat Feb 06 06:51:10 2010 -0500
+++ b/review/web_ui.py	Sat Feb 06 13:30:55 2010 +0100
@@ -1,4 +1,5 @@
 """The review extension's web UI."""
+from __future__ import with_statement
 
 import sys, os
 import api