Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
cacheimages Namespace Reference

Functions

 convertImgs (infile)
 
 Flags ()
 
 main ()
 

Variables

 SWARM_PATH = dirname(abspath(__file__))
 
 CLIENT_PATH = dirname(dirname(SWARM_PATH))
 
 CLIENT_TOOLS_PATH = join(CLIENT_PATH, 'tools')
 
str converter = CLIENT_TOOLS_PATH + '/htmlconverter.py'
 

Detailed Description

This script finds all HTML pages in a folder and downloads all images, replacing
the urls with local ones.

Function Documentation

◆ convertImgs()

cacheimages.convertImgs (   infile)

Definition at line 23 of file cacheimages.py.

23def convertImgs(infile):
24 global options
25 try:
26 htmlconverter.convertForOffline(infile,
27 infile,
28 verbose=options.verbose,
29 encode_images=options.inline_images)
30 print('Converted ' + infile)
31 except BaseException as e:
32 print('Caught error: %s' % e)
33
34
void print(void *str)
Definition bridge.cpp:126

◆ Flags()

cacheimages.Flags ( )
 Constructs a parser for extracting flags from the command line. 

Definition at line 35 of file cacheimages.py.

35def Flags():
36 """ Constructs a parser for extracting flags from the command line. """
37 parser = optparse.OptionParser()
38 parser.add_option(
39 "--inline_images",
40 help=("Encode img payloads as data:// URLs rather than local files."),
41 default=False,
42 action='store_true')
43 parser.add_option("--verbose",
44 help="Print verbose output",
45 default=False,
46 action="store_true")
47 return parser
48
49

◆ main()

cacheimages.main ( )

Definition at line 50 of file cacheimages.py.

50def main():
51 global options
52 parser = Flags()
53 options, args = parser.parse_args()
54 print("args: %s" % args)
55 if len(args) < 1 or 'help' in args[0]:
56 print('Usage: %s DIRECTORY' % basename(sys.argv[0]))
57 return 1
58
59 dirname = args[0]
60 print('Searching directory ' + dirname)
61
62 files = []
63 for root, dirs, fnames in os.walk(dirname):
64 for fname in fnames:
65 if fname.endswith('.html'):
66 files.append(join(root, fname))
67
68 count = 4 * multiprocessing.cpu_count()
69 pool = multiprocessing.Pool(processes=count)
70 # Note: need a timeout to get keyboard interrupt due to a Python bug
71 pool.map_async(convertImgs, files).get(3600) # one hour
72
73
Definition main.py:1

Variable Documentation

◆ CLIENT_PATH

cacheimages.CLIENT_PATH = dirname(dirname(SWARM_PATH))

Definition at line 13 of file cacheimages.py.

◆ CLIENT_TOOLS_PATH

cacheimages.CLIENT_TOOLS_PATH = join(CLIENT_PATH, 'tools')

Definition at line 14 of file cacheimages.py.

◆ converter

str cacheimages.converter = CLIENT_TOOLS_PATH + '/htmlconverter.py'

Definition at line 19 of file cacheimages.py.

◆ SWARM_PATH

cacheimages.SWARM_PATH = dirname(abspath(__file__))

Definition at line 12 of file cacheimages.py.