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

Side by Side Diff: cms/bin/generate_static_pages.py

Issue 5076874740891648: Issue 2456 - [cms] Use logging module (Closed)
Patch Set: Created May 5, 2015, 1:30 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 | « no previous file | cms/bin/test_server.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 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 import sys, os, re, errno, codecs 18 import sys, os, re, errno, codecs, logging
19 from ..utils import process_page 19 from ..utils import process_page
20 from ..sources import MercurialSource 20 from ..sources import MercurialSource
21 21
22 def memoize(func): 22 def memoize(func):
23 memoized = {} 23 memoized = {}
24 def wrapper(*args): 24 def wrapper(*args):
25 try: 25 try:
26 return memoized[args] 26 return memoized[args]
27 except KeyError: 27 except KeyError:
28 return memoized.setdefault(args, func(*args)) 28 return memoized.setdefault(args, func(*args))
29 return wrapper 29 return wrapper
30 30
31 def generate_pages(repo, output_dir): 31 def generate_pages(repo, output_dir):
32 known_files = set() 32 known_files = set()
33 33
34 def write_file(path_parts, contents, binary=False): 34 def write_file(path_parts, contents, binary=False):
35 encoding = None if binary else "utf-8" 35 encoding = None if binary else "utf-8"
36 outfile = os.path.join(output_dir, *path_parts) 36 outfile = os.path.join(output_dir, *path_parts)
37 if outfile in known_files: 37 if outfile in known_files:
38 print >>sys.stderr, "Warning: File %s has multiple sources" % outfile 38 logging.warning("File %s has multiple sources", outfile)
39 return 39 return
40 known_files.add(outfile) 40 known_files.add(outfile)
41 41
42 if os.path.exists(outfile): 42 if os.path.exists(outfile):
43 with codecs.open(outfile, "rb", encoding=encoding) as handle: 43 with codecs.open(outfile, "rb", encoding=encoding) as handle:
44 if handle.read() == contents: 44 if handle.read() == contents:
45 return 45 return
46 46
47 try: 47 try:
48 os.makedirs(os.path.dirname(outfile)) 48 os.makedirs(os.path.dirname(outfile))
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 os.rmdir(path) 100 os.rmdir(path)
101 remove_unknown(output_dir) 101 remove_unknown(output_dir)
102 102
103 if __name__ == "__main__": 103 if __name__ == "__main__":
104 if len(sys.argv) < 3: 104 if len(sys.argv) < 3:
105 print >>sys.stderr, "Usage: %s source_repository output_dir" % sys.argv[0] 105 print >>sys.stderr, "Usage: %s source_repository output_dir" % sys.argv[0]
106 sys.exit(1) 106 sys.exit(1)
107 107
108 repo, output_dir = sys.argv[1:3] 108 repo, output_dir = sys.argv[1:3]
109 generate_pages(repo, output_dir) 109 generate_pages(repo, output_dir)
OLDNEW
« no previous file with comments | « no previous file | cms/bin/test_server.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld