Browse Source

The way that no parents was computing the paths wasn't right

/foo/foobar is a child of /foo/foo, even though its not
master
Raphael Roberts 7 years ago
parent
commit
0df175b69c
  1. 21
      ext_open/util.py

21
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:

Loading…
Cancel
Save