Commit 23c5ffa5 authored by Seblu's avatar Seblu

Handle exit() in scripts

Allow scripts to call exit() or exit(0) to interupt their execution properly.
Can save a useless brace adn tab time.

Exiting another value cause script to fail.
parent e88273ee
......@@ -223,8 +223,14 @@ class Image(object):
# we need installsystems.printer to conserve arrow level
sysmodules["installsystems.printer"] = installsystems.printer
exec bytecode in global_dict
except SystemExit as e:
# skip a script which call exit(0) or exit()
if e.code is None or e.code == 0:
return
else:
raise ISError(u"Script %s exits with status" % path, e)
except Exception as e:
raise ISError(u"Unable to execute script %s" % path, e)
raise ISError(u"Fail to execute script %s" % path, e)
finally:
sysmodules.clear()
sysmodules.update(sysmodules_backup)
......
......@@ -49,6 +49,8 @@ parser = """# -*- python -*-
# global image object is a reference to current image
# global parser object is your installsystems subparser (argparse)
# you can use exit() to break the execution of the script
import os
import argparse
from installsystems.printer import arrow
......@@ -72,6 +74,8 @@ setup = u"""# -*- python -*-
# global image object is a reference to current image
# namespace object is the persistant, it can be used to store data accross scripts
# you can use exit() to break the execution of the script
from installsystems.printer import arrow
arrow(u"hostname: %s" % namespace.hostname)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment