91 lines
2.3 KiB
Python
91 lines
2.3 KiB
Python
"""
|
|
cli.conv.assets - Vhex asset converter user interface
|
|
"""
|
|
import os
|
|
|
|
from core.logger import log
|
|
from core import assets_generate
|
|
|
|
__all__ = [
|
|
'assets_conv_cli'
|
|
]
|
|
|
|
#---
|
|
# Internals
|
|
#---
|
|
|
|
__HELP__ = """vxsdk-converter-asset
|
|
Convert all assets file in the project directory.
|
|
|
|
USAGE:
|
|
vxsdk vxgos conv-asset <assets prefix> <output prefix>
|
|
|
|
DESCRIPTION:
|
|
Convert all assets file in the asset directory. This part of the converter
|
|
module will scan the provided folder (or the current working directory) and
|
|
will try to find all `vxconv.txt` file, which describe all assets that
|
|
should be converted.
|
|
|
|
If no argument is provided, then the current working directory is used as
|
|
asset prefix and a storag for all generated source file. You can modify
|
|
this behaviour using OPTIONS.
|
|
|
|
For more information about the `vxconv.txt` in the wiki.
|
|
|
|
OPTIONS:
|
|
-f, --force Force assets generation even if they exist
|
|
--bootloader Generate bootloader font encoding
|
|
--kernel Generate kernel font encoding
|
|
--os Generate OS font encoding (default)
|
|
-h, --help Display this help
|
|
"""
|
|
|
|
#---
|
|
# Public
|
|
#---
|
|
|
|
def assets_conv_cli(argv):
|
|
"""Process CLI arguments"""
|
|
# check obvious flags
|
|
if '-h' in argv or '--help' in argv:
|
|
log.user(__HELP__)
|
|
return 0
|
|
|
|
# fetch user indication
|
|
force = False
|
|
generator = 'os'
|
|
prefix_output = ''
|
|
prefix_assets = ''
|
|
assets_filter = []
|
|
for arg in argv:
|
|
if arg in ['-f', '--force']:
|
|
force = True
|
|
continue
|
|
if arg == '--bootloader':
|
|
generator = 'bootloader'
|
|
continue
|
|
if not prefix_assets:
|
|
prefix_assets = arg
|
|
continue
|
|
if arg.find('--filter=') == 0:
|
|
assets_filter = arg[9:].split(',')
|
|
continue
|
|
if prefix_output:
|
|
log.warn(f"previous output path ({prefix_output}) dropped")
|
|
prefix_output = arg
|
|
|
|
# check indication
|
|
if not prefix_assets:
|
|
log.emergency('missing assets prefix')
|
|
if not prefix_assets:
|
|
log.emergency('missing output prefix')
|
|
|
|
# generate assets information
|
|
return assets_generate(
|
|
os.path.abspath(prefix_assets),
|
|
os.path.abspath(prefix_output),
|
|
generator,
|
|
assets_filter,
|
|
force
|
|
)
|