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

Side by Side Diff: sitescripts/management/bin/updateExternalFiles.py

Issue 4742530226716672: Noissue - Removed unussed script updateExternalFiles.py (Closed)
Patch Set: Removed externalFiles section from example config Created April 9, 2015, 6:34 p.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 | « .sitescripts.example ('k') | no next file » | 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 web scripts,
4 # Copyright (C) 2006-2015 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
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 setting in settings.itervalues():
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.check_call(['hg', 'clone', '-q', '-U', repoPath, tempdir])
33 subprocess.check_call(['hg', 'up', '-q', '-R', tempdir, '-r', 'default'])
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().decode('utf-8')
43 file.write(data)
44 file.close()
45
46 if subprocess.check_output(['hg', 'stat', '-R', tempdir]) != '':
47 message = 'Updated copy of external file %s'
48 if not exists:
49 message = 'Added copy of external file %s'
50 subprocess.check_call(['hg', 'commit', '-q', '-A', '-R', tempdir, '-u', 'hgbot', '-m', message % filename])
51 subprocess.call(['hg', 'push', '-q', '-R', tempdir])
52 finally:
53 rmtree(tempdir)
54
55 def readSettings():
56 result = {}
57 for option, value in get_config().items('externalFiles'):
58 if option.find('_') < 0:
59 continue
60 name, setting = option.rsplit('_', 2)
61 if not setting in ('source', 'targetrepository', 'targetfile'):
62 continue
63
64 if not name in result:
65 result[name] = {
66 'source': None,
67 'targetrepository': None,
68 'targetfile': None
69 }
70 result[name][setting] = value
71 return result
72
73 if __name__ == '__main__':
74 setupStderr()
75 updateExternalFiles()
OLDNEW
« no previous file with comments | « .sitescripts.example ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld