Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: packagerSafari.py

Issue 11544056: Prepared buildtools for Safari (Closed)
Patch Set: Created Sept. 4, 2013, 8:03 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « packagerChrome.py ('k') | safariInfo.js.tmpl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # coding: utf-8
2
3 # This file is part of the Adblock Plus build tools,
4 # Copyright (C) 2006-2013 Eyeo GmbH
5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation.
9 #
10 # Adblock Plus is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17
18 import re, json
19 from urlparse import urlparse
20 from collections import OrderedDict
21
22 from packager import readMetadata, getDefaultFileName, getBuildVersion, getTempl ate, Files
23 from buildtools.packagerChrome import convertJS, importGeckoLocales, getIgnoredF iles, getPackageFiles, ImageConverter
24
25 def createPlist(params, files):
26 template = getTemplate('Info.plist.tmpl')
27 metadata = params['metadata']
28 catalog = json.loads(files['_locales/en_US/messages.json'])
29
30 def toxml(val, indent=0):
31 if isinstance(val, bool):
32 return '<true/>' if val else '<false/>'
33 if isinstance(val, (int, long)):
34 return '<real>%d</real>' % val
35 if isinstance(val, basestring):
36 return '<string>%s</string>' % val
37
38 def parse_section(section, levels=1):
39 rv = OrderedDict()
40
41 if not metadata.has_section(section):
42 return rv
43
44 for opt in metadata.options(section):
45 bits = opt.split('_', levels)
46 key = bits.pop(-1).replace('_', ' ').title()
47 d = rv
48
49 for x in bits:
50 try:
51 d = d[x]
52 except KeyError:
53 d[x] = d = OrderedDict()
54
55 d[key] = metadata.get(section, opt)
56
57 return rv
58
59 allowedDomains = set()
60 allowAllDomains = False
61 allowSecurePages = False
62
63 for perm in re.split(r'\s+', metadata.get('general', 'permissions')):
64 if perm == '<all_urls>':
65 allowAllDomains = True
66 allowSecurePages = True
67 continue
68
69 url = urlparse(perm)
70
71 if url.scheme == 'https':
72 allowSecurePages = True
73 elif url.scheme != 'http':
74 continue
75
76 if '*' in url.hostname:
77 allowAllDomains = True
78 continue
79
80 allowedDomains.add(url.hostname)
81
82 menus = parse_section('menus', 2)
83 toolbarItems = parse_section('toolbar_items')
84
85 return template.render(
86 author=metadata.get('general', 'author'),
87 version=params['version'],
88 name=catalog['name']['message'],
89 description=catalog['description']['message'],
90 website=metadata.get('general', 'website'),
91 identifier=metadata.get('general', 'identifier'),
92 allowedDomains=allowedDomains,
93 allowAllDomains=allowAllDomains,
94 allowSecurePages=allowSecurePages,
95 contentScripts={
96 'start': metadata.get('contentScripts', 'document_start').split(),
97 'end': metadata.get('contentScripts', 'document_end' ).split(),
98 },
99 menus=parse_section('menus', 2),
100 toolbarItems=parse_section('toolbar_items'),
101 popovers=parse_section('popovers'),
102 toxml=toxml
103 ).encode('utf-8')
104
105 def createBackgroundPage(params):
106 template = getTemplate('background.html.tmpl')
107 return template.render(
108 backgroundScripts=re.split(r'\s+', params['metadata'].get(
109 'general', 'backgroundScripts'
110 ))
111 ).encode('utf-8')
112
113 def createInfoModule(params):
114 template = getTemplate('safariInfo.js.tmpl')
115 return template.render(params).encode('utf-8');
116
117 def createBuild(baseDir, type, outFile=None, buildNum=None, releaseBuild=False):
118 metadata = readMetadata(baseDir, type)
119 version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum)
120
121 if outFile == None:
122 outFile = getDefaultFileName(baseDir, metadata, version, 'zip')
123
124 params = {
125 'type': type,
126 'baseDir': baseDir,
127 'releaseBuild': releaseBuild,
128 'version': version,
129 'devenv': False,
130 'metadata': metadata,
131 }
132
133 files = Files(getPackageFiles(params), getIgnoredFiles(params),
134 process=lambda path, data: data)
135 if metadata.has_section('mapping'):
136 files.readMappedFiles(metadata.items('mapping'))
137 files.read(baseDir)
138
139 if metadata.has_section('convert_js'):
140 convertJS(params, files)
141
142 if metadata.has_section('convert_img'):
143 ImageConverter().convert(params, files)
144
145 if metadata.has_section('import_locales'):
146 importGeckoLocales(params, files)
147
148 files['lib/info.js'] = createInfoModule(params)
149 files['background.html'] = createBackgroundPage(params)
150 files['Info.plist'] = createPlist(params, files)
151
152 with open(outFile, 'wb') as f:
153 f.write(files.zipToString())
OLDNEW
« no previous file with comments | « packagerChrome.py ('k') | safariInfo.js.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld