-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
executable file
·29 lines (22 loc) · 946 Bytes
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python
import os
import shlex
from snixCore import execute, execute_in_dir_and_revert, abort
import snixLogger
logger = snixLogger.SnixLogger.logger()
class Script:
"""Represents an executable script."""
def __init__(self, context):
if not type(context) is dict:
abort('Cannot execute a script without the configuration.')
self._context = context
def execute(self):
script_path=os.path.join(self._context['snix_root'],self._context['script_location'])
if not os.access(script_path, os.X_OK):
abort(script_path+"is not executable!")
with execute_in_dir_and_revert(os.path.split(script_path)[0]):
msg = "Executing {0}...".format(script_path)
logger.info(msg + script_path)
ret = execute(shlex.split(script_path), True)
logger.info(msg + 'StatusCode:' + str(ret))
logger.info(msg + 'Done!')