-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_profile.py
122 lines (88 loc) · 2.32 KB
/
find_profile.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
#
# Find the Browser Profiles
#
import os
#base = os.path.dirname(os.path.realpath(__file__))
import sys
sys.dont_write_bytecode = True
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository.GdkPixbuf import Pixbuf
import glob
ICON = "applications-internet"
ICON_SIZE = 64
#class ProfileData:
profile_path_list = [
"/home/atom/Chrome",
"/home/atom/.mozilla/firefox"
]
def load_browser_profiles():
prof_list = []
# Default Chrome
prof = {}
prof['path'] = "/home/atom/.config/chromium"
prof['name'] = "Default"
prof['type'] = "chrome"
prof['icon'] = _find_browser_profile_icon(prof)
prof_list.append(prof)
# Default Firefox
# prof = {}
# prof['path'] = "/home/atom/.config/chromium"
# prof['name'] = "Default"
# prof['type'] = "chrome"
# prof['icon'] = _find_browser_profile_icon(prof)
# prof_list.append(prof)
for path in profile_path_list:
list0 = _find_browser_profiles(path)
for p in list0:
prof_list.append(p)
return prof_list
# end-def
#
# Find the Profiles
def _find_browser_profiles(path):
print("Find: " + path)
prof_list = []
dir_list = sorted(glob.glob(path + "/*"))
for d in dir_list:
if os.path.isdir(d):
prof = {}
prof['path'] = d
prof['name'] = os.path.basename(d)
prof['type'] = _find_browser_profile_type(prof)
prof['icon'] = _find_browser_profile_icon(prof)
prof_list.append(prof)
return prof_list
# end-def
#
def _find_browser_profile_icon(prof):
# print("Icon: " + prof['path'])
# Default Icon
icon = Gtk.IconTheme.get_default().load_icon(ICON, ICON_SIZE, 0)
if "chrome" == prof['type']:
icon = Gtk.IconTheme.get_default().load_icon("google-chrome", ICON_SIZE, 0)
# Firefox Icon
if "firefox" == prof['type']:
icon = Gtk.IconTheme.get_default().load_icon("firefox-bin", ICON_SIZE, 0)
# Specific Icon
file = prof['path'] + "/icon.png"
if os.path.isfile(file):
print("With Icon File: " + file)
icon = Pixbuf.new_from_file(file)
icon0 = icon.scale_simple(ICON_SIZE, ICON_SIZE, 2)
return icon0
# end-def
#
def _find_browser_profile_type(prof):
# Old Chrome
if os.path.isfile(prof['path'] + "/Profile 1/README"):
return "chrome"
# New Chrome
if os.path.isfile(prof['path'] + "/Default/README"):
return "chrome"
# Firefox
if os.path.isfile(prof['path'] + "/key3.db"):
return "firefox"
return "chrome"
# end-def