blob: 5fc02672b26e526958d69b4774de222887134b0d [file] [log] [blame]
Comran Morshedfe7f9ea2015-02-19 23:52:57 +00001#!/usr/bin/env python
2
3# This file is a modified version of the gen_embedded script included in the
4# scripts directory of seasocks (version 1.1.2). It has been modified to
5# recursively find the web files itself, which was originally done by piping
6# in the results from a "find" shell command.
7
8# The embedded files includes only those that are required for the server to run
9# (including 404 files, a default index page, favicon, etc.)
10
11import os, os.path, sys
12
13o = open('embedded.h', 'w')
14
15web = []
16for root, dirs, files in os.walk("./web", topdown=False):
17 for name in files:
18 web.append(os.path.join(root, name))
19 for name in dirs:
20 web.append(os.path.join(root, name))
21
22o.write("""
23#include "internal/Embedded.h"
24
25#include <string>
26#include <unordered_map>
27
28namespace {
29
30std::unordered_map<std::string, EmbeddedContent> embedded = {
31""")
32
33for f in web:
34 bytes = open(f, 'rb').read()
35 o.write('{"/%s", {' % os.path.basename(f))
36 o.write('"' + "".join(['\\x%02x' % ord(x) for x in bytes]) + '"')
37 o.write(',%d }},' % len(bytes))
38
39o.write("""
40};
41
42} // namespace
43
44const EmbeddedContent* findEmbeddedContent(const std::string& name) {
45 auto found = embedded.find(name);
46 if (found == embedded.end()) {
47 return NULL;
48 }
49 return &found->second;
50}
51""")
52
53o.close()