Skip to content

Commit 6a032d5

Browse files
committed
Improve workflow runner application.
1 parent e7b2992 commit 6a032d5

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

src/mapclient/runner.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def _backup_and_merge_config(location, config_file, config, config_name):
6666

6767

6868
def _restore_backup(config_file):
69+
if os.path.isfile(config_file):
70+
os.remove(config_file)
71+
6972
os.rename(_backup_file(config_file), config_file)
7073

7174

@@ -94,10 +97,10 @@ def _determine_configuration_name(wf, identifier):
9497
def workflow_runner(location, configuration):
9598

9699
if not is_workflow(location):
97-
sys.exit(1)
100+
return 1
98101

99102
if not is_json(configuration):
100-
sys.exit(2)
103+
return 2
101104

102105
with open(configuration) as fh:
103106
config = json.load(fh)
@@ -120,17 +123,25 @@ def workflow_runner(location, configuration):
120123
if errors:
121124
for error in errors:
122125
print(error)
123-
else:
126+
127+
return 3
128+
129+
try:
124130
sans_gui_main(location)
131+
return_code = 0
132+
except Exception:
133+
return_code = 4
134+
finally:
135+
for modified_config in modified_configs:
136+
_restore_backup(modified_config)
125137

126-
for modified_config in modified_configs:
127-
_restore_backup(modified_config)
138+
return return_code
128139

129140

130141
def main():
131142
args = _parse_arguments()
132-
workflow_runner(args.workflow, args.configuration)
143+
return workflow_runner(args.workflow, args.configuration)
133144

134145

135146
if __name__ == "__main__":
136-
main()
147+
sys.exit(main())

0 commit comments

Comments
 (0)