Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 # coding: utf-8 | |
2 | |
3 # This file is part of the Adblock Plus web scripts, | |
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 os, subprocess, codecs, urllib, re | |
Felix Dahlke
2013/06/25 10:10:02
Seems like the re module is not being used here.
| |
19 from sitescripts.utils import get_config, setupStderr | |
20 from tempfile import mkdtemp | |
21 from shutil import rmtree | |
22 | |
23 def updateExternalFiles(): | |
24 settings = readSettings() | |
25 for name, setting in settings.iteritems(): | |
Wladimir Palant
2013/06/25 11:21:03
Nit: for setting in settings.itervalues() - the ke
| |
26 tempdir = mkdtemp(prefix='external') | |
27 try: | |
28 repoPath = setting['targetrepository'] | |
29 targetPath = os.path.dirname(setting['targetfile']) | |
30 filename = os.path.basename(setting['targetfile']) | |
31 | |
32 subprocess.Popen(['hg', 'clone', '-q', '-U', repoPath, tempdir], stdout=su bprocess.PIPE).communicate() | |
33 subprocess.Popen(['hg', 'up', '-q', '-R', tempdir, '-r', 'default'], stdou t=subprocess.PIPE).communicate() | |
34 | |
35 path = os.path.join(tempdir, targetPath) | |
36 if not os.path.exists(path): | |
37 os.makedirs(path) | |
38 | |
39 path = os.path.join(path, filename) | |
40 exists = os.path.exists(path) | |
41 file = codecs.open(path, 'wb', encoding='utf-8') | |
42 data = urllib.urlopen(setting['source']).read() | |
Wladimir Palant
2013/06/25 11:21:03
You need to add .decode('utf-8') at the end - as i
| |
43 file.write(data) | |
44 file.close() | |
45 | |
46 message = 'Updated copy of external file %s' | |
47 if not exists: | |
48 message = 'Added copy of external file %s' | |
49 subprocess.Popen(['hg', 'commit', '-q', '-A', '-R', tempdir, '-u', 'hgbot' , '-m', message % filename], stdout=subprocess.PIPE).communicate() | |
50 subprocess.Popen(['hg', 'push', '-q', '-R', tempdir], stdout=subprocess.PI PE).communicate() | |
51 finally: | |
52 rmtree(tempdir) | |
53 | |
54 def readSettings(): | |
55 result = {} | |
56 for option, value in get_config().items('externalFiles'): | |
57 if option.find('_') < 0: | |
58 continue | |
59 name, setting = option.rsplit('_', 2) | |
60 if not setting in ('source', 'targetrepository', 'targetfile'): | |
61 continue | |
62 | |
63 if not name in result: | |
64 result[name] = { | |
65 'source': None, | |
66 'targetrepository': None, | |
67 'targetfile': None | |
68 } | |
69 result[name][setting] = value | |
70 return result | |
71 | |
72 if __name__ == '__main__': | |
73 setupStderr() | |
74 updateExternalFiles() | |
OLD | NEW |