Check if file exists and abort if t doesn't

This commit is contained in:
David Kilias 2020-03-22 21:35:36 +01:00 committed by Stefan Haun
parent 7cbcefa4de
commit 43c2cffc83

View file

@ -4,7 +4,7 @@
import npyscreen
import json
import datetime
from sys import argv
import sys
import pathlib
from base_data_model import base_data_model
@ -59,18 +59,21 @@ class FormApp(npyscreen.NPSAppManaged):
def main(*_args):
if len(argv) > 1:
filename = argv[1]
if len(sys.argv) > 1:
file_path = pathlib.Path(sys.argv[1])
if not file_path.exists():
print("Trying to open nonexistent file. Aborting.")
sys.exit(0)
else:
filename = pathlib.Path(pathlib.Path(__file__).absolute().parent, 'example.json')
file_path = pathlib.Path(pathlib.Path(__file__).absolute().parent, 'example.json')
app = FormApp(filename)
app = FormApp(file_path)
try:
app.run()
except Exception as e:
print(e)
return 0
sys.exit(0)
if app.data_has_changed():
out_data = app.get_data_from_form()