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

Delta Between Two Patch Sets: sitescripts/extensions/pad/__init__.py

Issue 5723465818570752: Issue 520 - Generate PAD files for download portals when updating download links (Closed)
Left Patch Set: Created May 26, 2014, 10 a.m.
Right Patch Set: Addressed comments Created June 4, 2014, 4:35 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « sitescripts/extensions/bin/updateDownloadLinks.py ('k') | sitescripts/extensions/pad/language.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-2014 Eyeo GmbH 2 # Copyright (C) 2006-2014 Eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 import subprocess, os, re, time 16 import subprocess
Wladimir Palant 2014/05/26 10:54:57 One import per line?
17 import os
18 import re
19 import time
17 from datetime import datetime 20 from datetime import datetime
18 from urlparse import urljoin 21 from urlparse import urljoin
19 22
20 from sitescripts.utils import get_template 23 from sitescripts.utils import get_template
21 from sitescripts.extensions.android import get_min_android_version 24 from sitescripts.extensions.android import get_min_android_version
Wladimir Palant 2014/05/26 10:54:57 from ..android? Note that most code uses absolute
22 from sitescripts.extensions.pad.language import iso2pad 25 from sitescripts.extensions.pad.language import iso2pad
Sebastian Noack 2014/05/26 12:04:53 See above.
23 from sitescripts.extensions.pad.validation import validate_pad 26 from sitescripts.extensions.pad.validation import validate_pad
24 27
25 OS_WINDOWS = ['Win7 x32', 'Win7 x64', 'WinVista', 'WinVista x64', 'WinXP'] 28 OS_WINDOWS = ['Windows 8', 'Win7 x32', 'Win7 x64', 'WinVista', 'WinVista x64', ' WinXP']
26 OS_LINUX = ['Linux'] 29 OS_LINUX = ['Linux']
27 OS_MAC = ['Mac OS X'] 30 OS_MAC = ['Mac OS X']
28 OS_ANDROID = ['Android'] 31 OS_ANDROID = ['Android']
29 32
30 class PadFile: 33 class PadFile:
31 def __init__(self, repo, version, download_url): 34 def __init__(self, repo, version, download_url):
32 self.repo = repo 35 self.repo = repo
33 self.version = version 36 self.version = version
34 self.download_url = re.sub(r'(?<=^http)s(?=:)', '', download_url) 37 self.download_url = download_url
35 38
39 self.first_release = True
36 for i, (filename, version) in enumerate(repo.getDownloads()): 40 for i, (filename, version) in enumerate(repo.getDownloads()):
37 self.first_release = (i == 0) 41 if i > 0:
Wladimir Palant 2014/05/26 10:54:57 Isn't that supposed to be inside the if block belo
Sebastian Noack 2014/05/27 12:01:23 Done.
42 self.first_release = False
38 43
39 if version == self.version: 44 if version == self.version:
40 self.download_filename = filename 45 self.download_filename = filename
41 46
42 @property 47 @property
43 def release_status(self): 48 def release_status(self):
44 if self.first_release: 49 if self.first_release:
45 return 'New Release' 50 return 'New Release'
46 51
47 if self.version.rstrip('.0').count('.') < 2: 52 if self.version.rstrip('.0').count('.') < 2:
48 return 'Major Update' 53 return 'Major Update'
49 54
50 return 'Minor Update' 55 return 'Minor Update'
51 56
52 @property 57 @property
53 def release_date(self): 58 def release_date(self):
54 command = ['hg', 'log', '-l', '1', self.download_filename, '--template', '{d ate}'] 59 command = ['hg', 'log', '-l', '1', self.download_filename, '--template', '{d ate}']
55 result = subprocess.check_output(command, cwd=self.repo.downloadsRepo) 60 result = subprocess.check_output(command, cwd=self.repo.downloadsRepo)
56 timestamp, offset = re.match(r'(.*)([-+].*)', result).groups() 61 timestamp, offset = re.match(r'(.*)([-+].*)', result).groups()
57 return datetime(*time.gmtime(float(timestamp) + float(offset))[:6]) 62 return datetime(*time.gmtime(float(timestamp) + float(offset))[:6])
58 63
59 @property 64 @property
60 def download_size(self): 65 def download_size(self):
61 return os.stat(os.path.join(self.repo.downloadsRepo, self.download_filename) ).st_size 66 return len(subprocess.check_output(
67 ['hg', 'cat', '-r', 'tip', self.download_filename],
68 cwd=self.repo.downloadsRepo
69 ))
62 70
63 @property 71 @property
64 def browser_min_version(self): 72 def browser_min_version(self):
65 return self.repo.readMetadata(self.version).items('compat')[0][1].split('/') [0].rstrip('.0') 73 metadata = self.repo.readMetadata(self.version)
74 compat_option = getattr(self, 'compat_option', self.repo.type)
75 return metadata.get('compat', compat_option).split('/')[0].rstrip('.0')
66 76
67 @property 77 @property
68 def languages(self): 78 def languages(self):
69 files = self.repo.listContents(self.version) 79 files = self.repo.listContents(self.version)
70 languages = set() 80 languages = set()
71 skipped = set() 81 skipped = set()
72 82
73 for filename in files: 83 for filename in files:
74 match = re.match(self.translation_files_regex, filename) 84 match = re.match(self.translation_files_regex, filename)
75 85
(...skipping 13 matching lines...) Expand all
89 if groups.get('skip') is not None: 99 if groups.get('skip') is not None:
90 skipped.add(code) 100 skipped.add(code)
91 continue 101 continue
92 102
93 languages.add(code) 103 languages.add(code)
94 104
95 return iso2pad(languages.difference(skipped)) 105 return iso2pad(languages.difference(skipped))
96 106
97 def write(self): 107 def write(self):
98 template = get_template(self.repo.padTemplate) 108 template = get_template(self.repo.padTemplate)
99 filename = self.repo.basename + '.xml' 109 basename = self.repo.basename
110 filename = basename + '.xml'
100 111
101 pad = template.render({ 112 pad = template.render({
113 'name': self.repo.name,
102 'type': self.repo.type, 114 'type': self.repo.type,
115 'basename': basename,
103 'browser_name': self.browser_name, 116 'browser_name': self.browser_name,
104 'browser_min_version': self.browser_min_version, 117 'browser_min_version': self.browser_min_version,
105 'version': self.version, 118 'version': self.version,
106 'release_date': self.release_date, 119 'release_date': self.release_date,
107 'release_status': self.release_status, 120 'release_status': self.release_status,
108 'os_support': ','.join(self.os_support), 121 'os_support': ','.join(self.os_support),
109 'language': ','.join(self.languages), 122 'language': ','.join(self.languages),
110 'download_size': self.download_size, 123 'download_size': self.download_size,
111 'download_url': self.download_url, 124 'download_url': self.download_url,
112 'pad_url': urljoin(self.repo.padURL, filename), 125 'pad_url': urljoin(self.repo.padURL, filename),
(...skipping 19 matching lines...) Expand all
132 return InternetExplorerPadFile(repo, *args, **kwargs) 145 return InternetExplorerPadFile(repo, *args, **kwargs)
133 if repo.type == 'android': 146 if repo.type == 'android':
134 return AndroidPadFile(repo, *args, **kwargs) 147 return AndroidPadFile(repo, *args, **kwargs)
135 148
136 raise Exception('unknown repository type %r' % repo.type) 149 raise Exception('unknown repository type %r' % repo.type)
137 150
138 class FirefoxPadFile(PadFile): 151 class FirefoxPadFile(PadFile):
139 browser_name = 'Mozilla Firefox' 152 browser_name = 'Mozilla Firefox'
140 os_support = OS_WINDOWS + OS_MAC + OS_LINUX + OS_ANDROID 153 os_support = OS_WINDOWS + OS_MAC + OS_LINUX + OS_ANDROID
141 translation_files_regex = r'chrome\/locale\/(?P<code>.+?)\/(?P<skip>\.incomple te$)?' 154 translation_files_regex = r'chrome\/locale\/(?P<code>.+?)\/(?P<skip>\.incomple te$)?'
155 compat_option = 'firefox'
142 156
143 class ChromePadFile(PadFile): 157 class ChromePadFile(PadFile):
144 browser_name = 'Google Chrome' 158 browser_name = 'Google Chrome'
145 os_support = OS_WINDOWS + OS_MAC + OS_LINUX 159 os_support = OS_WINDOWS + OS_MAC + OS_LINUX
146 translation_files_regex = r'_locales\/(?P<code>.+?)\/' 160 translation_files_regex = r'_locales\/(?P<code>.+?)\/'
147 161
148 class OperaPadFile(PadFile): 162 class OperaPadFile(PadFile):
149 browser_name = 'Opera' 163 browser_name = 'Opera'
150 browser_min_version = '17' 164 browser_min_version = '17'
151 os_support = OS_WINDOWS + OS_MAC + OS_LINUX 165 os_support = OS_WINDOWS + OS_MAC + OS_LINUX
152 translation_files_regex = ChromePadFile.translation_files_regex 166 translation_files_regex = ChromePadFile.translation_files_regex
153 167
154 class SafariPadFile(PadFile): 168 class SafariPadFile(PadFile):
155 borwser_name = 'Safari' 169 browser_name = 'Safari'
156 browser_min_version = '6' 170 browser_min_version = '6'
157 os_support = OS_MAC 171 os_support = OS_MAC
158 translation_files_regex = ChromePadFile.translation_files_regex 172 translation_files_regex = ChromePadFile.translation_files_regex
159 173
160 class InternetExplorerPadFile(PadFile): 174 class InternetExplorerPadFile(PadFile):
161 browser_name = 'Internet Explorer' 175 browser_name = 'Internet Explorer'
162 browser_min_version = '8' 176 browser_min_version = '8'
163 os_support = OS_WINDOWS 177 os_support = OS_WINDOWS
164 translation_files_regex = r'locales\/(?P<code>.+)\.ini$' 178 translation_files_regex = r'locales\/(?P<code>.+)\.ini$'
165 179
166 class AndroidPadFile(PadFile): 180 class AndroidPadFile(PadFile):
167 browser_name = 'Android' 181 browser_name = 'Android'
168 os_support = OS_ANDROID 182 os_support = OS_ANDROID
169 translation_files_regex = r'res\/(?:raw|values)(?:-(?P<code>.+?)|(?P<is_en>))\ /' 183 translation_files_regex = r'res\/(?:raw|values)(?:-(?P<code>.+?)|(?P<is_en>))\ /'
170 184
171 @property 185 @property
172 def browser_min_version(self): 186 def browser_min_version(self):
173 return get_min_android_version(self.repo, self.version) 187 return get_min_android_version(self.repo, self.version)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld