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
master
Lertsenem 2020-07-09 10:19:03 +02:00
parent d5a85266c8
commit 0f8d64a091
1 changed files with 19 additions and 15 deletions

View File

@ -1,5 +1,6 @@
import argparse import argparse
import datetime import datetime
import html
import logging import logging
import os, os.path import os, os.path
import sys import sys
@ -40,9 +41,14 @@ def main():
help = "The tournament slug or id", help = "The tournament slug or id",
) )
top8_parser.add_argument( top8_parser.add_argument(
"--resourcesdir", "-RD", "--rootdir", "-RD",
default = "res", default = None,
help = "The directories containing images and templates resources", 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( top8_parser.add_argument(
"--templatesdir", "-TD", "--templatesdir", "-TD",
@ -109,6 +115,10 @@ def main():
print(version.VERSION_NAME) print(version.VERSION_NAME)
sys.exit(0) sys.exit(0)
# -------------------------------------------------------------------------
if args.rootdir is None:
args.rootdir = "." # TODO compute script root?
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
if args.command not in [ "top8" ]: if args.command not in [ "top8" ]:
parser.print_help() parser.print_help()
@ -155,12 +165,7 @@ def main():
log.info("Génération du SVG en utilisant le template") log.info("Génération du SVG en utilisant le template")
jj2_env = jinja2.Environment( jj2_env = jinja2.Environment(
loader = jinja2.FileSystemLoader( loader = jinja2.FileSystemLoader( args.templatesdir )
os.path.join(
args.resourcesdir,
args.templatesdir,
)
)
) )
jj2_tpl = jj2_env.get_template( jj2_tpl = jj2_env.get_template(
@ -176,18 +181,17 @@ def main():
top_players.values(), top_players.values(),
key = lambda p: p.placement, key = lambda p: p.placement,
), ),
"imgdir_ssbu_chars": os.path.join( "dir_root": args.rootdir,
args.resourcesdir, "dir_res_ssbu": os.path.join(
"ssbu", args.imgdir,
"Super Smash Bros Ultimate", "chars",
"Fighter Portraits",
), ),
} }
if args.outfile is None: if args.outfile is None:
args.outfile = "{}.svg".format(tournament.slug) args.outfile = "{}.svg".format(tournament.slug)
# TODO add png export
jj2_tpl.stream(context).dump( args.outfile ) jj2_tpl.stream(context).dump( args.outfile )