Support for loading multiple config files as successive overlays.
Chris Pressey
3 years ago
1 | 1 | import os |
2 | 2 | import sys |
3 | 3 | |
4 | from kinoje.utils import BaseProcessor, load_config_file, zrange | |
4 | from kinoje.utils import BaseProcessor, load_config_files, zrange | |
5 | 5 | |
6 | 6 | |
7 | 7 | SUPPORTED_OUTPUT_FORMATS = ('.m4v', '.mp4', '.gif') |
76 | 76 | def main(): |
77 | 77 | argparser = ArgumentParser() |
78 | 78 | |
79 | argparser.add_argument('configfile', metavar='FILENAME', type=str, | |
80 | help='Configuration file containing the template and parameters' | |
79 | argparser.add_argument('configfile', metavar='FILENAME(S)', type=str, | |
80 | help='Configuration file containing the template and parameters. ' | |
81 | 'May be a comma-separated list of YAML files, where successive ' | |
82 | 'files are applied as overlays.' | |
81 | 83 | ) |
82 | 84 | argparser.add_argument('framesdir', metavar='DIRNAME', type=str, |
83 | 85 | help='Directory that will be populated with image of each single frame' |
104 | 106 | if outext not in SUPPORTED_OUTPUT_FORMATS: |
105 | 107 | raise ValueError("%s not a supported output format (%r)" % (outext, SUPPORTED_OUTPUT_FORMATS)) |
106 | 108 | |
107 | config = load_config_file(options.configfile) | |
109 | config = load_config_files(options.configfile) | |
108 | 110 | config['shorten_final_frame'] = options.shorten_final_frame |
109 | 111 | |
110 | 112 | compiler = Compiler.get_class_for(options.output)(config, options.framesdir, options.output) |
5 | 5 | |
6 | 6 | from jinja2 import Template |
7 | 7 | |
8 | from kinoje.utils import BaseProcessor, fmod, tween, load_config_file, items, zrange | |
8 | from kinoje.utils import BaseProcessor, fmod, tween, load_config_files, items, zrange | |
9 | 9 | |
10 | 10 | |
11 | 11 | class Expander(BaseProcessor): |
46 | 46 | argparser = ArgumentParser() |
47 | 47 | |
48 | 48 | argparser.add_argument('configfile', metavar='FILENAME', type=str, |
49 | help='Configuration file containing the template and parameters' | |
49 | help='Configuration file containing the template and parameters. ' | |
50 | 'May be a comma-separated list of YAML files, where successive ' | |
51 | 'files are applied as overlays.' | |
50 | 52 | ) |
51 | 53 | argparser.add_argument('instantsdir', metavar='DIRNAME', type=str, |
52 | 54 | help='Directory that will be populated with instants (text files describing frames)' |
55 | 57 | |
56 | 58 | options = argparser.parse_args(sys.argv[1:]) |
57 | 59 | |
58 | config = load_config_file(options.configfile) | |
60 | config = load_config_files(options.configfile) | |
59 | 61 | |
60 | 62 | expander = Expander(config, options.instantsdir) |
61 | 63 | expander.expand_all() |
11 | 11 | from kinoje.renderer import Renderer |
12 | 12 | from kinoje.compiler import Compiler, SUPPORTED_OUTPUT_FORMATS |
13 | 13 | |
14 | from kinoje.utils import LoggingExecutor, load_config_file | |
14 | from kinoje.utils import LoggingExecutor, load_config_files | |
15 | 15 | |
16 | 16 | |
17 | 17 | def main(): |
18 | 18 | argparser = ArgumentParser() |
19 | 19 | |
20 | argparser.add_argument('configfile', metavar='FILENAME', type=str, | |
20 | argparser.add_argument('configfile', metavar='FILENAME(S)', type=str, | |
21 | 21 | help='A YAML file containing the template to render for each frame, ' |
22 | 'as well as configuration for rendering the template.' | |
22 | 'as well as configuration for rendering the template. ' | |
23 | 'May be a comma-separated list of YAML files, where successive ' | |
24 | 'files are applied as overlays.' | |
23 | 25 | ) |
24 | 26 | argparser.add_argument('-o', '--output', metavar='FILENAME', type=str, default=None, |
25 | 27 | help='The movie file to create. The extension of this filename ' |
39 | 41 | |
40 | 42 | CompilerClass = Compiler.get_class_for(output_filename) |
41 | 43 | |
42 | config = load_config_file(options.configfile) | |
44 | config = load_config_files(options.configfile) | |
43 | 45 | |
44 | 46 | fd, log_filename = mkstemp() |
45 | 47 | exe = LoggingExecutor(log_filename) |
2 | 2 | import os |
3 | 3 | import sys |
4 | 4 | |
5 | from kinoje.utils import BaseProcessor, load_config_file | |
5 | from kinoje.utils import BaseProcessor, load_config_files | |
6 | 6 | |
7 | 7 | |
8 | 8 | class Renderer(BaseProcessor): |
40 | 40 | def main(): |
41 | 41 | argparser = ArgumentParser() |
42 | 42 | |
43 | argparser.add_argument('configfile', metavar='FILENAME', type=str, | |
44 | help='Configuration file containing the template and parameters' | |
43 | argparser.add_argument('configfile', metavar='FILENAME(S)', type=str, | |
44 | help='Configuration file containing the template and parameters. ' | |
45 | 'May be a comma-separated list of YAML files, where successive ' | |
46 | 'files are applied as overlays.' | |
45 | 47 | ) |
46 | 48 | argparser.add_argument('instantsdir', metavar='DIRNAME', type=str, |
47 | 49 | help='Directory containing instants (text file descriptions of each single frame) to render' |
53 | 55 | |
54 | 56 | options = argparser.parse_args(sys.argv[1:]) |
55 | 57 | |
56 | config = load_config_file(options.configfile) | |
58 | config = load_config_files(options.configfile) | |
57 | 59 | |
58 | 60 | renderer = Renderer(config, options.instantsdir, options.framesdir) |
59 | 61 | renderer.render_all() |
23 | 23 | return xrange(*args) |
24 | 24 | except NameError: |
25 | 25 | return range(*args) |
26 | ||
27 | ||
28 | def load_config_files(filenames): | |
29 | if ',' in filenames: | |
30 | config = {} | |
31 | for filename in filenames.split(','): | |
32 | config.update(load_config_file(filename)) | |
33 | return config | |
34 | else: | |
35 | return load_config_file(filenames) | |
26 | 36 | |
27 | 37 | |
28 | 38 | def load_config_file(filename): |