-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchromeextensions.py
executable file
·46 lines (39 loc) · 2.4 KB
/
chromeextensions.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
#!/usr/bin/python
import os
import json
from Foundation import CFPreferencesCopyAppValue
#Get name of last logged in user so the extension attribute will report information for the user even if they aren't logged in"
lastloggedinuser = CFPreferencesCopyAppValue('lastUserName', 'com.apple.loginwindow')
userchromepath = '/Users/' + lastloggedinuser + '/Library/Application Support/Google/Chrome/'
#Initialize a dictionary to hold the variable names extension developers used if developers localized their extension
internationalized_extensions = {}
#Initialize a directory to hold the names of the installed extensions
installed_extensions = []
#walk the chrome application support folder
for (dirpath, dirnames, filenames) in os.walk(userchromepath):
#Test to see if file is a manifest.json file and then check its name if it is a placeholder name for a localization file (has __MSG)
#If it is a normal name, then add it to the final list. If its not, add it to the internationalized_extensions dictionary to match against a localized messages.json file
for file in filenames:
if ("Extensions" in dirpath and "manifest.json" in file):
manifest = json.load(open(os.path.join(dirpath, file)))
extension_name = manifest.get('name')
name = extension_name
if '__MSG_'not in extension_name:
installed_extensions.append(extension_name)
else:
extension_name = extension_name[6:-2]
if extension_name not in internationalized_extensions:
internationalized_extensions[extension_name] = extension_name
else:
if (("Extensions" and "locales/en" in dirpath) and "messages.json" in file):
manifest = json.load(open(os.path.join(dirpath, file)))
if manifest:
for key in internationalized_extensions.keys():
if manifest.get(key):
extension_name = manifest.get(key).get('message')
installed_extensions.append(extension_name)
else:
if manifest.get(key.lower()):
extension_name = manifest.get(key.lower()).get('message')
installed_extensions.append(extension_name)
print "<result>{}</result>".format(', '.join(sorted(list(set(installed_extensions)))))