]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/util/path.py
1 # Status: this module is ported on demand by however needs something
2 # from it. Functionality that is not needed by Python port will
5 # Copyright (C) Vladimir Prus 2002. Permission to copy, use, modify, sell and
6 # distribute this software is granted provided this copyright notice appears in
7 # all copies. This software is provided "as is" without express or implied
8 # warranty, and with no claim as to its suitability for any purpose.
10 # Performs various path manipulations. Path are always in a 'normilized'
11 # representation. In it, a path may be either:
15 # - ['/'] [ ( '..' '/' )* (token '/')* token ]
17 # In plain english, path can be rooted, '..' elements are allowed only
18 # at the beginning, and it never ends in slash, except for path consisting
22 from utility
import to_seq
23 from glob
import glob
as builtin_glob
25 from b2
.util
import bjam_signature
27 @bjam_signature((["path", "root"],))
28 def root (path
, root
):
29 """ If 'path' is relative, it is rooted at 'root'. Otherwise, it's unchanged.
31 if os
.path
.isabs (path
):
34 return os
.path
.join (root
, path
)
36 @bjam_signature((["native"],))
38 """ Converts the native path into normalized form.
40 # TODO: make os selection here.
41 return make_UNIX (native
)
43 @bjam_signature([['native']])
44 def make_UNIX (native
):
46 # VP: I have no idea now 'native' can be empty here! But it can!
49 return os
.path
.normpath (native
)
51 @bjam_signature((["path"],))
53 """ Builds a native representation of the path.
55 # TODO: make os selection here.
56 return native_UNIX (path
)
58 def native_UNIX (path
):
63 """ Returns the current working directory.
64 # TODO: is it a good idea to use the current dir? Some use-cases
65 may not allow us to depend on the current dir.
67 return make (os
.getcwd ())
70 """ Tests if a path is rooted.
72 return path
and path
[0] == '/'
75 ###################################################################
77 # Original lines are prefixed with "# "
79 # # Copyright (C) Vladimir Prus 2002. Permission to copy, use, modify, sell and
80 # # distribute this software is granted provided this copyright notice appears in
81 # # all copies. This software is provided "as is" without express or implied
82 # # warranty, and with no claim as to its suitability for any purpose.
84 # # Performs various path manipulations. Path are always in a 'normilized'
85 # # representation. In it, a path may be either:
89 # # - ['/'] [ ( '..' '/' )* (token '/')* token ]
91 # # In plain english, path can be rooted, '..' elements are allowed only
92 # # at the beginning, and it never ends in slash, except for path consisting
98 # import errors : error ;
101 # os = [ modules.peek : OS ] ;
102 # if [ modules.peek : UNIX ]
104 # local uname = [ modules.peek : JAMUNAME ] ;
116 # # Tests if a path is rooted.
118 # rule is-rooted ( path )
120 # return [ MATCH "^(/)" : $(path) ] ;
124 # # Tests if a path has a parent.
126 # rule has-parent ( path )
136 # # Returns the path without any directory components.
138 # rule basename ( path )
140 # return [ MATCH "([^/]+)$" : $(path) ] ;
144 # # Returns parent directory of the path. If no parent exists, error is issued.
146 # rule parent ( path )
148 # if [ has-parent $(path) ] {
154 # # Strip everything at the end of path up to and including
156 # local result = [ regex.match "((.*)/)?([^/]+)" : $(path) : 2 3 ] ;
158 # # Did we strip what we shouldn't?
159 # if $(result[2]) = ".." {
160 # return $(path)/.. ;
162 # if ! $(result[1]) {
163 # if [ is-rooted $(path) ] {
169 # return $(result[1]) ;
173 # error "Path '$(path)' has no parent" ;
178 # # Returns path2 such that "[ join path path2 ] = .".
179 # # The path may not contain ".." element or be rooted.
181 # rule reverse ( path )
189 # local tokens = [ regex.split $(path) "/" ] ;
191 # for local i in $(tokens) {
194 # return [ sequence.join $(tokens2) : "/" ] ;
198 """Returns path2 such that `os.path.join(path, path2) == '.'`.
199 `path` may not contain '..' or be rooted.
202 path (str): the path to reverse
205 the string of the reversed path
209 >>> p1 = 'path/to/somewhere'
210 >>> p2 = reverse('path/to/somewhere')
213 >>> os.path.normpath(os.path.join(p1, p2))
216 if is_rooted(path
) or '..' in path
:
217 from b2
.manager
import get_manager
218 get_manager().errors()(
219 'reverse(path): path is either rooted or contains ".." in the path')
222 path
= os
.path
.normpath(path
)
223 # os.sep.join() is being used over os.path.join() due
224 # to an extra '..' that is created by os.path.join()
225 return os
.sep
.join('..' for t
in path
.split(os
.sep
))
227 # # Auxillary rule: does all the semantic of 'join', except for error cheching.
228 # # The error checking is separated because this rule is recursive, and I don't
229 # # like the idea of checking the same input over and over.
231 # local rule join-imp ( elements + )
233 # return [ NORMALIZE_PATH $(elements:J="/") ] ;
237 # # Contanenates the passed path elements. Generates an error if
238 # # any element other than the first one is rooted.
240 # rule join ( elements + )
242 # if ! $(elements[2])
244 # return $(elements[1]) ;
248 # for local e in $(elements[2-])
250 # if [ is-rooted $(e) ]
252 # error only first element may be rooted ;
255 # return [ join-imp $(elements) ] ;
260 def glob (dirs
, patterns
):
261 """ Returns the list of files matching the given pattern in the
262 specified directory. Both directories and patterns are
263 supplied as portable paths. Each pattern should be non-absolute
264 path, and can't contain "." or ".." elements. Each slash separated
265 element of pattern can contain the following special characters:
266 - '?', which match any character
267 - '*', which matches arbitrary number of characters.
268 A file $(d)/e1/e2/e3 (where 'd' is in $(dirs)) matches pattern p1/p2/p3
269 if and only if e1 matches p1, e2 matches p2 and so on.
273 [ glob . : */build/Jamfile ]
279 # # When a pattern has a directory element, we first glob for
280 # # directory, and then glob for file name is the found directories.
281 # for local p in $(patterns)
283 # # First glob for directory part.
284 # local globbed-dirs = [ glob $(dirs) : $(p:D) ] ;
285 # result += [ glob $(globbed-dirs) : $(p:D="") ] ;
290 # # When a pattern has not directory, we glob directly.
291 # # Take care of special ".." value. The "GLOB" rule simply ignores
292 # # the ".." element (and ".") element in directory listings. This is
295 # # [ glob libs/*/Jamfile ]
299 # # libs/../Jamfile (which is the same as ./Jamfile)
301 # # On the other hand, when ".." is explicitly present in the pattern
302 # # we need to return it.
304 # for local dir in $(dirs)
306 # for local p in $(patterns)
310 # result += [ sequence.transform make
311 # : [ GLOB [ native $(dir) ] : $(p) ] ] ;
315 # result += [ path.join $(dir) .. ] ;
324 # TODO: (PF) I replaced the code above by this. I think it should work but needs to be tested.
327 patterns
= to_seq (patterns
)
331 splitdirs
+= dir.split (os
.pathsep
)
333 for dir in splitdirs
:
334 for pattern
in patterns
:
335 p
= os
.path
.join (dir, pattern
)
337 result
.extend (glob
.glob (p
))
341 # Find out the absolute name of path and returns the list of all the parents,
342 # starting with the immediate one. Parents are returned as relative names.
343 # If 'upper_limit' is specified, directories above it will be pruned.
345 def all_parents(path
, upper_limit
=None, cwd
=None):
350 path_abs
= os
.path
.join(cwd
, path
)
353 upper_limit
= os
.path
.join(cwd
, upper_limit
)
356 while path_abs
and path_abs
!= upper_limit
:
357 (head
, tail
) = os
.path
.split(path
)
358 path
= os
.path
.join(path
, "..")
362 if upper_limit
and path_abs
!= upper_limit
:
363 raise BaseException("'%s' is not a prefix of '%s'" % (upper_limit
, path
))
367 # Search for 'pattern' in parent directories of 'dir', up till and including
368 # 'upper_limit', if it is specified, or till the filesystem root otherwise.
370 def glob_in_parents(dir, patterns
, upper_limit
=None):
373 parent_dirs
= all_parents(dir, upper_limit
)
375 for p
in parent_dirs
:
376 result
= glob(p
, patterns
)
383 # # Assuming 'child' is a subdirectory of 'parent', return the relative
384 # # path from 'parent' to 'child'
386 # rule relative ( child parent )
394 # local split1 = [ regex.split $(parent) / ] ;
395 # local split2 = [ regex.split $(child) / ] ;
399 # if $(split1[1]) = $(split2[1])
401 # split1 = $(split1[2-]) ;
402 # split2 = $(split2[2-]) ;
406 # errors.error $(child) is not a subdir of $(parent) ;
409 # return [ join $(split2) ] ;
413 # # Returns the minimal path to path2 that is relative path1.
415 # rule relative-to ( path1 path2 )
417 # local root_1 = [ regex.split [ reverse $(path1) ] / ] ;
418 # local split1 = [ regex.split $(path1) / ] ;
419 # local split2 = [ regex.split $(path2) / ] ;
421 # while $(split1) && $(root_1)
423 # if $(split1[1]) = $(split2[1])
425 # root_1 = $(root_1[2-]) ;
426 # split1 = $(split1[2-]) ;
427 # split2 = $(split2[2-]) ;
434 # return [ join . $(root_1) $(split2) ] ;
437 # Returns the list of paths which are used by the operating system
438 # for looking up programs
439 def programs_path ():
441 names
= ['PATH', 'Path', 'path']
444 raw
.append(os
.environ
.get (name
, ''))
449 for p
in elem
.split(os
.path
.pathsep
):
450 # it's possible that the user's Path has
451 # double path separators, thus it is possible
452 # for p to be an empty string.
454 result
.append(make(p
))
458 # rule make-NT ( native )
460 # local tokens = [ regex.split $(native) "[/\\]" ] ;
463 # # Handle paths ending with slashes
464 # if $(tokens[-1]) = ""
466 # tokens = $(tokens[1--2]) ; # discard the empty element
469 # result = [ path.join $(tokens) ] ;
471 # if [ regex.match "(^.:)" : $(native) ]
473 # result = /$(result) ;
484 # rule native-NT ( path )
486 # local result = [ MATCH "^/?(.*)" : $(path) ] ;
487 # result = [ sequence.join [ regex.split $(result) "/" ] : "\\" ] ;
491 # rule make-CYGWIN ( path )
493 # return [ make-NT $(path) ] ;
496 # rule native-CYGWIN ( path )
498 # local result = $(path) ;
499 # if [ regex.match "(^/.:)" : $(path) ] # win absolute
501 # result = [ MATCH "^/?(.*)" : $(path) ] ; # remove leading '/'
503 # return [ native-UNIX $(result) ] ;
507 # # split-VMS: splits input native path into
508 # # device dir file (each part is optional),
511 # # dev:[dir]file.c => dev: [dir] file.c
513 # rule split-path-VMS ( native )
515 # local matches = [ MATCH ([a-zA-Z0-9_-]+:)?(\\[[^\]]*\\])?(.*)?$ : $(native) ] ;
516 # local device = $(matches[1]) ;
517 # local dir = $(matches[2]) ;
518 # local file = $(matches[3]) ;
520 # return $(device) $(dir) $(file) ;
524 # # Converts a native VMS path into a portable path spec.
526 # # Does not handle current-device absolute paths such
527 # # as "[dir]File.c" as it is not clear how to represent
528 # # them in the portable path notation.
530 # # Adds a trailing dot (".") to the file part if no extension
531 # # is present (helps when converting it back into native path).
533 # rule make-VMS ( native )
535 # if [ MATCH ^(\\[[a-zA-Z0-9]) : $(native) ]
537 # errors.error "Can't handle default-device absolute paths: " $(native) ;
540 # local parts = [ split-path-VMS $(native) ] ;
541 # local device = $(parts[1]) ;
542 # local dir = $(parts[2]) ;
543 # local file = $(parts[3]) ;
551 # elems = /$(device) ;
557 # # Special case: current directory
559 # elems = $(elems) "." ;
563 # dir = [ regex.replace $(dir) "\\[|\\]" "" ] ;
564 # local dir_parts = [ regex.split $(dir) \\. ] ;
566 # if $(dir_parts[1]) = ""
571 # dir_parts = $(dir_parts[2--1]) ;
575 # # replace "parent-directory" parts (- => ..)
577 # dir_parts = [ regex.replace-list $(dir_parts) : - : .. ] ;
579 # elems = $(elems) $(dir_parts) ;
584 # if ! [ MATCH (\\.) : $(file) ]
587 # # Always add "." to end of non-extension file
591 # elems = $(elems) $(file) ;
594 # local portable = [ path.join $(elems) ] ;
596 # return $(portable) ;
600 # # Converts a portable path spec into a native VMS path.
602 # # Relies on having at least one dot (".") included in the file
603 # # name to be able to differentiate it ftom the directory part.
605 # rule native-VMS ( path )
607 # local device = "" ;
608 # local dir = $(path) ;
616 # if [ is-rooted $(dir) ]
618 # split = [ MATCH ^/([^:]+:)/?(.*) : $(dir) ] ;
619 # device = $(split[1]) ;
620 # dir = $(split[2]) ;
626 # # This is no exact science, just guess work:
628 # # If the last part of the current path spec
629 # # includes some chars, followed by a dot,
630 # # optionally followed by more chars -
631 # # then it is a file (keep your fingers crossed).
633 # split = [ regex.split $(dir) / ] ;
634 # local maybe_file = $(split[-1]) ;
636 # if [ MATCH ^([^.]+\\..*) : $(maybe_file) ]
638 # file = $(maybe_file) ;
639 # dir = [ sequence.join $(split[1--2]) : / ] ;
651 # dir = [ regex.replace $(dir) \\.\\. - ] ;
652 # dir = [ regex.replace $(dir) / . ] ;
657 # # Relative directory
661 # dir = "["$(dir)"]" ;
664 # native = [ sequence.join $(device) $(dir) $(file) ] ;
670 # rule __test__ ( ) {
673 # import errors : try catch ;
675 # assert.true is-rooted "/" ;
676 # assert.true is-rooted "/foo" ;
677 # assert.true is-rooted "/foo/bar" ;
678 # assert.result : is-rooted "." ;
679 # assert.result : is-rooted "foo" ;
680 # assert.result : is-rooted "foo/bar" ;
682 # assert.true has-parent "foo" ;
683 # assert.true has-parent "foo/bar" ;
684 # assert.true has-parent "." ;
685 # assert.result : has-parent "/" ;
687 # assert.result "." : basename "." ;
688 # assert.result ".." : basename ".." ;
689 # assert.result "foo" : basename "foo" ;
690 # assert.result "foo" : basename "bar/foo" ;
691 # assert.result "foo" : basename "gaz/bar/foo" ;
692 # assert.result "foo" : basename "/gaz/bar/foo" ;
694 # assert.result "." : parent "foo" ;
695 # assert.result "/" : parent "/foo" ;
696 # assert.result "foo/bar" : parent "foo/bar/giz" ;
697 # assert.result ".." : parent "." ;
698 # assert.result ".." : parent "../foo" ;
699 # assert.result "../../foo" : parent "../../foo/bar" ;
702 # assert.result "." : reverse "." ;
703 # assert.result ".." : reverse "foo" ;
704 # assert.result "../../.." : reverse "foo/bar/giz" ;
706 # assert.result "foo" : join "foo" ;
707 # assert.result "/foo" : join "/" "foo" ;
708 # assert.result "foo/bar" : join "foo" "bar" ;
709 # assert.result "foo/bar" : join "foo/giz" "../bar" ;
710 # assert.result "foo/giz" : join "foo/bar/baz" "../../giz" ;
711 # assert.result ".." : join "." ".." ;
712 # assert.result ".." : join "foo" "../.." ;
713 # assert.result "../.." : join "../foo" "../.." ;
714 # assert.result "/foo" : join "/bar" "../foo" ;
715 # assert.result "foo/giz" : join "foo/giz" "." ;
716 # assert.result "." : join lib2 ".." ;
717 # assert.result "/" : join "/a" ".." ;
719 # assert.result /a/b : join /a/b/c .. ;
721 # assert.result "foo/bar/giz" : join "foo" "bar" "giz" ;
722 # assert.result "giz" : join "foo" ".." "giz" ;
723 # assert.result "foo/giz" : join "foo" "." "giz" ;
729 # catch only first element may be rooted ;
731 # local CWD = "/home/ghost/build" ;
732 # assert.result : all-parents . : . : $(CWD) ;
733 # assert.result . .. ../.. ../../.. : all-parents "Jamfile" : "" : $(CWD) ;
734 # assert.result foo . .. ../.. ../../.. : all-parents "foo/Jamfile" : "" : $(CWD) ;
735 # assert.result ../Work .. ../.. ../../.. : all-parents "../Work/Jamfile" : "" : $(CWD) ;
737 # local CWD = "/home/ghost" ;
738 # assert.result . .. : all-parents "Jamfile" : "/home" : $(CWD) ;
739 # assert.result . : all-parents "Jamfile" : "/home/ghost" : $(CWD) ;
741 # assert.result "c/d" : relative "a/b/c/d" "a/b" ;
742 # assert.result "foo" : relative "foo" "." ;
744 # local save-os = [ modules.peek path : os ] ;
745 # modules.poke path : os : NT ;
747 # assert.result "foo/bar/giz" : make "foo/bar/giz" ;
748 # assert.result "foo/bar/giz" : make "foo\\bar\\giz" ;
749 # assert.result "foo" : make "foo/." ;
750 # assert.result "foo" : make "foo/bar/.." ;
751 # assert.result "/D:/My Documents" : make "D:\\My Documents" ;
752 # assert.result "/c:/boost/tools/build/new/project.jam" : make "c:\\boost\\tools\\build\\test\\..\\new\\project.jam" ;
754 # assert.result "foo\\bar\\giz" : native "foo/bar/giz" ;
755 # assert.result "foo" : native "foo" ;
756 # assert.result "D:\\My Documents\\Work" : native "/D:/My Documents/Work" ;
758 # modules.poke path : os : UNIX ;
760 # assert.result "foo/bar/giz" : make "foo/bar/giz" ;
761 # assert.result "/sub1" : make "/sub1/." ;
762 # assert.result "/sub1" : make "/sub1/sub2/.." ;
763 # assert.result "sub1" : make "sub1/." ;
764 # assert.result "sub1" : make "sub1/sub2/.." ;
765 # assert.result "/foo/bar" : native "/foo/bar" ;
767 # modules.poke path : os : VMS ;
770 # # Don't really need to poke os before these
772 # assert.result "disk:" "[dir]" "file" : split-path-VMS "disk:[dir]file" ;
773 # assert.result "disk:" "[dir]" "" : split-path-VMS "disk:[dir]" ;
774 # assert.result "disk:" "" "" : split-path-VMS "disk:" ;
775 # assert.result "disk:" "" "file" : split-path-VMS "disk:file" ;
776 # assert.result "" "[dir]" "file" : split-path-VMS "[dir]file" ;
777 # assert.result "" "[dir]" "" : split-path-VMS "[dir]" ;
778 # assert.result "" "" "file" : split-path-VMS "file" ;
779 # assert.result "" "" "" : split-path-VMS "" ;
782 # # Special case: current directory
784 # assert.result "" "[]" "" : split-path-VMS "[]" ;
785 # assert.result "disk:" "[]" "" : split-path-VMS "disk:[]" ;
786 # assert.result "" "[]" "file" : split-path-VMS "[]file" ;
787 # assert.result "disk:" "[]" "file" : split-path-VMS "disk:[]file" ;
790 # # Make portable paths
792 # assert.result "/disk:" : make "disk:" ;
793 # assert.result "foo/bar/giz" : make "[.foo.bar.giz]" ;
794 # assert.result "foo" : make "[.foo]" ;
795 # assert.result "foo" : make "[.foo.bar.-]" ;
796 # assert.result ".." : make "[.-]" ;
797 # assert.result ".." : make "[-]" ;
798 # assert.result "." : make "[]" ;
799 # assert.result "giz.h" : make "giz.h" ;
800 # assert.result "foo/bar/giz.h" : make "[.foo.bar]giz.h" ;
801 # assert.result "/disk:/my_docs" : make "disk:[my_docs]" ;
802 # assert.result "/disk:/boost/tools/build/new/project.jam" : make "disk:[boost.tools.build.test.-.new]project.jam" ;
805 # # Special case (adds '.' to end of file w/o extension to
806 # # disambiguate from directory in portable path spec).
808 # assert.result "Jamfile." : make "Jamfile" ;
809 # assert.result "dir/Jamfile." : make "[.dir]Jamfile" ;
810 # assert.result "/disk:/dir/Jamfile." : make "disk:[dir]Jamfile" ;
813 # # Make native paths
815 # assert.result "disk:" : native "/disk:" ;
816 # assert.result "[.foo.bar.giz]" : native "foo/bar/giz" ;
817 # assert.result "[.foo]" : native "foo" ;
818 # assert.result "[.-]" : native ".." ;
819 # assert.result "[.foo.-]" : native "foo/.." ;
820 # assert.result "[]" : native "." ;
821 # assert.result "disk:[my_docs.work]" : native "/disk:/my_docs/work" ;
822 # assert.result "giz.h" : native "giz.h" ;
823 # assert.result "disk:Jamfile." : native "/disk:Jamfile." ;
824 # assert.result "disk:[my_docs.work]Jamfile." : native "/disk:/my_docs/work/Jamfile." ;
826 # modules.poke path : os : $(save-os) ;
833 #def glob(dir, patterns):
835 # for pattern in patterns:
836 # result.extend(builtin_glob(os.path.join(dir, pattern)))
839 def glob(dirs
, patterns
, exclude_patterns
=None):
840 """Returns the list of files matching the given pattern in the
841 specified directory. Both directories and patterns are
842 supplied as portable paths. Each pattern should be non-absolute
843 path, and can't contain '.' or '..' elements. Each slash separated
844 element of pattern can contain the following special characters:
845 - '?', which match any character
846 - '*', which matches arbitrary number of characters.
847 A file $(d)/e1/e2/e3 (where 'd' is in $(dirs)) matches pattern p1/p2/p3
848 if and only if e1 matches p1, e2 matches p2 and so on.
851 [ glob . : */build/Jamfile ]
854 assert(isinstance(patterns
, list))
855 assert(isinstance(dirs
, list))
857 if not exclude_patterns
:
858 exclude_patterns
= []
860 assert(isinstance(exclude_patterns
, list))
862 real_patterns
= [os
.path
.join(d
, p
) for p
in patterns
for d
in dirs
]
863 real_exclude_patterns
= [os
.path
.join(d
, p
) for p
in exclude_patterns
866 inc
= [os
.path
.normpath(name
) for p
in real_patterns
867 for name
in builtin_glob(p
)]
868 exc
= [os
.path
.normpath(name
) for p
in real_exclude_patterns
869 for name
in builtin_glob(p
)]
870 return [x
for x
in inc
if x
not in exc
]
872 def glob_tree(roots
, patterns
, exclude_patterns
=None):
873 """Recursive version of GLOB. Builds the glob of files while
874 also searching in the subdirectories of the given roots. An
875 optional set of exclusion patterns will filter out the
876 matching entries from the result. The exclusions also apply
877 to the subdirectory scanning, such that directories that
878 match the exclusion patterns will not be searched."""
880 if not exclude_patterns
:
881 exclude_patterns
= []
883 result
= glob(roots
, patterns
, exclude_patterns
)
884 subdirs
= [s
for s
in glob(roots
, ["*"], exclude_patterns
) if s
!= "." and s
!= ".." and os
.path
.isdir(s
)]
886 result
.extend(glob_tree(subdirs
, patterns
, exclude_patterns
))
890 def glob_in_parents(dir, patterns
, upper_limit
=None):
891 """Recursive version of GLOB which glob sall parent directories
892 of dir until the first match is found. Returns an empty result if no match
895 assert(isinstance(dir, str))
896 assert(isinstance(patterns
, list))
900 absolute_dir
= os
.path
.join(os
.getcwd(), dir)
901 absolute_dir
= os
.path
.normpath(absolute_dir
)
903 new_dir
= os
.path
.split(absolute_dir
)[0]
904 if new_dir
== absolute_dir
:
906 result
= glob([new_dir
], patterns
)
909 absolute_dir
= new_dir
914 # The relpath functionality is written by
916 def split(p
, rest
=[]):
917 (h
,t
) = os
.path
.split(p
)
918 if len(h
) < 1: return [t
]+rest
919 if len(t
) < 1: return [h
]+rest
920 return split(h
,[t
]+rest
)
922 def commonpath(l1
, l2
, common
=[]):
923 if len(l1
) < 1: return (common
, l1
, l2
)
924 if len(l2
) < 1: return (common
, l1
, l2
)
925 if l1
[0] != l2
[0]: return (common
, l1
, l2
)
926 return commonpath(l1
[1:], l2
[1:], common
+[l1
[0]])
929 (common
,l1
,l2
) = commonpath(split(p1
), split(p2
))
932 p
= [ '../' * len(l1
) ]
935 return os
.path
.join( *p
)