LEFT | RIGHT |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 # This file is part of the Adblock Plus web scripts, | 3 # This file is part of the Adblock Plus web scripts, |
4 # Copyright (C) 2006-2014 Eyeo GmbH | 4 # Copyright (C) 2006-2014 Eyeo GmbH |
5 # | 5 # |
6 # Adblock Plus is free software: you can redistribute it and/or modify | 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 | 7 # it under the terms of the GNU General Public License version 3 as |
8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. |
9 # | 9 # |
10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 # GNU General Public License for more details. | 13 # GNU General Public License for more details. |
14 # | 14 # |
15 # You should have received a copy of the GNU General Public License | 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/>. | 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 |
18 """ | 18 """ |
19 Generate update manifests | 19 Generate update manifests |
20 ========================= | 20 ========================= |
21 | 21 |
22 This script generates update manifests for all extensions and apps | 22 This script generates update manifests for all extensions and apps |
23 """ | 23 """ |
24 | 24 |
| 25 import os |
25 import re | 26 import re |
26 import subprocess | 27 import subprocess |
27 from buildtools.packagerGecko import KNOWN_APPS | 28 from buildtools.packagerGecko import KNOWN_APPS |
28 from ConfigParser import SafeConfigParser | 29 from ConfigParser import SafeConfigParser |
29 from sitescripts.utils import get_config, get_template | 30 from sitescripts.utils import get_config, get_template |
30 from sitescripts.extensions.utils import (Configuration, getDownloadLinks, | 31 from sitescripts.extensions.utils import ( |
31 getSafariCertificateID) | 32 Configuration, getDownloadLinks, getSafariCertificateID, |
| 33 writeIEUpdateManifest) |
32 from sitescripts.extensions.android import get_min_sdk_version | 34 from sitescripts.extensions.android import get_min_sdk_version |
33 | 35 |
34 def readMetadata(repo, version): | 36 def readMetadata(repo, version): |
35 """ | 37 """ |
36 reads extension ID and compatibility information from metadata file in the | 38 reads extension ID and compatibility information from metadata file in the |
37 extension's repository | 39 extension's repository |
38 """ | 40 """ |
39 if repo.type == 'android': | 41 if repo.type == 'android': |
40 command = ['hg', '-R', repo.repository, 'id', '-r', version, '-n'] | 42 command = ['hg', '-R', repo.repository, 'id', '-r', version, '-n'] |
41 result = subprocess.check_output(command) | 43 result = subprocess.check_output(command) |
(...skipping 18 matching lines...) Expand all Loading... |
60 'version': version, | 62 'version': version, |
61 'compat': [] | 63 'compat': [] |
62 } | 64 } |
63 for key, value in KNOWN_APPS.iteritems(): | 65 for key, value in KNOWN_APPS.iteritems(): |
64 if metadata.has_option('compat', key): | 66 if metadata.has_option('compat', key): |
65 minVersion, maxVersion = metadata.get('compat', key).split('/') | 67 minVersion, maxVersion = metadata.get('compat', key).split('/') |
66 result['compat'].append({'id': value, 'minVersion': minVersion, 'maxVers
ion': maxVersion}) | 68 result['compat'].append({'id': value, 'minVersion': minVersion, 'maxVers
ion': maxVersion}) |
67 return result | 69 return result |
68 elif repo.type == 'ie': | 70 elif repo.type == 'ie': |
69 return { | 71 return { |
70 'name': repo.name, | 72 'version': version, |
71 'version': version | 73 'basename': os.path.basename(repo.repository) |
72 } | 74 } |
73 else: | 75 else: |
74 raise Exception('unknown repository type %r' % repo.type) | 76 raise Exception('unknown repository type %r' % repo.type) |
75 | 77 |
76 def writeUpdateManifest(links): | 78 def writeUpdateManifest(links): |
77 """ | 79 """ |
78 writes an update manifest for all extensions and Android apps | 80 writes an update manifest for all extensions and Android apps |
79 """ | 81 """ |
80 | 82 |
81 extensions = {'gecko': [], 'android': [], 'safari': [], 'ie': []} | 83 extensions = {'gecko': [], 'android': [], 'safari': [], 'ie': []} |
82 for repo in Configuration.getRepositoryConfigurations(): | 84 for repo in Configuration.getRepositoryConfigurations(): |
83 if repo.type not in extensions or not links.has_section(repo.repositoryName)
: | 85 if repo.type not in extensions or not links.has_section(repo.repositoryName)
: |
84 continue | 86 continue |
85 data = readMetadata(repo, links.get(repo.repositoryName, 'version')) | 87 data = readMetadata(repo, links.get(repo.repositoryName, 'version')) |
86 data['updateURL'] = links.get(repo.repositoryName, 'downloadURL') | 88 data['updateURL'] = links.get(repo.repositoryName, 'downloadURL') |
87 if data['updateURL'].startswith(repo.downloadsURL): | 89 if data['updateURL'].startswith(repo.downloadsURL): |
88 data['updateURL'] += "?update" | 90 data['updateURL'] += "?update" |
89 extensions[repo.type].append(data) | 91 extensions[repo.type].append(data) |
90 | 92 |
91 if len(extensions['android']) > 1: | 93 if len(extensions['android']) > 1: |
92 print >>sys.stderr, 'Warning: more than one Android app defined, update mani
fest only works for one' | 94 print >>sys.stderr, 'Warning: more than one Android app defined, update mani
fest only works for one' |
93 | 95 |
94 for repoType in extensions.iterkeys(): | 96 for repoType in extensions.iterkeys(): |
95 manifestPath = get_config().get('extensions', '%sUpdateManifestPath' % repoT
ype) | 97 manifestPath = get_config().get('extensions', '%sUpdateManifestPath' % repoT
ype) |
96 template = get_template(get_config().get('extensions', '%sUpdateManifest' %
repoType)) | 98 if repoType == 'ie': |
97 template.stream({'extensions': extensions[repoType]}).dump(manifestPath) | 99 writeIEUpdateManifest(manifestPath, extensions[repoType]) |
| 100 else: |
| 101 template = get_template(get_config().get('extensions', '%sUpdateManifest'
% repoType)) |
| 102 template.stream({'extensions': extensions[repoType]}).dump(manifestPath) |
98 | 103 |
99 def updateUpdateManifests(): | 104 def updateUpdateManifests(): |
100 """ | 105 """ |
101 updates all update manifests with the current versions | 106 updates all update manifests with the current versions |
102 """ | 107 """ |
103 | 108 |
104 parser = SafeConfigParser() | 109 parser = SafeConfigParser() |
105 getDownloadLinks(parser) | 110 getDownloadLinks(parser) |
106 writeUpdateManifest(parser) | 111 writeUpdateManifest(parser) |
107 | 112 |
108 if __name__ == "__main__": | 113 if __name__ == "__main__": |
109 updateUpdateManifests() | 114 updateUpdateManifests() |
LEFT | RIGHT |