-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathpathutils.py
45 lines (39 loc) · 1.43 KB
/
pathutils.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
42
43
44
45
# The beginning of a collection of file system related utilities which do not really
# belong in the main code file
import sys
from os import getenv
from pathlib import Path
def appdata_dir():
r"""
Get OS specific appdata directory path for cewe2pdf.
Typical user data directories are:
macOS: ~/Library/Application Support/cewe2pdf
Unix: ~/.local/share/cewe2pdf # or in $XDG_DATA_HOME, if defined
Win 10: C:\Users\<username>\AppData\Local\cewe2pdf
:return: full path to the user-specific data dir
"""
# get os specific path
if sys.platform.startswith("win"):
os_path = getenv("LOCALAPPDATA")
elif sys.platform.startswith("darwin"):
os_path = "~/Library/Application Support"
else:
# linux
os_path = getenv("XDG_DATA_HOME", "~/.local/share")
# join with cewe2pdf dir
path = Path(os_path) / "cewe2pdf"
return path.expanduser()
def localfont_dir():
# Get OS specific directory for locally installed fonts
if sys.platform.startswith("win"):
# microsoft windows
os_path = getenv("LOCALAPPDATA") + "/Microsoft/Windows/Fonts/"
elif sys.platform.startswith("darwin"):
# Mac and several others
os_path = "~/Library/Fonts"
else:
# assume linux
os_path = getenv("XDG_DATA_HOME", "~/.local/share") + "/fonts"
# join with cewe2pdf dir
path = Path(os_path)
return path.expanduser()