Attempt to fix CRLF/LF issue

* Generated launchers were using inconsistent endings causing very strange crashes.
  * New plan: strip current endings and let Python handle them instead.
This commit is contained in:
Alan Mason 2017-11-21 18:15:38 -08:00
parent 2db4252f69
commit d8214cce14

View file

@ -93,12 +93,12 @@ def generate_launcher(section, name, options):
# Format options # Format options
f_options = {} f_options = {}
for opt in options.keys(): for opt in options.keys():
# Values need to be a list to support the multi-line extra code sections
if opt == 'Extra Code': if opt == 'Extra Code':
f_options['rem EXTRA_CODE'] = '{}\n'.format( f_options['rem EXTRA_CODE'] = options['Extra Code']
'\n'.join(options['Extra Code']))
elif re.search(r'^L_\w+', opt, re.IGNORECASE): elif re.search(r'^L_\w+', opt, re.IGNORECASE):
new_opt = 'set {}='.format(opt) new_opt = 'set {}='.format(opt)
f_options[new_opt] = 'set {}={}\n'.format(opt, options[opt]) f_options[new_opt] = ['set {}={}'.format(opt, options[opt])]
# Remove existing launcher # Remove existing launcher
os.makedirs(dest, exist_ok=True) os.makedirs(dest, exist_ok=True)
@ -110,8 +110,11 @@ def generate_launcher(section, name, options):
out_text = [] out_text = []
with open(template, 'r') as f: with open(template, 'r') as f:
for line in f.readlines(): for line in f.readlines():
if line.strip() in f_options: # Strip all lines to let Python handle/correct the CRLF endings
out_text.append(f_options[line.strip()]) line = line.strip()
if line in f_options:
# Extend instead of append to support extra code sections
out_text.extend(f_options[line])
else: else:
out_text.append(line) out_text.append(line)
with open(full_path, 'w') as f: with open(full_path, 'w') as f: