forked from dgsasha/qualia-gtk-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paths.py
executable file
·144 lines (125 loc) · 5.41 KB
/
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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
'''This module is for getting paths to parts of the theme.'''
from os import path, environ
from glob import glob
SUDO_USER = environ.get('SUDO_USER')
USER = SUDO_USER if SUDO_USER is not None else environ.get('USER')
HOME = path.expanduser(f'~{USER}')
REPO_DIR = path.dirname(path.realpath(__file__))
GTK4_DIR = f'{HOME}/.config/gtk-4.0'
SRC = f'{REPO_DIR}/src'
CONFIG = f'{REPO_DIR}/config.txt'
OLD_CONFIG = f'{SRC}/installed-versions.txt'
SRC = {
'gtk3': f'{SRC}/dg-adw-gtk3',
'gtk4': f'{SRC}/dg-libadwaita',
'yaru': f'{SRC}/dg-yaru',
'firefox': f'{SRC}/dg-firefox-theme',
'vscode': f'{SRC}/dg-vscode-adwaita',
}
FIREFOX_DIR = {
'standard': f'{HOME}/.mozilla/firefox',
'flatpak': f'{HOME}/.var/app/org.mozilla.firefox/.mozilla/firefox',
'snap': f'{HOME}/snap/firefox/common/.mozilla/firefox',
}
OLD_NAMES = {
'dg-yaru': ['dg-yaru'],
'dg-adw-gtk3': ['dg-adw-gtk3'],
'dg-firefox-theme': ['dg-firefox-theme'],
}
CURRENT_NAMES = {
'dg-yaru': ['qualia'],
'dg-adw-gtk3': ['qualia'],
'dg-firefox-theme': ['qualia'],
}
VSCODE_DIR = {
'standard': f'{HOME}/.vscode/extensions',
'flatpak': f'{HOME}/.var/app/com.visualstudio.code/data/vscode/extensions',
}
def installed(old_only = False, new_only = False, just_theme_dirs = False, directory = None):
'''
Return paths of installed themes.
Parameters:
old_only (bool) : True if we only care about dg-gnome-theme.
new_only (bool) : True if we only care about the current theme.
just_theme_dirs (bool) : Just return the path to the theme dirs, not all of the paths.
directory (string) : Either 'root', 'home', or 'not_default'. Used for uninstalling from specific directories. Defaults to None.
Returns:
paths (dict) : Returns a dictionary with all of the paths if just_theme_dirs is false.
paths['theme_dirs'] (list) : Returns a list with the paths to the theme dirs if just_theme_dirs is true.
'''
if directory == 'root':
dg_yaru_prefixes = ('/usr/share',)
dg_adw_gtk3_prefixes = dg_yaru_prefixes
elif directory == 'home':
dg_yaru_prefixes = (f'{HOME}/.local/share',)
dg_adw_gtk3_prefixes = dg_yaru_prefixes
elif directory == 'not_default':
dg_yaru_prefixes = (f'{HOME}/.local/share',)
dg_adw_gtk3_prefixes = ('/usr/share',)
else:
dg_yaru_prefixes = ('/usr/share', f'{HOME}/.local/share')
dg_adw_gtk3_prefixes = dg_yaru_prefixes
names = {}
for i in ('dg-yaru', 'dg-adw-gtk3', 'dg-firefox-theme'):
if old_only:
names[i] = (i,)
elif new_only:
names[i] = ('qualia',)
else:
names[i] = ('qualia', i)
paths = { # These have to be lists even if they only have one value
'gtk3': [],
'gtk4': [],
'gtk4-libadwaita': [],
'gnome-shell': [],
'cinnamon-shell': [],
'metacity': [],
'ubuntu-unity': [],
'xfwm4': [],
'firefox': [],
'icons': [],
'cursors': [],
'sounds': [],
'gtksourceview': [],
'vscode': [],
'theme_dirs': []
}
for name in names['dg-yaru']:
for prefix in dg_yaru_prefixes:
for subdir in ('themes', 'icons', 'sounds', 'gnome-shell/theme'):
paths['theme_dirs'] += glob(f'{prefix}/{subdir}/{name}*')
if just_theme_dirs:
continue
paths['gnome-shell'] += glob(f'{prefix}/themes/{name}*/gnome-shell') + glob(f'{prefix}/gnome-shell/theme/{name}*')
paths['metacity'] += glob(f'{prefix}/themes/{name}*/metacity')
paths['cinnamon-shell'] += glob(f'{prefix}/themes/{name}*/cinnamon')
paths['ubuntu-unity'] += glob(f'{prefix}/themes/{name}*/unity')
paths['xfwm4'] += glob(f'{prefix}/themes/{name}*/xfwm4')
paths['icons'] += glob(f'{prefix}/icons/{name}*/*')
paths['cursors'] += [f'{prefix}/icons/{name}/cursor.theme', f'{prefix}/icons/{name}/cursors']
paths['sounds'] += [f'{prefix}/sounds/{name}']
for i in ('gtksourceview-5', 'gtksourceview-4', 'gtksourceview-3.0', 'gtksourceview-2.0'):
paths['gtksourceview'] += glob(f'{prefix}/{i}/styles/{name}*')
for name in names['dg-adw-gtk3']:
for prefix in dg_adw_gtk3_prefixes:
paths['theme_dirs'] += glob(f'{prefix}/themes/{name}*')
if just_theme_dirs:
continue
paths['gtk3'] += glob(f'{prefix}/themes/{name}*/gtk-3.0') + glob(f'{prefix}/themes/{name}*/gtk-2.0')
if not just_theme_dirs:
if directory is None:
for firefox_path in FIREFOX_DIR.values():
for name in names['dg-firefox-theme']:
paths['firefox'] += glob(f'{firefox_path}/*/chrome/{name}')
if not old_only:
paths['firefox'] += glob(f'{firefox_path}/*/user.js') + glob(f'{firefox_path}/*/chrome/userChrome.css') + glob(f'{firefox_path}/*/userContent.css')
if not old_only:
if directory is None:
paths['gtk4'] += [f'{GTK4_DIR}/mac-icons']
paths['gtk4'] += [f'{GTK4_DIR}/gtk.css']
for extensions_path in VSCODE_DIR.values():
paths['vscode'] += [f'{extensions_path}/qualia']
for prefix in dg_adw_gtk3_prefixes:
paths['gtk4-libadwaita'] += glob(f'{prefix}/themes/qualia*/gtk-4.0')
return paths
return paths['theme_dirs']