# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
# This module contains code for running an HTTP server to view build info. import http.server import json import os
import requests
class HTTPHandler(http.server.BaseHTTPRequestHandler): def do_GET(self):
s = self.server.wrapper
p = self.path
if p == "/build_resources.json":
self.send_response(200)
self.send_header("Content-Type", "application/json; charset=utf-8")
self.end_headers()
keys = sorted(s.json_files.keys())
s = json.dumps({"files": ["resources/%s" % k for k in keys]})
self.wfile.write(s.encode("utf-8")) return
if p.startswith("/resources/"):
key = p[len("/resources/") :]
if key notin s.json_files:
self.send_error(404) return
# Cheap security. This doesn't resolve symlinks, etc. But, it should be # acceptable since this server only runs locally. ifnot local_path.startswith(root):
self.send_error(404)
with open(local_path, "rb") as fh:
self.wfile.write(fh.read())
class BuildViewerServer(object): def __init__(self, address="localhost", port=0): # TODO use pkg_resources to obtain HTML resources.
pkg_dir = os.path.dirname(os.path.abspath(__file__))
doc_root = os.path.join(pkg_dir, "resources", "html-build-viewer") assert os.path.isdir(doc_root)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.