8Usage: gen_manifest.py DIRECTORY EXTENSIONS CACHE-FILE HTML-FILES...
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.
16gen_manifest.py war *.css,*.html,*.js,*.png cache.manifest foo.html bar.html
18Produces: foo-cache.html, bar-cache.html, and cache.manifest
28extensions = sys.argv[2].split(
',')
29manifestName = sys.argv[3]
30htmlFiles = sys.argv[4:]
33print(
"Generating manifest from root path: " + cacheDir)
35patterns = extensions + htmlFiles
39 for pattern
in patterns:
40 if fnmatch.fnmatch(file, pattern):
46 for root, dirs, files
in os.walk(rootDir):
49 yield os.path.join(root, f)[(
len(rootDir) + 1):]
53manifest.append(
"CACHE MANIFEST")
56manifest.append(
"# %s" % datetime.datetime.now().isoformat())
59manifest.append(
"CACHE:")
65manifest.append(
"NETWORK:")
68with open(manifestName,
'w')
as f:
69 f.writelines(m +
'\n' for m
in manifest)
71print(
"Created manifest file: " + manifestName)
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:
79 print(
"Processed html file: %s -> %s" % (htmlFile, cachedHtmlFile))
81print(
"Successfully generated manifest and html files")
static bool read(SkStream *stream, void *buffer, size_t amount)
def print(*args, **kwargs)