Update lokrez workflow to fit other smash games

Changes to basic args, etc. Commit not functionnal yet.
master
Lertsenem 2021-03-03 09:12:35 +01:00
parent b75e78f89a
commit 4854993a23
1 changed files with 115 additions and 46 deletions

View File

@ -16,6 +16,8 @@ from . import resources
from . import smashgg from . import smashgg
from . import version from . import version
from .games import ssbu, pplus, melee
# ============================================================================= # =============================================================================
__version__ = version.__version__ __version__ = version.__version__
__license__ = version.__license__ __license__ = version.__license__
@ -72,7 +74,7 @@ def get_infos_from_url(
# Get infos from smash.gg and write the config file # Get infos from smash.gg and write the config file
tournament, top_players = getTournamentTop( tournament, top_players = getTournamentTop(
id_or_slug = url_parsed.path.split("/")[2], id_or_slug = url_parsed.path.split("/")[2],
get_prefixes = options.get("use_smashgg_prefixes", False), import_options = options,
top = top, top = top,
token = token, token = token,
proxy = proxy, proxy = proxy,
@ -100,6 +102,53 @@ def get_infos_from_url(
)) ))
) )
# =============================================================================
def init_resources(
imgdir,
game,
source = None,
store_raw = False,
proxy = None,
log = LOG_DUMMY,
):
# Create imgdir
imgdir.mkdir(parents=True, exist_ok=True)
# Start resources download according to game
if game in ssbu.GAME.list_names():
resources.download_res(
dstdir = imgdir,
game = ssbu,
source = source,
store_raw = store_raw,
proxy = proxy,
log = log,
)
elif game in melee.GAME.list_names():
resources.download_res_ssbm(
dstdir = imgdir,
game = melee,
source = source,
store_raw = store_raw,
proxy = proxy,
log = log,
)
elif game in pplus.GAME.list_names():
resources.download_res(
dstdir = imgdir,
game = pplus,
source = source,
store_raw = store_raw,
proxy = proxy,
log = log,
)
else:
log.error("Unknown game '{}'".format(game))
return 1
return 0
# ============================================================================= # =============================================================================
def generate_pic( def generate_pic(
infos_or_lkrzfile = None, infos_or_lkrzfile = None,
@ -185,6 +234,13 @@ def main():
help = "The game you want to initialize the resources for", help = "The game you want to initialize the resources for",
) )
init_parser.add_argument(
"--source", "-s",
default = None,
choices = ["spriters", "smashlyon"],
help = "From where should the resources images be downloaded",
)
init_parser.add_argument( init_parser.add_argument(
"--imgdir", "-ID", "--imgdir", "-ID",
type = pathlib.Path, type = pathlib.Path,
@ -192,6 +248,12 @@ def main():
help = "The directory we should download the resources to", help = "The directory we should download the resources to",
) )
init_parser.add_argument(
"--raw", "-r",
action = "store_true",
help = "Download the raw zipfiles instead of extracting them",
)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
top8_parser = subparsers.add_parser( top8_parser = subparsers.add_parser(
"top8", "top8",
@ -201,13 +263,22 @@ def main():
top8_parser.add_argument( top8_parser.add_argument(
"tournament", "tournament",
default = None, default = None,
help = "The tournament slug or id", help = "The tournament url, slug or id",
) )
top8_parser.add_argument( top8_parser.add_argument(
"--token", "-t", "--token", "-t",
default = None, default = None,
help = "the authentication token to use", help = "the authentication token to use ; needed if you're " \
"generating the top8 from a smash.gg url",
)
top8_parser.add_argument(
"--playerskinsdb", "-P",
type = (lambda s: s if s.startswith("http") else pathlib.Path(s)),
default = ROOTDIR / "data" / "playerskinsdb.json",
help = "A JSON file path or url matching player tags, characters,"\
" sponsors, and preferred skins",
) )
top8_parser.add_argument( top8_parser.add_argument(
@ -217,13 +288,6 @@ def main():
help = "The directories containing images, be careful whether " \ help = "The directories containing images, be careful whether " \
"you specify an absolute path or a relative one.", "you specify an absolute path or a relative one.",
) )
top8_parser.add_argument(
"--playerskinsdb", "-PD",
type = (lambda s: s if s.startswith("http") else pathlib.Path(s)),
default = ROOTDIR / "data" / "playerskinsdb.json",
help = "A JSON file path or url matching player tags, characters,"\
" sponsors, and preferred skins",
)
top8_parser.add_argument( top8_parser.add_argument(
"--cachedir", "-CD", "--cachedir", "-CD",
type = pathlib.Path, type = pathlib.Path,
@ -243,48 +307,41 @@ def main():
help = "The local result template to use", help = "The local result template to use",
) )
top8_parser.add_argument( top8_parser.add_argument(
"--template-options", "-O", "--template-options", "-TO",
action = "append", action = "append",
default = [], default = [],
help = "Template-specific options", help = "Template-specific options (like 'covid' or 'animated')",
) )
top8_parser.add_argument( top8_parser.add_argument(
"--export-options", "-E", "--export-options", "-EO",
action = "append", action = "append",
default = [], default = [],
help = "Export options (like svg_embed_png)", help = "Export options (like 'svg_embed_png')",
) )
top8_parser.add_argument( top8_parser.add_argument(
"--lkrz-file", "-f", "--import-options", "-IO",
type = pathlib.Path, action = "append",
default = None, default = [],
help = "The lkrz file in which the results are stored ; if it " \ help = "Import options (like 'use_smashgg_prefixes')",
"does not exist, one will be created from the smashgg data",
) )
top8_parser.add_argument( top8_parser.add_argument(
"--outfile", "-o", "--outfile", "-o",
type = pathlib.Path, type = pathlib.Path,
default = None, default = None,
help = "The SVG or PNG local result file to output to ; if it's " \ help = "The SVG or PNG local result file to output to ; if it's " \
"not specified, it will use the tournament slug as name", "not specified, it will default to SVG and use the " \
"tournament slug as name ; if you're generating a " \
"localresult from a url, a LKRZ file with the same name " \
"will also be generated along the image file (unless you " \
"use the --no-lkrz flag).",
) )
top8_parser.add_argument( parser.add_argument( "--no-lkrz", "-nl",
"--name-seo-delimiter", default = False,
default = None, action = "store_true",
help = "A character that will delimit in a tournament name what " \ help = "Do not output a LKRZ file" )
"really is its name, and what's actually here for SEO " \
"purposes (example: in 'Cornismash #42 - Ultimate Weekly " \
"Lyon', only the 'Cornismash #42' is the tournament name, "\
"the rest is here to help find the tournament).",
)
top8_parser.add_argument(
"--use-smashgg-prefixes", "-P",
action = "store_true",
help = "Use the prefixes (sponsor, team, etc) set by players on " \
"smash.gg for the tournament",
)
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
parser.add_argument( "--verbose", "-v", parser.add_argument( "--verbose", "-v",
@ -327,20 +384,28 @@ def main():
print(version.VERSION_NAME) print(version.VERSION_NAME)
return 0 return 0
# Check if command is recognized
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
if args.command not in [ "init", "top8" ]: if args.command not in [ "init", "top8" ]:
parser.print_help() parser.print_help()
return 1 return 1
# -- init
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
if args.command == "init": if args.command == "init":
args.imgdir.mkdir(parents=True, exist_ok=True)
resources.download_res_ssbu( rv = init_resources(
dstdir = args.imgdir, imgdir = args.imgdir,
game = args.game,
source = args.source,
store_raw = args.raw,
proxy = args.proxy, proxy = args.proxy,
log = log, log = log,
) )
return 0
return rv
# -- top8
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
if args.command == "top8": if args.command == "top8":
@ -410,20 +475,24 @@ def main():
else: else:
# Get infos from smash.gg and write the config file infos = get_infos_from_url(
tournament, top_players = getTournamentTop( url = args.tournament,
id_or_slug = args.tournament,
get_prefixes = args.use_smashgg_prefixes,
top = 8,
token = args.token, token = args.token,
options = args.import_options,
outform = "dict",
top = 8,
proxy = args.proxy, proxy = args.proxy,
log = log, log = log,
) )
tournament = infos["tournament"]
top_players = infos["players"]
if tournament is None or top_players is None: if tournament is None or top_players is None:
log.error("Could not load data from smash.gg") log.error("Could not load data from smash.gg")
return 1 return 1
# Save a lkrz file
lkrz_data = "\n".join( lkrz_data = "\n".join(
[ tournament.conf() ] \ [ tournament.conf() ] \
+ list(map( + list(map(
@ -483,7 +552,7 @@ def main():
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
def getTournamentTop( def getTournamentTop(
id_or_slug, id_or_slug,
get_prefixes = True, import_options = {}
top = 8, top = 8,
token = "", token = "",
proxy = None, proxy = None,
@ -622,7 +691,7 @@ def getTournamentTop(
except TypeError: except TypeError:
twitterHandle = None twitterHandle = None
if get_prefixes: if import_options.get("use_smashgg_prefixes", True):
prefix = participant_data["prefix"] prefix = participant_data["prefix"]
else: else:
prefix = "" prefix = ""