1 | """ |
||
2 | Retrive basic library/application data/cache locations. |
||
3 | |||
4 | The basic FS layout for Orange data files is |
||
5 | |||
6 | $DATA_HOME/Orange/$VERSION/ |
||
7 | widgets/ |
||
8 | canvas/ |
||
9 | |||
10 | where DATA_HOME is a platform dependent application directory |
||
11 | (:ref:`data_dir_base`) and VERSION is Orange.__version__ string. |
||
12 | |||
13 | ``canvas`` subdirectory is reserved for settings/preferences stored |
||
14 | by Orange Canvas |
||
15 | ``widget`` subdirectory is reserved for settings/preferences stored |
||
16 | by OWWidget |
||
17 | |||
18 | """ |
||
19 | |||
20 | import os |
||
21 | import sys |
||
22 | |||
23 | import Orange |
||
24 | |||
25 | |||
26 | def data_dir_base(): |
||
27 | """ |
||
28 | Return the platform dependent application directory. |
||
29 | |||
30 | This is usually |
||
31 | |||
32 | - on windows: "%USERPROFILE%\\AppData\\Local\\" |
||
33 | - on OSX: "~/Library/Application Support/" |
||
34 | - other: "~/.local/share/ |
||
35 | """ |
||
36 | |||
37 | if sys.platform == "darwin": |
||
38 | base = os.path.expanduser("~/Library/Application Support") |
||
39 | elif sys.platform == "win32": |
||
40 | base = os.getenv("APPDATA", os.path.expanduser("~/AppData/Local")) |
||
41 | elif os.name == "posix": |
||
42 | base = os.getenv('XDG_DATA_HOME', os.path.expanduser("~/.local/share")) |
||
43 | else: |
||
44 | base = os.path.expanduser("~/.local/share") |
||
45 | return base |
||
46 | |||
47 | |||
48 | def data_dir(): |
||
49 | """ |
||
50 | Return the platform dependent Orange data directory. |
||
51 | |||
52 | This is ``data_dir_base()``/Orange/__VERSION__/ directory. |
||
53 | """ |
||
54 | base = data_dir_base() |
||
55 | return os.path.join(base, "Orange", Orange.__version__) |
||
56 | |||
57 | |||
58 | def widget_settings_dir(): |
||
59 | """ |
||
60 | Return the platform dependent directory where widgets save their settings. |
||
61 | |||
62 | This a subdirectory of ``data_dir()`` named "widgets" |
||
63 | """ |
||
64 | return os.path.join(data_dir(), "widgets") |
||
65 | |||
66 | |||
67 | def cache_dir(*args): |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
68 | """ |
||
69 | Return the platform dependent Orange cache directory. |
||
70 | """ |
||
71 | if sys.platform == "darwin": |
||
72 | base = os.path.expanduser("~/Library/Caches") |
||
73 | elif sys.platform == "win32": |
||
74 | base = os.getenv("APPDATA", os.path.expanduser("~/AppData/Local")) |
||
75 | elif os.name == "posix": |
||
76 | base = os.getenv("XDG_CACHE_HOME", os.path.expanduser("~/.cache")) |
||
77 | else: |
||
78 | base = os.path.expanduser("~/.cache") |
||
79 | |||
80 | base = os.path.join(base, "Orange", Orange.__version__) |
||
81 | if sys.platform == "win32": |
||
82 | # On Windows cache and data dir are the same. |
||
83 | # Microsoft suggest using a Cache subdirectory |
||
84 | return os.path.join(base, "Cache") |
||
85 | else: |
||
86 | return base |
||
87 |