You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/01/28 22:05:38 UTC

[1/2] ios commit: including a manual relpath function

including a manual relpath function

script originally used os.path.relpath, but that was introduced in
python 2.6, so anyone who is using an earlier version of python was
getting an error trying to create a project etc.


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/c9ed42f4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/c9ed42f4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/c9ed42f4

Branch: refs/heads/master
Commit: c9ed42f4ea24e1a3077ab7821a4ad2bf23fdb632
Parents: 97e7c2c
Author: Ben Nevile <be...@mainsocial.com>
Authored: Sun Jan 27 16:34:28 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Jan 28 16:03:41 2013 -0500

----------------------------------------------------------------------
 bin/update_cordova_subproject |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/c9ed42f4/bin/update_cordova_subproject
----------------------------------------------------------------------
diff --git a/bin/update_cordova_subproject b/bin/update_cordova_subproject
index fca4700..921431e 100755
--- a/bin/update_cordova_subproject
+++ b/bin/update_cordova_subproject
@@ -27,6 +27,7 @@ import fileinput
 import os
 import re
 import sys
+from posixpath import curdir, sep, pardir, join, abspath, commonprefix
 
 def Usage():
   print __doc__
@@ -53,6 +54,21 @@ def AbsProjectPath(relative_path):
     raise Exception('The following is not a valid path to an XCode project: %s' % project_path)
   return project_path
 
+def relpath(path, start=curdir):
+  # it would be nice to use os.path.relpath, 
+  # but that leaves out those with python < v2.6
+  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)
+
+
 def main(argv):
   if len(argv) < 2 or len(argv) > 3:
     Usage()
@@ -65,7 +81,7 @@ def main(argv):
     cordova_lib_xcode_path = AbsProjectPath(argv[2])
 
   parent_project_path = AbsParentPath(project_path)
-  subproject_path = os.path.relpath(cordova_lib_xcode_path, parent_project_path)
+  subproject_path = relpath(cordova_lib_xcode_path, parent_project_path)
 
   # /* CordovaLib.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = CordovaLib.xcodeproj; sourceTree = "<group>"; };
   REGEX = re.compile(r'(.+PBXFileReference.+wrapper.pb-project.+)(path = .+?;)(.*)(sourceTree.+;)(.+)')