aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDeathamns <deathamns@gmail.com>2014-12-16 17:02:26 +0100
committerDeathamns <deathamns@gmail.com>2015-01-13 07:29:06 +0100
commit45137c2be9fb421f8cd4e37ee549b54a62475d3e (patch)
treeb13896159bdaf081c7888733059249684d396baa /tools
parentec69a50101a5d98a3b51117cabd8c0873687238a (diff)
downloaduBlock-45137c2be9fb421f8cd4e37ee549b54a62475d3e.zip
uBlock-45137c2be9fb421f8cd4e37ee549b54a62475d3e.tar.gz
uBlock-45137c2be9fb421f8cd4e37ee549b54a62475d3e.tar.bz2
Firefox: update manifest files when building
Diffstat (limited to 'tools')
-rw-r--r--tools/make-firefox-meta.py75
-rw-r--r--tools/make-firefox.sh2
-rw-r--r--tools/make-locale-firefox.py41
3 files changed, 76 insertions, 42 deletions
diff --git a/tools/make-firefox-meta.py b/tools/make-firefox-meta.py
new file mode 100644
index 0000000..c1fce91
--- /dev/null
+++ b/tools/make-firefox-meta.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python3
+
+import os
+import json
+import sys
+from shutil import rmtree
+from collections import OrderedDict
+
+if not sys.argv[1]:
+ raise SystemExit('Build dir missing.')
+
+
+def mkdirs(path):
+ try:
+ os.makedirs(path)
+ finally:
+ return os.path.exists(path)
+
+pj = os.path.join
+
+build_dir = os.path.abspath(sys.argv[1])
+source_locale_dir = pj(build_dir, '_locales')
+target_locale_dir = pj(build_dir, 'locale')
+language_codes = []
+description = ''
+
+for alpha2 in os.listdir(source_locale_dir):
+ locale_path = pj(source_locale_dir, alpha2, 'messages.json')
+ with open(locale_path, encoding='utf-8') as f:
+ string_data = json.load(f, object_pairs_hook=OrderedDict)
+
+ if alpha2 == 'en':
+ description = string_data['extShortDesc']['message']
+
+ alpha2 = alpha2.replace('_', '-')
+
+ language_codes.append(alpha2)
+
+ mkdirs(pj(target_locale_dir, alpha2))
+
+ locale_path = pj(target_locale_dir, alpha2, 'messages.properties')
+ with open(locale_path, 'wt', encoding='utf-8', newline='\n') as f:
+ for string_name in string_data:
+ f.write(string_name)
+ f.write('=')
+ f.write(string_data[string_name]['message'].replace('\n', r'\n'))
+ f.write('\n')
+
+# generate chrome.manifest file
+chrome_manifest = pj(build_dir, 'chrome.manifest')
+
+with open(chrome_manifest, 'at', encoding='utf-8', newline='\n') as f:
+ f.write('\n')
+
+ for alpha2 in language_codes:
+ f.write('locale ublock ' + alpha2 + ' ./locale/' + alpha2 + '/\n')
+
+rmtree(source_locale_dir)
+
+# update install.rdf
+proj_dir = pj(os.path.split(os.path.abspath(__file__))[0], '..')
+chromium_manifest = pj(proj_dir, 'platform', 'chromium', 'manifest.json')
+
+with open(chromium_manifest, encoding='utf-8') as m:
+ manifest = json.load(m)
+
+manifest['description'] = description
+
+install_rdf = pj(build_dir, 'install.rdf')
+
+with open(install_rdf, 'r+t', encoding='utf-8', newline='\n') as f:
+ install_rdf = f.read()
+ f.seek(0)
+
+ f.write(install_rdf.format(**manifest))
diff --git a/tools/make-firefox.sh b/tools/make-firefox.sh
index bdc5a48..35a4a99 100644
--- a/tools/make-firefox.sh
+++ b/tools/make-firefox.sh
@@ -24,6 +24,6 @@ cp platform/firefox/chrome.manifest $DES/
cp platform/firefox/install.rdf $DES/
echo "*** uBlock_xpi: Generating locales"
-python tools/make-locale-firefox.py $DES/
+python tools/make-firefox-meta.py $DES/
echo "*** uBlock_xpi: Package done."
diff --git a/tools/make-locale-firefox.py b/tools/make-locale-firefox.py
deleted file mode 100644
index 582e9a2..0000000
--- a/tools/make-locale-firefox.py
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/usr/bin/env python3
-
-import os
-import json
-import sys
-from shutil import rmtree
-from collections import OrderedDict
-
-if not sys.argv[1]:
- raise SystemExit('Build dir missing.')
-
-
-def mkdirs(path):
- try:
- os.makedirs(path)
- finally:
- return os.path.exists(path)
-
-
-build_dir = os.path.abspath(sys.argv[1])
-source_locale_dir = os.path.join(build_dir, '_locales')
-target_locale_dir = os.path.join(build_dir, 'locale')
-
-for alpha2 in os.listdir(source_locale_dir):
- locale_path = os.path.join(source_locale_dir, alpha2, 'messages.json')
- with open(locale_path, encoding='utf-8') as f:
- string_data = json.load(f, object_pairs_hook=OrderedDict)
-
- alpha2 = alpha2.replace('_', '-')
-
- mkdirs(os.path.join(target_locale_dir, alpha2))
-
- locale_path = os.path.join(target_locale_dir, alpha2, 'messages.properties')
- with open(locale_path, 'wt', encoding='utf-8', newline='\n') as f:
- for string_name in string_data:
- f.write(string_name)
- f.write('=')
- f.write(string_data[string_name]['message'].replace('\n', r'\n'))
- f.write('\n')
-
-rmtree(source_locale_dir)