Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added pathutil.relpath, to support Python < 2.6

  • Loading branch information...
commit 2ee52af95b2f90ca08785a8e604ac8364d6de65f 1 parent d950d9d
@labisso labisso authored
Showing with 25 additions and 0 deletions.
  1. +25 −0 web/src/python/nimbusweb/setup/pathutil.py
View
25 web/src/python/nimbusweb/setup/pathutil.py
@@ -164,4 +164,29 @@ def write_repl_file(path, outputtext, log):
log.debug("Wrote '%s'." % path)
+relpath = None
+try:
+ # os.path.relpath is in 2.6+
+ relpath = getattr(os.path, 'relpath')
+except AttributeError:
+ relpath = _relpath
+# from Python 2.6 standard library, slightly modified
+def _relpath(path, start):
+ """Return a relative version of a path"""
+
+ if not path:
+ raise ValueError("no path specified")
+ if not start:
+ raise ValueError("no start specified")
+
+ start_list = os.path.abspath(start).split(os.path.sep)
+ path_list = os.path.abspath(path).split(os.path.sep)
+
+ # Work out how much of the filepath is shared by start and path.
+ i = len(os.path.commonprefix([start_list, path_list]))
+
+ rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:]
+ if not rel_list:
+ return curdir
+ return os.path.join(*rel_list)
Please sign in to comment.
Something went wrong with that request. Please try again.