diff options
-rwxr-xr-x | planner_generator.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/planner_generator.py b/planner_generator.py index 66f5890..ea802e4 100755 --- a/planner_generator.py +++ b/planner_generator.py @@ -38,6 +38,7 @@ class Generator: self, year: Optional[int] = None, template: Optional[str] = None, + cover_template: Optional[str] = None, out_file: Optional[str] = None, build_dir: Optional[str] = "build", latitude: Optional[float] = None, @@ -52,7 +53,7 @@ class Generator: self.longitude = longitude self.timezone = timezone - self.out_file = out_file or self.default_template + ".pdf" + self.out_file = out_file or (template or self.default_template) + ".pdf" env = jinja2.Environment() self.templates_dir = "templates" @@ -61,13 +62,29 @@ class Generator: template = self.default_template self.template_recto = loader.load(env, template + "-r.svg") self.template_verso = loader.load(env, template + "-v.svg") - self.template_cover = loader.load(env, "cover-A6-r.svg") + self.template_cover = loader.load( + env, + self._get_cover_name(template, cover_template) + ) self.build_dir = build_dir self.page_fname = os.path.join( self.build_dir, template + "-{year}-{page:03}.svg" ) + def _get_cover_name(self, template, cover_template): + if cover_template: + return cover_template + if "A6" in template: + return "cover-A6-r.svg" + if "A5" in template: + return "cover-A5-r.svg" + if "A4" in template: + return "cover-A4-r.svg" + return "cover-A6-r.svg" + + + def render_page(self, page: int, **kw): # page counts starts with 0 if page == 0: @@ -314,6 +331,11 @@ class Command: help="Base name of the template (without -[rv].svg)", ) parser.add_argument( + "--cover-template", + default=None, + help="Full name of the template (including -[rv].svg)", + ) + parser.add_argument( "--latitude", default=None, type=float, @@ -350,6 +372,7 @@ class Command: generator( year=self.args.year, template=self.args.template, + cover_template=self.args.cover_template, latitude=self.args.latitude, longitude=self.args.longitude, timezone=self.args.timezone, |