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

Side by Side Diff: sitescripts/subscriptions/bin/updateSubscriptionDownloads.py

Issue 29345242: Noissue - Adapt quotes for compliance with our coding style in sitescripts (Closed)
Patch Set: Fixed raw string Created May 30, 2016, 8:47 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
OLDNEW
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-2016 Eyeo GmbH 2 # Copyright (C) 2006-2016 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 os 16 import os
17 import re 17 import re
18 import subprocess 18 import subprocess
19 import tempfile 19 import tempfile
20 import shutil 20 import shutil
21 import zipfile 21 import zipfile
22 from StringIO import StringIO 22 from StringIO import StringIO
23 from ...utils import get_config, setupStderr 23 from ...utils import get_config, setupStderr
24 from ..combineSubscriptions import combine_subscriptions 24 from ..combineSubscriptions import combine_subscriptions
25 25
26 26
27 class MercurialSource: 27 class MercurialSource:
28 _prefix = "./" 28 _prefix = './'
29 29
30 def __init__(self, repo): 30 def __init__(self, repo):
31 command = ["hg", "-R", repo, "archive", "-r", "default", 31 command = ['hg', '-R', repo, 'archive', '-r', 'default',
32 "-t", "uzip", "-p", ".", "-"] 32 '-t', 'uzip', '-p', '.', '-']
33 data = subprocess.check_output(command) 33 data = subprocess.check_output(command)
34 self._archive = zipfile.ZipFile(StringIO(data), mode="r") 34 self._archive = zipfile.ZipFile(StringIO(data), mode='r')
35 35
36 def close(self): 36 def close(self):
37 self._archive.close() 37 self._archive.close()
38 38
39 def read_file(self, filename): 39 def read_file(self, filename):
40 return self._archive.read(self._prefix + filename).decode("utf-8") 40 return self._archive.read(self._prefix + filename).decode('utf-8')
41 41
42 def list_top_level_files(self): 42 def list_top_level_files(self):
43 for filename in self._archive.namelist(): 43 for filename in self._archive.namelist():
44 filename = filename[len(self._prefix):] 44 filename = filename[len(self._prefix):]
45 if "/" not in filename: 45 if '/' not in filename:
46 yield filename 46 yield filename
47 47
48 if __name__ == "__main__": 48 if __name__ == '__main__':
49 setupStderr() 49 setupStderr()
50 50
51 source_repos = {} 51 source_repos = {}
52 for option, value in get_config().items("subscriptionDownloads"): 52 for option, value in get_config().items('subscriptionDownloads'):
53 if option.endswith("_repository"): 53 if option.endswith('_repository'):
54 source_repos[re.sub(r"_repository$", "", option)] = MercurialSource( value) 54 source_repos[re.sub(r'_repository$', '', option)] = MercurialSource( value)
55 55
56 basedir = get_config().get("subscriptionDownloads", "outdir") 56 basedir = get_config().get('subscriptionDownloads', 'outdir')
57 destination = os.path.join(basedir, "data") 57 destination = os.path.join(basedir, 'data')
58 try: 58 try:
59 combine_subscriptions(source_repos, destination, tempdir=basedir) 59 combine_subscriptions(source_repos, destination, tempdir=basedir)
60 finally: 60 finally:
61 for source in source_repos.itervalues(): 61 for source in source_repos.itervalues():
62 source.close() 62 source.close()
OLDNEW

Powered by Google App Engine
This is Rietveld