Can't resist defining a base class and inheriting from it.
Chris Pressey
5 years ago
1 | 1 |
import os
|
2 | 2 |
import sys
|
3 | 3 |
|
4 | |
from kinoje.utils import Executor, load_config_file, zrange
|
|
4 |
from kinoje.utils import BaseProcessor, Executor, load_config_file, zrange
|
5 | 5 |
|
6 | 6 |
|
7 | 7 |
SUPPORTED_OUTPUT_FORMATS = ('.m4v', '.mp4', '.gif')
|
8 | 8 |
|
9 | 9 |
|
10 | |
class Compiler(object):
|
11 | |
def __init__(self, config, dirname, outfilename, exe=None, tqdm=None):
|
|
10 |
class Compiler(BaseProcessor):
|
|
11 |
def __init__(self, config, dirname, outfilename, **kwargs):
|
|
12 |
super(Compiler, self).__init__(config, **kwargs)
|
12 | 13 |
self.dirname = dirname
|
13 | |
self.exe = exe or Executor()
|
14 | 14 |
self.outfilename = outfilename
|
15 | |
self.config = config
|
16 | 15 |
self.frame_fmt = "%08d.png"
|
17 | |
if not tqdm:
|
18 | |
def tqdm(x, **kwargs): return x
|
19 | |
self.tqdm = tqdm
|
20 | 16 |
|
21 | 17 |
@classmethod
|
22 | 18 |
def get_class_for(cls, filename):
|
5 | 5 |
|
6 | 6 |
from jinja2 import Template
|
7 | 7 |
|
8 | |
from kinoje.utils import Executor, fmod, tween, load_config_file, items, zrange
|
|
8 |
from kinoje.utils import BaseProcessor, Executor, fmod, tween, load_config_file, items, zrange
|
9 | 9 |
|
10 | 10 |
|
11 | |
class Expander(object):
|
|
11 |
class Expander(BaseProcessor):
|
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=None, tqdm=None):
|
|
14 |
def __init__(self, config, dirname, **kwargs):
|
|
15 |
super(Expander, self).__init__(config, **kwargs)
|
15 | 16 |
self.dirname = dirname
|
16 | 17 |
self.template = Template(config['template'])
|
17 | |
self.config = config
|
18 | |
self.exe = exe or Executor()
|
19 | |
if not tqdm:
|
20 | |
def tqdm(x, **kwargs): return x
|
21 | |
self.tqdm = tqdm
|
22 | |
|
23 | 18 |
self.fun_context = {}
|
24 | 19 |
for key, value in items(self.config.get('functions', {})):
|
25 | 20 |
self.fun_context[key] = eval("lambda x: " + value)
|
8 | 8 |
except ImportError:
|
9 | 9 |
from yaml import Loader
|
10 | 10 |
|
11 | |
from kinoje.utils import Executor, load_config_file
|
|
11 |
from kinoje.utils import BaseProcessor, Executor, load_config_file
|
12 | 12 |
|
13 | 13 |
|
14 | |
class Renderer(object):
|
|
14 |
class Renderer(BaseProcessor):
|
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=None, tqdm=None):
|
|
17 |
def __init__(self, config, src, dest, **kwargs):
|
|
18 |
super(Renderer, self).__init__(config, **kwargs)
|
|
19 |
self.src = src
|
|
20 |
self.dest = dest
|
18 | 21 |
self.command = config['command']
|
19 | 22 |
self.libdir = config['libdir']
|
20 | |
self.src = src
|
21 | |
self.dest = dest
|
22 | |
self.exe = exe or Executor()
|
23 | 23 |
self.width = config['width']
|
24 | 24 |
self.height = config['height']
|
25 | |
if not tqdm:
|
26 | |
def tqdm(x, **kwargs): return x
|
27 | |
self.tqdm = tqdm
|
28 | 25 |
|
29 | 26 |
def render_all(self):
|
30 | 27 |
for filename in self.tqdm(sorted(os.listdir(self.src))):
|
0 | 0 |
import os
|
1 | 1 |
import sys
|
2 | 2 |
from subprocess import check_call
|
|
3 |
|
|
4 |
|
|
5 |
class BaseProcessor(object):
|
|
6 |
def __init__(self, config, exe=None, tqdm=None):
|
|
7 |
self.config = config
|
|
8 |
self.exe = exe or Executor()
|
|
9 |
if not tqdm:
|
|
10 |
def tqdm(x, **kwargs): return x
|
|
11 |
self.tqdm = tqdm
|
3 | 12 |
|
4 | 13 |
|
5 | 14 |
def items(d):
|