Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Bug 784841 - Part 4: Use os.path.relpath in ConfigStatus.py; r=glandium
Browse files Browse the repository at this point in the history
We now require Python 2.7 and os.path.relpath is always available.
  • Loading branch information
indygreg committed Jan 16, 2013
1 parent 965633f commit 133aa74
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 46 deletions.
25 changes: 2 additions & 23 deletions build/ConfigStatus.py
Expand Up @@ -11,6 +11,8 @@
import sys, re, os, posixpath, ntpath
import errno
from StringIO import StringIO
from os.path import relpath

# Standalone js doesn't have virtualenv.
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'config'))
from Preprocessor import Preprocessor
Expand All @@ -21,29 +23,6 @@ def log(string):
if verbose:
print >>sys.stderr, string

# We need relpath, but it is introduced in python 2.6
# http://docs.python.org/library/os.path.html
def my_relpath(path, start):
"""
Return a relative version of a path
from /usr/lib/python2.6/posixpath.py
"""

if not path:
raise ValueError("no path 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 os.curdir
return os.path.join(*rel_list)

relpath = getattr(os.path, "relpath", my_relpath)

def ensureParentDir(file):
'''Ensures the directory parent to the given file exists'''
Expand Down
25 changes: 2 additions & 23 deletions js/src/build/ConfigStatus.py
Expand Up @@ -11,6 +11,8 @@
import sys, re, os, posixpath, ntpath
import errno
from StringIO import StringIO
from os.path import relpath

# Standalone js doesn't have virtualenv.
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'config'))
from Preprocessor import Preprocessor
Expand All @@ -21,29 +23,6 @@ def log(string):
if verbose:
print >>sys.stderr, string

# We need relpath, but it is introduced in python 2.6
# http://docs.python.org/library/os.path.html
def my_relpath(path, start):
"""
Return a relative version of a path
from /usr/lib/python2.6/posixpath.py
"""

if not path:
raise ValueError("no path 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 os.curdir
return os.path.join(*rel_list)

relpath = getattr(os.path, "relpath", my_relpath)

def ensureParentDir(file):
'''Ensures the directory parent to the given file exists'''
Expand Down

0 comments on commit 133aa74

Please sign in to comment.