exe argument is optional, defaults to generic Executor.
Chris Pressey
4 years ago
1 | 1 |
import os
|
2 | 2 |
import sys
|
3 | 3 |
|
4 | |
from kinoje.utils import LoggingExecutor, load_config_file
|
|
4 |
from kinoje.utils import Executor, LoggingExecutor, load_config_file
|
5 | 5 |
|
6 | 6 |
|
7 | 7 |
SUPPORTED_OUTPUT_FORMATS = ('.m4v', '.mp4', '.gif')
|
8 | 8 |
|
9 | 9 |
|
10 | 10 |
class Compiler(object):
|
11 | |
def __init__(self, config, dirname, outfilename, exe):
|
|
11 |
def __init__(self, config, dirname, outfilename, exe=None):
|
12 | 12 |
self.dirname = dirname
|
13 | |
self.exe = exe
|
|
13 |
self.exe = exe or Executor()
|
14 | 14 |
self.outfilename = outfilename
|
15 | 15 |
self.config = config
|
16 | 16 |
self.frame_fmt = "%08d.png"
|
|
104 | 104 |
|
105 | 105 |
exe = LoggingExecutor('compiler.log')
|
106 | 106 |
|
107 | |
compiler = Compiler.get_class_for(options.output)(config, options.framesdir, options.output, exe)
|
|
107 |
compiler = Compiler.get_class_for(options.output)(config, options.framesdir, options.output, exe=exe)
|
108 | 108 |
compiler.compile_all()
|
109 | 109 |
|
110 | 110 |
if options.view:
|
5 | 5 |
|
6 | 6 |
from jinja2 import Template
|
7 | 7 |
|
8 | |
from kinoje.utils import LoggingExecutor, fmod, tween, load_config_file
|
|
8 |
from kinoje.utils import Executor, LoggingExecutor, fmod, tween, load_config_file
|
9 | 9 |
|
10 | 10 |
|
11 | 11 |
class Expander(object):
|
12 | 12 |
"""Takes a directory and a template (Jinja2) and expands the template a number of times,
|
13 | 13 |
creating a number of filled-out text files in the directory."""
|
14 | |
def __init__(self, config, dirname, exe):
|
|
14 |
def __init__(self, config, dirname, exe=None):
|
15 | 15 |
self.dirname = dirname
|
16 | 16 |
self.template = Template(config['template'])
|
17 | 17 |
self.config = config
|
18 | |
self.exe = exe
|
|
18 |
self.exe = exe or Executor()
|
19 | 19 |
|
20 | 20 |
self.fun_context = {}
|
21 | 21 |
for key, value in self.config.get('functions', {}).iteritems():
|
|
60 | 60 |
|
61 | 61 |
exe = LoggingExecutor('movie.log')
|
62 | 62 |
|
63 | |
expander = Expander(config, options.instantsdir, exe)
|
|
63 |
expander = Expander(config, options.instantsdir, exe=exe)
|
64 | 64 |
expander.expand_all()
|
65 | 65 |
|
66 | 66 |
exe.close()
|
47 | 47 |
instants_dir = mkdtemp()
|
48 | 48 |
frames_dir = mkdtemp()
|
49 | 49 |
|
50 | |
expander = Expander(config, instants_dir, exe)
|
|
50 |
expander = Expander(config, instants_dir, exe=exe)
|
51 | 51 |
expander.expand_all()
|
52 | 52 |
|
53 | |
renderer = Renderer(config, instants_dir, frames_dir, exe)
|
|
53 |
renderer = Renderer(config, instants_dir, frames_dir, exe=exe)
|
54 | 54 |
renderer.render_all()
|
55 | 55 |
|
56 | |
compiler = Compiler.get_class_for(output_filename)(config, frames_dir, output_filename, exe)
|
|
56 |
compiler = Compiler.get_class_for(output_filename)(config, frames_dir, output_filename, exe=exe)
|
57 | 57 |
compiler.compile_all()
|
58 | 58 |
|
59 | 59 |
exe.close()
|
8 | 8 |
except ImportError:
|
9 | 9 |
from yaml import Loader
|
10 | 10 |
|
11 | |
from kinoje.utils import LoggingExecutor, load_config_file
|
|
11 |
from kinoje.utils import Executor, LoggingExecutor, load_config_file
|
12 | 12 |
|
13 | 13 |
|
14 | 14 |
class Renderer(object):
|
15 | 15 |
"""Takes a source directory filled with text files and a destination directory and
|
16 | 16 |
creates one image file in the destination directory from each text file in the source."""
|
17 | |
def __init__(self, config, src, dest, exe):
|
|
17 |
def __init__(self, config, src, dest, exe=None):
|
18 | 18 |
self.command = config['command']
|
19 | 19 |
self.libdir = config['libdir']
|
20 | 20 |
self.src = src
|
21 | 21 |
self.dest = dest
|
22 | |
self.exe = exe
|
|
22 |
self.exe = exe or Executor()
|
23 | 23 |
self.width = config['width']
|
24 | 24 |
self.height = config['height']
|
25 | 25 |
|
|
62 | 62 |
|
63 | 63 |
exe = LoggingExecutor('renderer.log')
|
64 | 64 |
|
65 | |
renderer = Renderer(config, options.instantsdir, options.framesdir, exe)
|
|
65 |
renderer = Renderer(config, options.instantsdir, options.framesdir, exe=exe)
|
66 | 66 |
renderer.render_all()
|
67 | 67 |
|
68 | 68 |
exe.close()
|