From deac1a6ddaa52343922fcfbed0e2caaf9869cda2 Mon Sep 17 00:00:00 2001 From: Alan Mason <1923621+2Shirt@users.noreply.github.com> Date: Tue, 21 Nov 2017 13:26:33 -0800 Subject: [PATCH] Completed generate launchers --- .bin/Scripts/Launcher_Template.cmd | 2 +- .bin/Scripts/functions/update.py | 35 ++++++++++++++++++++++++++++++ .bin/Scripts/update_kit.py | 8 ++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/.bin/Scripts/Launcher_Template.cmd b/.bin/Scripts/Launcher_Template.cmd index 488f5800..c7078e1c 100644 --- a/.bin/Scripts/Launcher_Template.cmd +++ b/.bin/Scripts/Launcher_Template.cmd @@ -14,7 +14,7 @@ call :SetTitle Launcher :Optional :: This section is for any work that needs done before launching L_ITEM -rem EXTRA_CODE_GOES_HERE +rem EXTRA_CODE :DefineLaunch :: Set L_TYPE to one of these options: diff --git a/.bin/Scripts/functions/update.py b/.bin/Scripts/functions/update.py index 7dcc590f..cf3d4e3e 100644 --- a/.bin/Scripts/functions/update.py +++ b/.bin/Scripts/functions/update.py @@ -81,6 +81,41 @@ def extract_temp_to_cbin(source, item, mode='x', sz_args=[]): shutil.copytree(include_path, dest) extract_generic(source, dest, mode, sz_args) +def generate_launcher(section, name, options): + # Prep + dest = r'{}\{}'.format(global_vars['BaseDir'], section) + if section == '(Root)': + dest = global_vars['BaseDir'] + full_path = r'{}\{}.cmd'.format(dest, name) + template = r'{}\Scripts\Launcher_Template.cmd'.format(global_vars['BinDir']) + + # Format options + f_options = {} + for opt in options.keys(): + if opt == 'Extra Code': + f_options['rem EXTRA_CODE'] = '{}\n'.format( + '\n'.join(options['Extra Code'])) + elif re.search(r'^L_\w+', opt, re.IGNORECASE): + new_opt = 'set {}='.format(opt) + f_options[new_opt] = 'set {}={}\n'.format(opt, options[opt]) + + # Remove existing launcher + os.makedirs(dest, exist_ok=True) + if os.path.exists(full_path): + remove_item(full_path) + sleep(1) + + # Read template and update using f_options + out_text = [] + with open(template, 'r') as f: + for line in f.readlines(): + if line.strip() in f_options: + out_text.append(f_options[line.strip()]) + else: + out_text.append(line) + with open(full_path, 'w') as f: + f.writelines(out_text) + def remove_item(item_path): if os.path.exists(item_path): if os.path.isdir(item_path): diff --git a/.bin/Scripts/update_kit.py b/.bin/Scripts/update_kit.py index 4ce18a7e..3f5cc069 100644 --- a/.bin/Scripts/update_kit.py +++ b/.bin/Scripts/update_kit.py @@ -118,7 +118,13 @@ if __name__ == '__main__': item = item) ## Generate Launchers - # TODO + print_success('Generating launchers') + for section in sorted(LAUNCHERS.keys()): + print_info(' {}'.format(section)) + for name, options in sorted(LAUNCHERS[section].items()): + try_and_print(message=name, function=generate_launcher, + section=section, name=name, options=options, + other_results=other_results, width=40) # Done print_standard('\nDone.')