From 0f8d64a0918977c4100ca2c33394a20415f3edb7 Mon Sep 17 00:00:00 2001 From: Lertsenem Date: Thu, 9 Jul 2020 10:19:03 +0200 Subject: [PATCH] Change arguments for dir path Now : - rootdir is the directory all the img paths will be relative to ; defaults to '.' - imgdir is the directory containing all required images ; defaults to 'res/ssbu'. It is expected to hold a 'chars' directory --- lokrez/__init__.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lokrez/__init__.py b/lokrez/__init__.py index c02efe4..cea4f5b 100644 --- a/lokrez/__init__.py +++ b/lokrez/__init__.py @@ -1,5 +1,6 @@ import argparse import datetime +import html import logging import os, os.path import sys @@ -40,9 +41,14 @@ def main(): help = "The tournament slug or id", ) top8_parser.add_argument( - "--resourcesdir", "-RD", - default = "res", - help = "The directories containing images and templates resources", + "--rootdir", "-RD", + default = None, + help = "The directories containing this script, defaults to '.'", + ) + top8_parser.add_argument( + "--imgdir", "-ID", + default = "res/ssbu", + help = "The directories containing images", ) top8_parser.add_argument( "--templatesdir", "-TD", @@ -109,6 +115,10 @@ def main(): print(version.VERSION_NAME) sys.exit(0) + # ------------------------------------------------------------------------- + if args.rootdir is None: + args.rootdir = "." # TODO compute script root? + # ------------------------------------------------------------------------- if args.command not in [ "top8" ]: parser.print_help() @@ -155,12 +165,7 @@ def main(): log.info("Génération du SVG en utilisant le template") jj2_env = jinja2.Environment( - loader = jinja2.FileSystemLoader( - os.path.join( - args.resourcesdir, - args.templatesdir, - ) - ) + loader = jinja2.FileSystemLoader( args.templatesdir ) ) jj2_tpl = jj2_env.get_template( @@ -176,18 +181,17 @@ def main(): top_players.values(), key = lambda p: p.placement, ), - "imgdir_ssbu_chars": os.path.join( - args.resourcesdir, - "ssbu", - "Super Smash Bros Ultimate", - "Fighter Portraits", + "dir_root": args.rootdir, + "dir_res_ssbu": os.path.join( + args.imgdir, + "chars", ), - } if args.outfile is None: args.outfile = "{}.svg".format(tournament.slug) + # TODO add png export jj2_tpl.stream(context).dump( args.outfile )