git @ Cat's Eye Technologies kinoje / c9a3651
Can't resist defining a base class and inheriting from it. Chris Pressey 4 years ago
4 changed file(s) with 23 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
11 import os
22 import sys
33
4 from kinoje.utils import Executor, load_config_file, zrange
4 from kinoje.utils import BaseProcessor, Executor, load_config_file, zrange
55
66
77 SUPPORTED_OUTPUT_FORMATS = ('.m4v', '.mp4', '.gif')
88
99
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)
1213 self.dirname = dirname
13 self.exe = exe or Executor()
1414 self.outfilename = outfilename
15 self.config = config
1615 self.frame_fmt = "%08d.png"
17 if not tqdm:
18 def tqdm(x, **kwargs): return x
19 self.tqdm = tqdm
2016
2117 @classmethod
2218 def get_class_for(cls, filename):
55
66 from jinja2 import Template
77
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
99
1010
11 class Expander(object):
11 class Expander(BaseProcessor):
1212 """Takes a directory and a template (Jinja2) and expands the template a number of times,
1313 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)
1516 self.dirname = dirname
1617 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
2318 self.fun_context = {}
2419 for key, value in items(self.config.get('functions', {})):
2520 self.fun_context[key] = eval("lambda x: " + value)
88 except ImportError:
99 from yaml import Loader
1010
11 from kinoje.utils import Executor, load_config_file
11 from kinoje.utils import BaseProcessor, Executor, load_config_file
1212
1313
14 class Renderer(object):
14 class Renderer(BaseProcessor):
1515 """Takes a source directory filled with text files and a destination directory and
1616 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
1821 self.command = config['command']
1922 self.libdir = config['libdir']
20 self.src = src
21 self.dest = dest
22 self.exe = exe or Executor()
2323 self.width = config['width']
2424 self.height = config['height']
25 if not tqdm:
26 def tqdm(x, **kwargs): return x
27 self.tqdm = tqdm
2825
2926 def render_all(self):
3027 for filename in self.tqdm(sorted(os.listdir(self.src))):
00 import os
11 import sys
22 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
312
413
514 def items(d):