forked from biolab/orange3
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenviron.py
86 lines (65 loc) · 2.3 KB
/
environ.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""
Retrive basic library/application data/cache locations.
The basic FS layout for Orange data files is
$DATA_HOME/Orange/$VERSION/
widgets/
canvas/
where DATA_HOME is a platform dependent application directory
(:ref:`data_dir_base`) and VERSION is Orange.__version__ string.
``canvas`` subdirectory is reserved for settings/preferences stored
by Orange Canvas
``widget`` subdirectory is reserved for settings/preferences stored
by OWWidget
"""
import os
import sys
import Orange
def data_dir_base():
"""
Return the platform dependent application directory.
This is usually
- on windows: "%USERPROFILE%\\AppData\\Local\\"
- on OSX: "~/Library/Application Support/"
- other: "~/.local/share/
"""
if sys.platform == "darwin":
base = os.path.expanduser("~/Library/Application Support")
elif sys.platform == "win32":
base = os.getenv("APPDATA", os.path.expanduser("~/AppData/Local"))
elif os.name == "posix":
base = os.getenv('XDG_DATA_HOME', os.path.expanduser("~/.local/share"))
else:
base = os.path.expanduser("~/.local/share")
return base
def data_dir():
"""
Return the platform dependent Orange data directory.
This is ``data_dir_base()``/Orange/__VERSION__/ directory.
"""
base = data_dir_base()
return os.path.join(base, "Orange", Orange.__version__)
def widget_settings_dir():
"""
Return the platform dependent directory where widgets save their settings.
This a subdirectory of ``data_dir()`` named "widgets"
"""
return os.path.join(data_dir(), "widgets")
def cache_dir(*args):
"""
Return the platform dependent Orange cache directory.
"""
if sys.platform == "darwin":
base = os.path.expanduser("~/Library/Caches")
elif sys.platform == "win32":
base = os.getenv("APPDATA", os.path.expanduser("~/AppData/Local"))
elif os.name == "posix":
base = os.getenv("XDG_CACHE_HOME", os.path.expanduser("~/.cache"))
else:
base = os.path.expanduser("~/.cache")
base = os.path.join(base, "Orange", Orange.__version__)
if sys.platform == "win32":
# On Windows cache and data dir are the same.
# Microsoft suggest using a Cache subdirectory
return os.path.join(base, "Cache")
else:
return base