diff --git a/ext_open/util.py b/ext_open/util.py index a3ab663..8ce862a 100644 --- a/ext_open/util.py +++ b/ext_open/util.py @@ -1,10 +1,13 @@ +from config import config from ctypes import windll -import datetime +from itertools import starmap from pydoc import pager +import datetime import os import re -from config import config windows_path = re.compile(r"[a-zA-Z]\:(\\[^/\\?\%\*\:\|\"\<\>]+)+") +windows_part = re.compile(r'(^[a-z]:\\|[a-zA-Z]\:\\|[^/\\\?\%\*\:|\"\<\>]+)') +# unix_part = re.compile(r'(^/|[^\x00/]+)') # https://stackoverflow.com/a/827397 def is_admin(): return windll.shell32.IsUserAnAdmin() != 0 @@ -19,8 +22,9 @@ def get_drives(): bitmask >>= 1 return drives + def no_parents(paths): - paths = sorted(paths,key=len) + paths = sorted(map(path_split,paths),key=len) ret = [] paths while len(paths) > 0: @@ -30,9 +34,16 @@ def no_parents(paths): paths = [] for path in old_paths: - if not path.startswith(el1): + if not startswith(path,el1): paths.append(path) - return ret + return list(starmap(os.path.join,ret)) + +def startswith(a,b): + l = len(b) + return a[:l] == b + +def path_split(path): + return windows_part.findall(path) def abbreviate(path,n=72,min_path = 2): if len(path) > n: