Force encoding to utf-8 on text file operations Fixes #332

# Conflicts:
#	ui/server.py
This commit is contained in:
Marc-Andre Ferland 2022-10-17 23:15:36 -04:00
parent e24be913e5
commit 578b3ba4f4
2 changed files with 5 additions and 5 deletions

View File

@ -616,7 +616,7 @@ Negative Prompt: {req.negative_prompt}
Stable Diffusion model: {req.use_stable_diffusion_model + '.ckpt'}
'''
try:
with open(meta_out_path, 'w') as f:
with open(meta_out_path, 'w', encoding='utf-8') as f:
f.write(metadata)
except:
print('could not save the file', traceback.format_exc())

View File

@ -60,7 +60,7 @@ def getConfig(default_val=APP_CONFIG_DEFAULTS):
mtime = os.path.getmtime(config_json_path)
if mtime <= config_last_mod_time:
return config_cached
with open(config_json_path, 'r') as f:
with open(config_json_path, 'r', encoding='utf-8') as f:
config_cached = json.load(f)
config_last_mod_time = os.path.getmtime(config_json_path)
return config_cached
@ -72,7 +72,7 @@ def getConfig(default_val=APP_CONFIG_DEFAULTS):
def setConfig(config):
try: # config.json
config_json_path = os.path.join(CONFIG_DIR, 'config.json')
with open(config_json_path, 'w') as f:
with open(config_json_path, 'w', encoding='utf-8') as f:
return json.dump(config, f)
except:
print(traceback.format_exc())
@ -100,7 +100,7 @@ def setConfig(config):
config_bat.append(f"::@set CUDA_VISIBLE_DEVICES={','.join(gpu_devices)}") # Needs better detection for edge cases, add as a comment for now.
print('Add the line "@set CUDA_VISIBLE_DEVICES=N" where N is the GPUs to use to config.bat')
config_bat_path = os.path.join(CONFIG_DIR, 'config.bat')
with open(config_bat_path, 'w') as f:
with open(config_bat_path, 'w', encoding='utf-8') as f:
f.write(f.write('\r\n'.join(config_bat)))
except Exception as e:
print(traceback.format_exc())
@ -115,7 +115,7 @@ def setConfig(config):
config_sh.append(f"#CUDA_VISIBLE_DEVICES={','.join(gpu_devices)}") # Needs better detection for edge cases, add as a comment for now.
print('Add the line "CUDA_VISIBLE_DEVICES=N" where N is the GPUs to use to config.sh')
config_sh_path = os.path.join(CONFIG_DIR, 'config.sh')
with open(config_sh_path, 'w') as f:
with open(config_sh_path, 'w', encoding='utf-8') as f:
f.write('\n'.join(config_sh))
except Exception as e:
print(traceback.format_exc())