mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 09:07:54 +01:00
Slight update for Python scripts
This commit is contained in:
parent
85ee514ebc
commit
90c874c2aa
2 changed files with 13 additions and 19 deletions
|
@ -3,10 +3,11 @@
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
from io import open
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
if not sys.argv[1]:
|
if len(sys.argv) == 1 or not sys.argv[1]:
|
||||||
raise SystemExit('Build dir missing.')
|
raise SystemExit('Build dir missing.')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,12 @@
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
import codecs
|
from io import open
|
||||||
from time import time
|
from time import time
|
||||||
from urllib import parse
|
|
||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
if not sys.argv[1]:
|
if len(sys.argv) == 1 or not sys.argv[1]:
|
||||||
raise SystemExit('Build dir missing.')
|
raise SystemExit('Build dir missing.')
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,9 +26,9 @@ description = ''
|
||||||
# locales
|
# locales
|
||||||
locale_dir = pj(build_dir, '_locales')
|
locale_dir = pj(build_dir, '_locales')
|
||||||
|
|
||||||
for alpha2 in os.listdir(locale_dir):
|
for alpha2 in sorted(os.listdir(locale_dir)):
|
||||||
locale_path = pj(locale_dir, alpha2, 'messages.json')
|
locale_path = pj(locale_dir, alpha2, 'messages.json')
|
||||||
with codecs.open(locale_path, 'r', encoding='utf8') as f:
|
with open(locale_path, encoding='utf-8') as f:
|
||||||
string_data = json.load(f, object_pairs_hook=OrderedDict)
|
string_data = json.load(f, object_pairs_hook=OrderedDict)
|
||||||
|
|
||||||
if alpha2 == 'en':
|
if alpha2 == 'en':
|
||||||
|
@ -45,29 +44,23 @@ for alpha2 in os.listdir(locale_dir):
|
||||||
|
|
||||||
mkdirs(pj(locale_dir))
|
mkdirs(pj(locale_dir))
|
||||||
|
|
||||||
with codecs.open(locale_path, 'w', encoding='utf8') as f:
|
with open(locale_path, 'wb') as f:
|
||||||
json.dump(string_data, f, ensure_ascii=False)
|
f.write(json.dumps(string_data, ensure_ascii=False).encode('utf8'))
|
||||||
|
|
||||||
|
|
||||||
# update Info.plist
|
# update Info.plist
|
||||||
proj_dir = pj(os.path.split(os.path.abspath(__file__))[0], '..')
|
proj_dir = pj(os.path.split(os.path.abspath(__file__))[0], '..')
|
||||||
chromium_manifest = pj(proj_dir, 'platform', 'chromium', 'manifest.json')
|
chromium_manifest = pj(proj_dir, 'platform', 'chromium', 'manifest.json')
|
||||||
|
|
||||||
with codecs.open(chromium_manifest, encoding='utf8') as m:
|
with open(chromium_manifest, encoding='utf-8') as m:
|
||||||
manifest = json.load(m)
|
manifest = json.load(m)
|
||||||
|
|
||||||
manifest['buildNumber'] = int(time())
|
manifest['buildNumber'] = int(time())
|
||||||
manifest['description'] = description
|
manifest['description'] = description
|
||||||
|
|
||||||
# pass "#name,version" as the fragment in the URL of the background script
|
|
||||||
manifest['appInfo'] = ','.join([
|
|
||||||
parse.quote(manifest['name']),
|
|
||||||
manifest['version']
|
|
||||||
])
|
|
||||||
|
|
||||||
info_plist = pj(build_dir, 'Info.plist')
|
info_plist = pj(build_dir, 'Info.plist')
|
||||||
|
|
||||||
with codecs.open(pj(build_dir, 'Info.plist'), 'r+', encoding='utf8') as f:
|
with open(info_plist, 'r+t', encoding='utf-8', newline='\n') as f:
|
||||||
info_plist = f.read()
|
info_plist = f.read()
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
|
|
||||||
|
@ -77,8 +70,8 @@ with codecs.open(pj(build_dir, 'Info.plist'), 'r+', encoding='utf8') as f:
|
||||||
update_plist = pj(proj_dir, 'platform', 'safari', 'Update.plist')
|
update_plist = pj(proj_dir, 'platform', 'safari', 'Update.plist')
|
||||||
update_plist_build = pj(build_dir, '..', os.path.basename(update_plist))
|
update_plist_build = pj(build_dir, '..', os.path.basename(update_plist))
|
||||||
|
|
||||||
with codecs.open(update_plist_build, 'w', encoding='utf8') as f:
|
with open(update_plist_build, 'wt', encoding='utf-8', newline='\n') as f:
|
||||||
with codecs.open(update_plist, encoding='utf8') as u:
|
with open(update_plist, encoding='utf-8') as u:
|
||||||
update_plist = u.read()
|
update_plist = u.read()
|
||||||
|
|
||||||
f.write(update_plist.format(**manifest))
|
f.write(update_plist.format(**manifest))
|
||||||
|
|
Loading…
Reference in a new issue