Merge pull request #410 from Deathamns/ports/safari

Safari: auto-update *.plist files when building
This commit is contained in:
Raymond Hill 2014-12-11 13:22:43 -05:00
commit 9008a8bc8b
5 changed files with 85 additions and 50 deletions

View file

@ -3,19 +3,19 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>Author</key> <key>Author</key>
<string>Raymond Hill</string> <string>{author}</string>
<key>Builder Version</key> <key>Builder Version</key>
<string>534.57.2</string> <string>534.57.2</string>
<key>CFBundleDisplayName</key> <key>CFBundleDisplayName</key>
<string>µBlock</string> <string>{name}</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
<string>net.gorhill.uBlock</string> <string>net.gorhill.uBlock</string>
<key>CFBundleInfoDictionaryVersion</key> <key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string> <string>6.0</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>0.8.1.2</string> <string>{version}</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1</string> <string>{buildNumber}</string>
<key>Chrome</key> <key>Chrome</key>
<dict> <dict>
<key>Database Quota</key> <key>Database Quota</key>
@ -43,7 +43,7 @@
<key>Image</key> <key>Image</key>
<string>img/icon16.png</string> <string>img/icon16.png</string>
<key>Label</key> <key>Label</key>
<string>µBlock</string> <string>{name}</string>
<key>Popover</key> <key>Popover</key>
<string>popover</string> <string>popover</string>
</dict> </dict>
@ -70,7 +70,7 @@
</array> </array>
</dict> </dict>
<key>Description</key> <key>Description</key>
<string>Finally, an efficient blocker. Easy on CPU and memory.</string> <string>{description}</string>
<key>ExtensionInfoDictionaryVersion</key> <key>ExtensionInfoDictionaryVersion</key>
<string>1.0</string> <string>1.0</string>
<key>Permissions</key> <key>Permissions</key>
@ -84,7 +84,7 @@
</dict> </dict>
</dict> </dict>
<!-- <key>Update Manifest URL</key> <!-- <key>Update Manifest URL</key>
<string>https://github.com/gorhill/uBlockupdate_safariextz.plist</string> --> <string>https://github.com/gorhill/uBlock/Safari/Update.plist</string> -->
<key>Website</key> <key>Website</key>
<string>https://github.com/gorhill/uBlock</string> <string>https://github.com/gorhill/uBlock</string>
</dict> </dict>

View file

@ -8,11 +8,11 @@
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
<string>net.gorhill.uBlock</string> <string>net.gorhill.uBlock</string>
<key>Developer Identifier</key> <key>Developer Identifier</key>
<string></string> <string>...</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>0.8.1.2</string> <string>{version}</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1</string> <string>{buildNumber}</string>
<key>URL</key> <key>URL</key>
<string>https://.../uBlock.safariextz</string> <string>https://.../uBlock.safariextz</string>
</dict> </dict>

View file

@ -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)

74
tools/make-safari-meta.py Normal file
View file

@ -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))

View file

@ -20,6 +20,6 @@ cp platform/safari/Info.plist $DES/
cp platform/safari/Settings.plist $DES/ cp platform/safari/Settings.plist $DES/
echo "*** uBlock_xpi: Generating locales" echo "*** uBlock_xpi: Generating locales"
python tools/make-locale-safari.py $DES/ python tools/make-safari-meta.py $DES/
echo "*** uBlock.safariextension: Package done." echo "*** uBlock.safariextension: Package done."