mirror of
https://github.com/akuker/RASCSI.git
synced 2024-09-12 09:55:00 +00:00
Merge pull request #365 from akuker/issue_356
Clean up config files after error
This commit is contained in:
commit
e2f6ce8bc2
@ -244,9 +244,11 @@ def write_config(file_name):
|
|||||||
return {"status": True, "msg": f"Successfully wrote to file: {file_name}"}
|
return {"status": True, "msg": f"Successfully wrote to file: {file_name}"}
|
||||||
except (IOError, ValueError, EOFError, TypeError) as e:
|
except (IOError, ValueError, EOFError, TypeError) as e:
|
||||||
logging.error(str(e))
|
logging.error(str(e))
|
||||||
|
delete_file(file_name)
|
||||||
return {"status": False, "msg": str(e)}
|
return {"status": False, "msg": str(e)}
|
||||||
except:
|
except:
|
||||||
logging.error(f"Could not write to file: {file_name}")
|
logging.error(f"Could not write to file: {file_name}")
|
||||||
|
delete_file(file_name)
|
||||||
return {"status": False, "msg": f"Could not write to file: {file_name}"}
|
return {"status": False, "msg": f"Could not write to file: {file_name}"}
|
||||||
|
|
||||||
|
|
||||||
@ -284,21 +286,24 @@ def read_config(file_name):
|
|||||||
|
|
||||||
def write_drive_properties(file_name, conf):
|
def write_drive_properties(file_name, conf):
|
||||||
"""
|
"""
|
||||||
Writes a drive property configuration file to the images dir.
|
Writes a drive property configuration file to the config dir.
|
||||||
Takes file name base (str) and conf (list of dicts) as arguments
|
Takes file name base (str) and conf (list of dicts) as arguments
|
||||||
Returns dict with boolean status and str msg
|
Returns dict with boolean status and str msg
|
||||||
"""
|
"""
|
||||||
from json import dump
|
from json import dump
|
||||||
|
file_path = cfg_dir + file_name
|
||||||
try:
|
try:
|
||||||
with open(cfg_dir + file_name, "w") as json_file:
|
with open(file_path, "w") as json_file:
|
||||||
dump(conf, json_file, indent=4)
|
dump(conf, json_file, indent=4)
|
||||||
return {"status": True, "msg": f"Successfully wrote to file: {file_name}"}
|
return {"status": True, "msg": f"Successfully wrote to file: {file_path}"}
|
||||||
except (IOError, ValueError, EOFError, TypeError) as e:
|
except (IOError, ValueError, EOFError, TypeError) as e:
|
||||||
logging.error(str(e))
|
logging.error(str(e))
|
||||||
|
delete_file(file_path)
|
||||||
return {"status": False, "msg": str(e)}
|
return {"status": False, "msg": str(e)}
|
||||||
except:
|
except:
|
||||||
logging.error(f"Could not write to file: {file_name}")
|
logging.error(f"Could not write to file: {file_path}")
|
||||||
return {"status": False, "msg": f"Could not write to file: {file_name}"}
|
delete_file(file_path)
|
||||||
|
return {"status": False, "msg": f"Could not write to file: {file_path}"}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user