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

Side by Side Diff: sitescripts/web/bin/test_server.py

Issue 17817001: Simple CMS as Anwiki replacement (Closed)
Patch Set: Created Oct. 23, 2013, 1:52 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/web/bin/generate_static_pages.py ('k') | sitescripts/web/converters.py » ('j') | 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-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 sys, os, flask
19 from sitescripts.utils import setupStderr
20 from sitescripts.web.utils import process_page
21 from sitescripts.web.sources import FileSource
22 from sitescripts.web.converters import converters
23
24 app = flask.Flask("sitescripts.web.bin.test_server")
25 source = None
26
27 def get_data(path):
28 if "/" in path:
29 locale, page = path.split("/", 1)
30 for format in converters.iterkeys():
31 if source.has_page(page, format):
32 return process_page(source, locale, page, format)
33 if source.has_localizable_file(locale, page):
34 return source.read_localizable_file(locale, page)
35
36 if source.has_static(path):
37 return source.read_static(path)
38
39 return None
40
41 @app.route("/<path:path>", methods = ["GET"])
42 def show(path):
43 data = get_data(path)
44 if data == None:
45 flask.abort(404)
46
47 root, ext = os.path.splitext(path)
48 if ext == ".js":
49 mime = "text/js; charset=utf-8"
50 elif ext == ".css":
51 mime = "text/css; charset=utf-8"
52 elif ext == ".png":
53 mime = "image/png"
54 elif ext == "":
55 mime = "text/html; charset=utf-8"
56 else:
57 mime = "application/octet-stream"
58 return data, 200, {"Content-Type": mime}
59
60 if __name__ == "__main__":
61 setupStderr()
62 if len(sys.argv) < 2:
63 print >>sys.stderr, "Usage: %s source_dir" % sys.argv[0]
64 sys.exit(1)
65
66 source = FileSource(sys.argv[1])
67 app.run(debug=True, use_reloader=False)
OLDNEW
« no previous file with comments | « sitescripts/web/bin/generate_static_pages.py ('k') | sitescripts/web/converters.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld