Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
gen_manifest.py
Go to the documentation of this file.
1# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2# for details. All rights reserved. Use of this source code is governed by a
3# BSD-style license that can be found in the LICENSE file.
4
5#!/usr/bin/env python3
6#
7"""
8Usage: gen_manifest.py DIRECTORY EXTENSIONS CACHE-FILE HTML-FILES...
9
10Outputs an app cache manifest file including (recursively) all files with the
11provided in the directory with the given extensions. Each html files is then
12processed and a corresponding <name>-cache.html file is created, pointing at
13the appropriate cache manifest file, which is saved as <name>-cache.manifest.
14
15Example:
16gen_manifest.py war *.css,*.html,*.js,*.png cache.manifest foo.html bar.html
17
18Produces: foo-cache.html, bar-cache.html, and cache.manifest
19"""
20
21import fnmatch
22import os
23import random
24import sys
25import datetime
26
27cacheDir = sys.argv[1]
28extensions = sys.argv[2].split(',')
29manifestName = sys.argv[3]
30htmlFiles = sys.argv[4:]
31
32os.chdir(cacheDir)
33print("Generating manifest from root path: " + cacheDir)
34
35patterns = extensions + htmlFiles
36
37
38def matches(file):
39 for pattern in patterns:
40 if fnmatch.fnmatch(file, pattern):
41 return True
42 return False
43
44
45def findFiles(rootDir):
46 for root, dirs, files in os.walk(rootDir):
47 for f in files:
48 # yields this file relative to the given directory
49 yield os.path.join(root, f)[(len(rootDir) + 1):]
50
51
52manifest = []
53manifest.append("CACHE MANIFEST")
54
55# print out a random number to force the browser to update the cache manifest
56manifest.append("# %s" % datetime.datetime.now().isoformat())
57
58# print out each file to be included in the cache manifest
59manifest.append("CACHE:")
60
61manifest += (f for f in findFiles('.') if matches(f))
62
63# force the browser to request any other files over the network,
64# even when offline (better failure mode)
65manifest.append("NETWORK:")
66manifest.append("*")
67
68with open(manifestName, 'w') as f:
69 f.writelines(m + '\n' for m in manifest)
70
71print("Created manifest file: " + manifestName)
72
73for htmlFile in htmlFiles:
74 cachedHtmlFile = htmlFile.replace('.html', '-cache.html')
75 text = open(htmlFile, 'r').read()
76 text = text.replace('<html>', '<html manifest="%s">' % manifestName, 1)
77 with open(cachedHtmlFile, 'w') as output:
78 output.write(text)
79 print("Processed html file: %s -> %s" % (htmlFile, cachedHtmlFile))
80
81print("Successfully generated manifest and html files")
static bool read(SkStream *stream, void *buffer, size_t amount)
void print(void *str)
Definition bridge.cpp:126
findFiles(rootDir)