Mercurial > repos > yating-l > jbrowsearchivecreator
annotate test/lib/python2.7/ntpath.py @ 3:7d1a9a91b989 draft
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
| author | yating-l | 
|---|---|
| date | Thu, 18 May 2017 18:37:28 -0400 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 3 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 1 # Module 'ntpath' -- common operations on WinNT/Win95 pathnames | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 2 """Common pathname manipulations, WindowsNT/95 version. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 3 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 4 Instead of importing this module directly, import os and refer to this | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 5 module as os.path. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 6 """ | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 7 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 8 import os | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 9 import sys | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 10 import stat | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 11 import genericpath | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 12 import warnings | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 13 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 14 from genericpath import * | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 15 from genericpath import _unicode | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 16 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 17 __all__ = ["normcase","isabs","join","splitdrive","split","splitext", | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 18 "basename","dirname","commonprefix","getsize","getmtime", | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 19 "getatime","getctime", "islink","exists","lexists","isdir","isfile", | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 20 "ismount","walk","expanduser","expandvars","normpath","abspath", | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 21 "splitunc","curdir","pardir","sep","pathsep","defpath","altsep", | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 22 "extsep","devnull","realpath","supports_unicode_filenames","relpath"] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 23 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 24 # strings representing various path-related bits and pieces | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 25 curdir = '.' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 26 pardir = '..' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 27 extsep = '.' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 28 sep = '\\' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 29 pathsep = ';' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 30 altsep = '/' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 31 defpath = '.;C:\\bin' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 32 if 'ce' in sys.builtin_module_names: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 33 defpath = '\\Windows' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 34 elif 'os2' in sys.builtin_module_names: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 35 # OS/2 w/ VACPP | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 36 altsep = '/' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 37 devnull = 'nul' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 38 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 39 # Normalize the case of a pathname and map slashes to backslashes. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 40 # Other normalizations (such as optimizing '../' away) are not done | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 41 # (this is done by normpath). | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 42 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 43 def normcase(s): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 44 """Normalize case of pathname. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 45 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 46 Makes all characters lowercase and all slashes into backslashes.""" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 47 return s.replace("/", "\\").lower() | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 48 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 49 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 50 # Return whether a path is absolute. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 51 # Trivial in Posix, harder on the Mac or MS-DOS. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 52 # For DOS it is absolute if it starts with a slash or backslash (current | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 53 # volume), or if a pathname after the volume letter and colon / UNC resource | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 54 # starts with a slash or backslash. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 55 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 56 def isabs(s): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 57 """Test whether a path is absolute""" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 58 s = splitdrive(s)[1] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 59 return s != '' and s[:1] in '/\\' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 60 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 61 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 62 # Join two (or more) paths. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 63 def join(path, *paths): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 64 """Join two or more pathname components, inserting "\\" as needed.""" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 65 result_drive, result_path = splitdrive(path) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 66 for p in paths: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 67 p_drive, p_path = splitdrive(p) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 68 if p_path and p_path[0] in '\\/': | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 69 # Second path is absolute | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 70 if p_drive or not result_drive: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 71 result_drive = p_drive | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 72 result_path = p_path | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 73 continue | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 74 elif p_drive and p_drive != result_drive: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 75 if p_drive.lower() != result_drive.lower(): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 76 # Different drives => ignore the first path entirely | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 77 result_drive = p_drive | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 78 result_path = p_path | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 79 continue | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 80 # Same drive in different case | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 81 result_drive = p_drive | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 82 # Second path is relative to the first | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 83 if result_path and result_path[-1] not in '\\/': | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 84 result_path = result_path + '\\' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 85 result_path = result_path + p_path | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 86 ## add separator between UNC and non-absolute path | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 87 if (result_path and result_path[0] not in '\\/' and | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 88 result_drive and result_drive[-1:] != ':'): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 89 return result_drive + sep + result_path | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 90 return result_drive + result_path | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 91 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 92 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 93 # Split a path in a drive specification (a drive letter followed by a | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 94 # colon) and the path specification. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 95 # It is always true that drivespec + pathspec == p | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 96 def splitdrive(p): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 97 """Split a pathname into drive/UNC sharepoint and relative path specifiers. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 98 Returns a 2-tuple (drive_or_unc, path); either part may be empty. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 99 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 100 If you assign | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 101 result = splitdrive(p) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 102 It is always true that: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 103 result[0] + result[1] == p | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 104 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 105 If the path contained a drive letter, drive_or_unc will contain everything | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 106 up to and including the colon. e.g. splitdrive("c:/dir") returns ("c:", "/dir") | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 107 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 108 If the path contained a UNC path, the drive_or_unc will contain the host name | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 109 and share up to but not including the fourth directory separator character. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 110 e.g. splitdrive("//host/computer/dir") returns ("//host/computer", "/dir") | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 111 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 112 Paths cannot contain both a drive letter and a UNC path. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 113 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 114 """ | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 115 if len(p) > 1: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 116 normp = p.replace(altsep, sep) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 117 if (normp[0:2] == sep*2) and (normp[2:3] != sep): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 118 # is a UNC path: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 119 # vvvvvvvvvvvvvvvvvvvv drive letter or UNC path | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 120 # \\machine\mountpoint\directory\etc\... | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 121 # directory ^^^^^^^^^^^^^^^ | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 122 index = normp.find(sep, 2) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 123 if index == -1: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 124 return '', p | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 125 index2 = normp.find(sep, index + 1) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 126 # a UNC path can't have two slashes in a row | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 127 # (after the initial two) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 128 if index2 == index + 1: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 129 return '', p | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 130 if index2 == -1: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 131 index2 = len(p) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 132 return p[:index2], p[index2:] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 133 if normp[1] == ':': | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 134 return p[:2], p[2:] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 135 return '', p | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 136 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 137 # Parse UNC paths | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 138 def splitunc(p): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 139 """Split a pathname into UNC mount point and relative path specifiers. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 140 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 141 Return a 2-tuple (unc, rest); either part may be empty. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 142 If unc is not empty, it has the form '//host/mount' (or similar | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 143 using backslashes). unc+rest is always the input path. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 144 Paths containing drive letters never have a UNC part. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 145 """ | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 146 if p[1:2] == ':': | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 147 return '', p # Drive letter present | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 148 firstTwo = p[0:2] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 149 if firstTwo == '//' or firstTwo == '\\\\': | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 150 # is a UNC path: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 151 # vvvvvvvvvvvvvvvvvvvv equivalent to drive letter | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 152 # \\machine\mountpoint\directories... | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 153 # directory ^^^^^^^^^^^^^^^ | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 154 normp = p.replace('\\', '/') | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 155 index = normp.find('/', 2) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 156 if index <= 2: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 157 return '', p | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 158 index2 = normp.find('/', index + 1) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 159 # a UNC path can't have two slashes in a row | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 160 # (after the initial two) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 161 if index2 == index + 1: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 162 return '', p | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 163 if index2 == -1: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 164 index2 = len(p) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 165 return p[:index2], p[index2:] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 166 return '', p | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 167 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 168 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 169 # Split a path in head (everything up to the last '/') and tail (the | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 170 # rest). After the trailing '/' is stripped, the invariant | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 171 # join(head, tail) == p holds. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 172 # The resulting head won't end in '/' unless it is the root. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 173 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 174 def split(p): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 175 """Split a pathname. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 176 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 177 Return tuple (head, tail) where tail is everything after the final slash. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 178 Either part may be empty.""" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 179 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 180 d, p = splitdrive(p) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 181 # set i to index beyond p's last slash | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 182 i = len(p) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 183 while i and p[i-1] not in '/\\': | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 184 i = i - 1 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 185 head, tail = p[:i], p[i:] # now tail has no slashes | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 186 # remove trailing slashes from head, unless it's all slashes | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 187 head2 = head | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 188 while head2 and head2[-1] in '/\\': | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 189 head2 = head2[:-1] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 190 head = head2 or head | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 191 return d + head, tail | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 192 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 193 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 194 # Split a path in root and extension. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 195 # The extension is everything starting at the last dot in the last | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 196 # pathname component; the root is everything before that. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 197 # It is always true that root + ext == p. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 198 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 199 def splitext(p): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 200 return genericpath._splitext(p, sep, altsep, extsep) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 201 splitext.__doc__ = genericpath._splitext.__doc__ | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 202 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 203 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 204 # Return the tail (basename) part of a path. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 205 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 206 def basename(p): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 207 """Returns the final component of a pathname""" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 208 return split(p)[1] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 209 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 210 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 211 # Return the head (dirname) part of a path. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 212 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 213 def dirname(p): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 214 """Returns the directory component of a pathname""" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 215 return split(p)[0] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 216 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 217 # Is a path a symbolic link? | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 218 # This will always return false on systems where posix.lstat doesn't exist. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 219 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 220 def islink(path): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 221 """Test for symbolic link. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 222 On WindowsNT/95 and OS/2 always returns false | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 223 """ | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 224 return False | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 225 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 226 # alias exists to lexists | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 227 lexists = exists | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 228 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 229 # Is a path a mount point? Either a root (with or without drive letter) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 230 # or a UNC path with at most a / or \ after the mount point. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 231 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 232 def ismount(path): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 233 """Test whether a path is a mount point (defined as root of drive)""" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 234 unc, rest = splitunc(path) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 235 if unc: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 236 return rest in ("", "/", "\\") | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 237 p = splitdrive(path)[1] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 238 return len(p) == 1 and p[0] in '/\\' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 239 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 240 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 241 # Directory tree walk. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 242 # For each directory under top (including top itself, but excluding | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 243 # '.' and '..'), func(arg, dirname, filenames) is called, where | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 244 # dirname is the name of the directory and filenames is the list | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 245 # of files (and subdirectories etc.) in the directory. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 246 # The func may modify the filenames list, to implement a filter, | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 247 # or to impose a different order of visiting. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 248 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 249 def walk(top, func, arg): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 250 """Directory tree walk with callback function. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 251 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 252 For each directory in the directory tree rooted at top (including top | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 253 itself, but excluding '.' and '..'), call func(arg, dirname, fnames). | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 254 dirname is the name of the directory, and fnames a list of the names of | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 255 the files and subdirectories in dirname (excluding '.' and '..'). func | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 256 may modify the fnames list in-place (e.g. via del or slice assignment), | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 257 and walk will only recurse into the subdirectories whose names remain in | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 258 fnames; this can be used to implement a filter, or to impose a specific | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 259 order of visiting. No semantics are defined for, or required of, arg, | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 260 beyond that arg is always passed to func. It can be used, e.g., to pass | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 261 a filename pattern, or a mutable object designed to accumulate | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 262 statistics. Passing None for arg is common.""" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 263 warnings.warnpy3k("In 3.x, os.path.walk is removed in favor of os.walk.", | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 264 stacklevel=2) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 265 try: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 266 names = os.listdir(top) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 267 except os.error: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 268 return | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 269 func(arg, top, names) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 270 for name in names: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 271 name = join(top, name) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 272 if isdir(name): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 273 walk(name, func, arg) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 274 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 275 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 276 # Expand paths beginning with '~' or '~user'. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 277 # '~' means $HOME; '~user' means that user's home directory. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 278 # If the path doesn't begin with '~', or if the user or $HOME is unknown, | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 279 # the path is returned unchanged (leaving error reporting to whatever | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 280 # function is called with the expanded path as argument). | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 281 # See also module 'glob' for expansion of *, ? and [...] in pathnames. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 282 # (A function should also be defined to do full *sh-style environment | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 283 # variable expansion.) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 284 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 285 def expanduser(path): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 286 """Expand ~ and ~user constructs. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 287 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 288 If user or $HOME is unknown, do nothing.""" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 289 if path[:1] != '~': | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 290 return path | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 291 i, n = 1, len(path) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 292 while i < n and path[i] not in '/\\': | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 293 i = i + 1 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 294 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 295 if 'HOME' in os.environ: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 296 userhome = os.environ['HOME'] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 297 elif 'USERPROFILE' in os.environ: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 298 userhome = os.environ['USERPROFILE'] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 299 elif not 'HOMEPATH' in os.environ: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 300 return path | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 301 else: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 302 try: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 303 drive = os.environ['HOMEDRIVE'] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 304 except KeyError: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 305 drive = '' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 306 userhome = join(drive, os.environ['HOMEPATH']) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 307 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 308 if i != 1: #~user | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 309 userhome = join(dirname(userhome), path[1:i]) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 310 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 311 return userhome + path[i:] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 312 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 313 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 314 # Expand paths containing shell variable substitutions. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 315 # The following rules apply: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 316 # - no expansion within single quotes | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 317 # - '$$' is translated into '$' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 318 # - '%%' is translated into '%' if '%%' are not seen in %var1%%var2% | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 319 # - ${varname} is accepted. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 320 # - $varname is accepted. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 321 # - %varname% is accepted. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 322 # - varnames can be made out of letters, digits and the characters '_-' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 323 # (though is not verified in the ${varname} and %varname% cases) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 324 # XXX With COMMAND.COM you can use any characters in a variable name, | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 325 # XXX except '^|<>='. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 326 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 327 def expandvars(path): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 328 """Expand shell variables of the forms $var, ${var} and %var%. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 329 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 330 Unknown variables are left unchanged.""" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 331 if '$' not in path and '%' not in path: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 332 return path | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 333 import string | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 334 varchars = string.ascii_letters + string.digits + '_-' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 335 if isinstance(path, _unicode): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 336 encoding = sys.getfilesystemencoding() | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 337 def getenv(var): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 338 return os.environ[var.encode(encoding)].decode(encoding) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 339 else: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 340 def getenv(var): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 341 return os.environ[var] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 342 res = '' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 343 index = 0 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 344 pathlen = len(path) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 345 while index < pathlen: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 346 c = path[index] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 347 if c == '\'': # no expansion within single quotes | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 348 path = path[index + 1:] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 349 pathlen = len(path) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 350 try: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 351 index = path.index('\'') | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 352 res = res + '\'' + path[:index + 1] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 353 except ValueError: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 354 res = res + c + path | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 355 index = pathlen - 1 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 356 elif c == '%': # variable or '%' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 357 if path[index + 1:index + 2] == '%': | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 358 res = res + c | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 359 index = index + 1 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 360 else: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 361 path = path[index+1:] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 362 pathlen = len(path) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 363 try: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 364 index = path.index('%') | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 365 except ValueError: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 366 res = res + '%' + path | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 367 index = pathlen - 1 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 368 else: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 369 var = path[:index] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 370 try: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 371 res = res + getenv(var) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 372 except KeyError: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 373 res = res + '%' + var + '%' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 374 elif c == '$': # variable or '$$' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 375 if path[index + 1:index + 2] == '$': | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 376 res = res + c | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 377 index = index + 1 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 378 elif path[index + 1:index + 2] == '{': | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 379 path = path[index+2:] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 380 pathlen = len(path) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 381 try: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 382 index = path.index('}') | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 383 var = path[:index] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 384 try: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 385 res = res + getenv(var) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 386 except KeyError: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 387 res = res + '${' + var + '}' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 388 except ValueError: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 389 res = res + '${' + path | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 390 index = pathlen - 1 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 391 else: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 392 var = '' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 393 index = index + 1 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 394 c = path[index:index + 1] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 395 while c != '' and c in varchars: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 396 var = var + c | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 397 index = index + 1 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 398 c = path[index:index + 1] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 399 try: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 400 res = res + getenv(var) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 401 except KeyError: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 402 res = res + '$' + var | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 403 if c != '': | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 404 index = index - 1 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 405 else: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 406 res = res + c | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 407 index = index + 1 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 408 return res | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 409 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 410 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 411 # Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A\B. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 412 # Previously, this function also truncated pathnames to 8+3 format, | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 413 # but as this module is called "ntpath", that's obviously wrong! | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 414 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 415 def normpath(path): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 416 """Normalize path, eliminating double slashes, etc.""" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 417 # Preserve unicode (if path is unicode) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 418 backslash, dot = (u'\\', u'.') if isinstance(path, _unicode) else ('\\', '.') | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 419 if path.startswith(('\\\\.\\', '\\\\?\\')): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 420 # in the case of paths with these prefixes: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 421 # \\.\ -> device names | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 422 # \\?\ -> literal paths | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 423 # do not do any normalization, but return the path unchanged | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 424 return path | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 425 path = path.replace("/", "\\") | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 426 prefix, path = splitdrive(path) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 427 # We need to be careful here. If the prefix is empty, and the path starts | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 428 # with a backslash, it could either be an absolute path on the current | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 429 # drive (\dir1\dir2\file) or a UNC filename (\\server\mount\dir1\file). It | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 430 # is therefore imperative NOT to collapse multiple backslashes blindly in | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 431 # that case. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 432 # The code below preserves multiple backslashes when there is no drive | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 433 # letter. This means that the invalid filename \\\a\b is preserved | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 434 # unchanged, where a\\\b is normalised to a\b. It's not clear that there | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 435 # is any better behaviour for such edge cases. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 436 if prefix == '': | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 437 # No drive letter - preserve initial backslashes | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 438 while path[:1] == "\\": | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 439 prefix = prefix + backslash | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 440 path = path[1:] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 441 else: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 442 # We have a drive letter - collapse initial backslashes | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 443 if path.startswith("\\"): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 444 prefix = prefix + backslash | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 445 path = path.lstrip("\\") | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 446 comps = path.split("\\") | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 447 i = 0 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 448 while i < len(comps): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 449 if comps[i] in ('.', ''): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 450 del comps[i] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 451 elif comps[i] == '..': | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 452 if i > 0 and comps[i-1] != '..': | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 453 del comps[i-1:i+1] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 454 i -= 1 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 455 elif i == 0 and prefix.endswith("\\"): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 456 del comps[i] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 457 else: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 458 i += 1 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 459 else: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 460 i += 1 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 461 # If the path is now empty, substitute '.' | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 462 if not prefix and not comps: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 463 comps.append(dot) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 464 return prefix + backslash.join(comps) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 465 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 466 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 467 # Return an absolute path. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 468 try: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 469 from nt import _getfullpathname | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 470 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 471 except ImportError: # not running on Windows - mock up something sensible | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 472 def abspath(path): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 473 """Return the absolute version of a path.""" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 474 if not isabs(path): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 475 if isinstance(path, _unicode): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 476 cwd = os.getcwdu() | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 477 else: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 478 cwd = os.getcwd() | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 479 path = join(cwd, path) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 480 return normpath(path) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 481 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 482 else: # use native Windows method on Windows | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 483 def abspath(path): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 484 """Return the absolute version of a path.""" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 485 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 486 if path: # Empty path must return current working directory. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 487 try: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 488 path = _getfullpathname(path) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 489 except WindowsError: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 490 pass # Bad path - return unchanged. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 491 elif isinstance(path, _unicode): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 492 path = os.getcwdu() | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 493 else: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 494 path = os.getcwd() | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 495 return normpath(path) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 496 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 497 # realpath is a no-op on systems without islink support | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 498 realpath = abspath | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 499 # Win9x family and earlier have no Unicode filename support. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 500 supports_unicode_filenames = (hasattr(sys, "getwindowsversion") and | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 501 sys.getwindowsversion()[3] >= 2) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 502 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 503 def _abspath_split(path): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 504 abs = abspath(normpath(path)) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 505 prefix, rest = splitunc(abs) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 506 is_unc = bool(prefix) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 507 if not is_unc: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 508 prefix, rest = splitdrive(abs) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 509 return is_unc, prefix, [x for x in rest.split(sep) if x] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 510 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 511 def relpath(path, start=curdir): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 512 """Return a relative version of a path""" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 513 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 514 if not path: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 515 raise ValueError("no path specified") | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 516 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 517 start_is_unc, start_prefix, start_list = _abspath_split(start) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 518 path_is_unc, path_prefix, path_list = _abspath_split(path) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 519 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 520 if path_is_unc ^ start_is_unc: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 521 raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 522 % (path, start)) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 523 if path_prefix.lower() != start_prefix.lower(): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 524 if path_is_unc: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 525 raise ValueError("path is on UNC root %s, start on UNC root %s" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 526 % (path_prefix, start_prefix)) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 527 else: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 528 raise ValueError("path is on drive %s, start on drive %s" | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 529 % (path_prefix, start_prefix)) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 530 # Work out how much of the filepath is shared by start and path. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 531 i = 0 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 532 for e1, e2 in zip(start_list, path_list): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 533 if e1.lower() != e2.lower(): | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 534 break | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 535 i += 1 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 536 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 537 rel_list = [pardir] * (len(start_list)-i) + path_list[i:] | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 538 if not rel_list: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 539 return curdir | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 540 return join(*rel_list) | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 541 | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 542 try: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 543 # The genericpath.isdir implementation uses os.stat and checks the mode | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 544 # attribute to tell whether or not the path is a directory. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 545 # This is overkill on Windows - just pass the path to GetFileAttributes | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 546 # and check the attribute from there. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 547 from nt import _isdir as isdir | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 548 except ImportError: | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 549 # Use genericpath.isdir as imported above. | 
| 
7d1a9a91b989
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit d583ac16a6c6942730ea536eb59cc37941816030-dirty
 yating-l parents: diff
changeset | 550 pass | 
