forked from rosshemsley/iOpener
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaths.py
41 lines (28 loc) · 957 Bytes
/
paths.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from os.path import isdir, isfile, expanduser, split, relpath, join, commonprefix, normpath
from os import listdir, sep, makedirs
HOME_DIRECTORY = '~'
def directory_listing_with_slahes(path):
"""
Return directory listing with directories having trailing slashes.
"""
output = []
for filename in listdir(path):
if isdir(join(path,filename)):
output.append(filename + sep)
else:
output.append(filename)
return output
def get_path_to_home():
return HOME_DIRECTORY + sep
def get_path_relative_to_home(path):
home = expanduser(HOME_DIRECTORY)
if len(commonprefix([home, path])) > 1:
relative_path = relpath(path, home)
if len(relative_path) > 1:
return join(HOME_DIRECTORY, relpath(path, home)) + sep
else:
return HOME_DIRECTORY + sep
elif path.endswith(sep):
return path
else:
return path + sep