changeset 156:2db236d25ecd

Improved the nativization of absolute paths by config.nativize_path
author Oleg Oshmyan <chortos@inbox.lv>
date Sat, 04 Jun 2011 01:31:55 +0100
parents f8041e1e4d0d
children 5f9e6121161a
files upreckon/config.py
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/upreckon/config.py	Sat Jun 04 00:14:16 2011 +0100
+++ b/upreckon/config.py	Sat Jun 04 01:31:55 2011 +0100
@@ -92,10 +92,16 @@
 		elif comp == '.':
 			comps[i] = os.path.curdir
 	native_path = os.path.join(*comps)
-	if posixpath.isabs(portable_path) != os.path.isabs(native_path):
+	if posixpath.isabs(portable_path) and not os.path.isabs(native_path):
+		abspath = os.path.abspath(native_path)
+		parent = os.path.dirname(abspath)
+		while parent != abspath:
+			abspath, parent = parent, os.path.dirname(parent)
+		native_path = os.path.join(parent, native_path)
+	elif not posixpath.isabs(portable_path) and os.path.isabs(native_path):
 		native_path = os.path.sep + native_path
-		if posixpath.isabs(portable_path) != os.path.isabs(native_path):
-			raise ValueError('cannot make native path relative/absolute')
+	if posixpath.isabs(portable_path) != os.path.isabs(native_path):
+		raise ValueError('cannot make native path relative/absolute')
 	return native_path
 
 def load_problem(problem_name):