From 857acaf2d2cc02b446f64d8958f31421e9d01c3b Mon Sep 17 00:00:00 2001 From: Deathamns Date: Thu, 11 Dec 2014 16:47:51 +0100 Subject: [PATCH] Safari: auto-update *.plist files when building --- platform/safari/Info.plist | 14 ++-- .../{update_safariextz.plist => Update.plist} | 6 +- tools/make-locale-safari.py | 39 ---------- tools/make-safari-meta.py | 74 +++++++++++++++++++ tools/make-safari.sh | 2 +- 5 files changed, 85 insertions(+), 50 deletions(-) rename platform/safari/{update_safariextz.plist => Update.plist} (85%) delete mode 100644 tools/make-locale-safari.py create mode 100644 tools/make-safari-meta.py diff --git a/platform/safari/Info.plist b/platform/safari/Info.plist index c5291ca14..048bf6173 100644 --- a/platform/safari/Info.plist +++ b/platform/safari/Info.plist @@ -3,19 +3,19 @@ Author - Raymond Hill + {author} Builder Version 534.57.2 CFBundleDisplayName - µBlock + {name} CFBundleIdentifier net.gorhill.uBlock CFBundleInfoDictionaryVersion 6.0 CFBundleShortVersionString - 0.8.1.2 + {version} CFBundleVersion - 1 + {buildNumber} Chrome Database Quota @@ -43,7 +43,7 @@ Image img/icon16.png Label - µBlock + {name} Popover popover @@ -70,7 +70,7 @@ Description - Finally, an efficient blocker. Easy on CPU and memory. + {description} ExtensionInfoDictionaryVersion 1.0 Permissions @@ -84,7 +84,7 @@ + https://github.com/gorhill/uBlock/Safari/Update.plist --> Website https://github.com/gorhill/uBlock diff --git a/platform/safari/update_safariextz.plist b/platform/safari/Update.plist similarity index 85% rename from platform/safari/update_safariextz.plist rename to platform/safari/Update.plist index c171e8689..969fe646e 100644 --- a/platform/safari/update_safariextz.plist +++ b/platform/safari/Update.plist @@ -8,11 +8,11 @@ CFBundleIdentifier net.gorhill.uBlock Developer Identifier - + ... CFBundleShortVersionString - 0.8.1.2 + {version} CFBundleVersion - 1 + {buildNumber} URL https://.../uBlock.safariextz diff --git a/tools/make-locale-safari.py b/tools/make-locale-safari.py deleted file mode 100644 index 62c819850..000000000 --- a/tools/make-locale-safari.py +++ /dev/null @@ -1,39 +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]) -locale_dir = os.path.join(build_dir, '_locales') - -for alpha2 in os.listdir(locale_dir): - locale_path = os.path.join(locale_dir, alpha2, 'messages.json') - with open(locale_path, encoding='utf-8') as f: - string_data = json.load(f, object_pairs_hook=OrderedDict) - - for string_name in string_data: - string_data[string_name] = string_data[string_name]['message'] - - rmtree(os.path.join(locale_dir, alpha2)) - - alpha2 = alpha2.replace('_', '-') - locale_path = os.path.join(locale_dir, alpha2 + '.json') - - mkdirs(os.path.join(locale_dir)) - - with open(locale_path, 'wt', encoding='utf-8', newline='\n') as f: - json.dump(string_data, f, ensure_ascii=False) diff --git a/tools/make-safari-meta.py b/tools/make-safari-meta.py new file mode 100644 index 000000000..eb0b701e8 --- /dev/null +++ b/tools/make-safari-meta.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 + +import os +import json +import sys +from time import time +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]) + +description = '' + +# locales +locale_dir = pj(build_dir, '_locales') + +for alpha2 in os.listdir(locale_dir): + locale_path = pj(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'] + + for string_name in string_data: + string_data[string_name] = string_data[string_name]['message'] + + rmtree(pj(locale_dir, alpha2)) + + alpha2 = alpha2.replace('_', '-') + locale_path = pj(locale_dir, alpha2 + '.json') + + mkdirs(pj(locale_dir)) + + with open(locale_path, 'wt', encoding='utf-8', newline='\n') as f: + json.dump(string_data, f, ensure_ascii=False) + + +# update Info.plist +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['buildNumber'] = int(time()) +manifest['description'] = description + +with open(pj(build_dir, 'Info.plist'), 'r+t', encoding='utf-8', newline='\n') as f: + info_plist = f.read() + f.seek(0) + + f.write(info_plist.format(**manifest)) + +# update Update.plist +update_plist = pj(proj_dir, 'platform', 'safari', 'Update.plist') +update_plist_build = pj(build_dir, '..', os.path.basename(update_plist)) + +with open(update_plist_build, 'wt', encoding='utf-8', newline='\n') as f: + with open(update_plist, encoding='utf-8') as u: + update_plist = u.read() + + f.write(update_plist.format(**manifest)) diff --git a/tools/make-safari.sh b/tools/make-safari.sh index 1b9840af8..bb8d5cd2b 100644 --- a/tools/make-safari.sh +++ b/tools/make-safari.sh @@ -20,6 +20,6 @@ cp platform/safari/Info.plist $DES/ cp platform/safari/Settings.plist $DES/ echo "*** uBlock_xpi: Generating locales" -python tools/make-locale-safari.py $DES/ +python tools/make-safari-meta.py $DES/ echo "*** uBlock.safariextension: Package done."