Compiler class factory sketch.
Chris Pressey
4 years ago
14 | 14 |
self.outfilename = outfilename
|
15 | 15 |
self.config = config
|
16 | 16 |
self.frame_fmt = "%08d.png"
|
|
17 |
|
|
18 |
@classmethod
|
|
19 |
def get_class_for(cls, filename):
|
|
20 |
(whatever, outext) = os.path.splitext(filename)
|
|
21 |
if outext not in SUPPORTED_OUTPUT_FORMATS:
|
|
22 |
raise ValueError("%s not a supported output format (%r)" % (outext, SUPPORTED_OUTPUT_FORMATS))
|
|
23 |
return {
|
|
24 |
'.gif': GifCompiler,
|
|
25 |
'.mp4': MpegCompiler,
|
|
26 |
'.m4v': MpegCompiler,
|
|
27 |
}[outext]
|
|
28 |
|
|
29 |
def compile(self, num_frames):
|
|
30 |
raise NotImplementedError
|
|
31 |
|
|
32 |
def compile_all(self):
|
|
33 |
return self.compile(self.config['num_frames'])
|
17 | 34 |
|
18 | 35 |
|
19 | 36 |
class GifCompiler(Compiler):
|
|
87 | 104 |
|
88 | 105 |
exe = LoggingExecutor('compiler.log')
|
89 | 106 |
|
90 | |
compiler = {
|
91 | |
'.gif': GifCompiler,
|
92 | |
'.mp4': MpegCompiler,
|
93 | |
'.m4v': MpegCompiler,
|
94 | |
}[outext](options.framesdir, options.output, config, exe)
|
95 | |
|
96 | |
compiler.compile(config['num_frames'])
|
|
107 |
compiler = Compiler.get_class_for(options.output)(options.framesdir, options.output, config, exe)
|
|
108 |
compiler.compile_all()
|
97 | 109 |
|
98 | 110 |
if options.view:
|
99 | 111 |
compiler.view()
|
51 | 51 |
renderer = Renderer(config, instants_dir, frames_dir, exe)
|
52 | 52 |
renderer.render_all()
|
53 | 53 |
|
54 | |
compiler = {
|
55 | |
'.gif': GifCompiler,
|
56 | |
'.mp4': MpegCompiler,
|
57 | |
'.m4v': MpegCompiler,
|
58 | |
}[outext](frames_dir, output_filename, config, exe)
|
|
54 |
compiler = Compiler.get_class_for(output_filename)(frames_dir, output_filename, config, exe)
|
|
55 |
compiler.compile_all()
|
59 | 56 |
|
60 | 57 |
exe.close()
|