git @ Cat's Eye Technologies kinoje / 46eac99
Compiler class factory sketch. Chris Pressey 4 years ago
2 changed file(s) with 21 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
1414 self.outfilename = outfilename
1515 self.config = config
1616 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'])
1734
1835
1936 class GifCompiler(Compiler):
87104
88105 exe = LoggingExecutor('compiler.log')
89106
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()
97109
98110 if options.view:
99111 compiler.view()
5151 renderer = Renderer(config, instants_dir, frames_dir, exe)
5252 renderer.render_all()
5353
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()
5956
6057 exe.close()