def run_script(script, remote=True): ''' Run a script. ''' custom_scripts = _get_config()['scripts'] # If the script is not defined raise error. if not is_script_defined(script): raise RuntimeError('Missing script "{}"'.format(script)) needs_notification = should_notify(script) if needs_notification: notif.send(RUNNING_SCRIPT_STARTED, { 'script': script, 'user': shell.get_user(), 'stage': shell.get_stage() }) # Get the command defined in the script. script_cmd = custom_scripts[script] info_text = 'Running {}\n{}'.format( cyan(script), cyan('> ' + script_cmd) ) host_info(info_text, remote=remote) # Run a custom script defined in the config. with hide('running'): run(script_cmd, remote) if needs_notification: notif.send(RUNNING_SCRIPT_FINISHED, { 'script': script, 'user': shell.get_user(), 'stage': shell.get_stage() })
def should_notify(script): ''' Check if the script being run should be notified. ''' notified_scripts = _get_config()['notified_hooks']['scripts'] if notified_scripts == 'all': return True if script in notified_scripts: return True return False
def get_script_cmd(script): ''' Return a script command if it does exist. ''' scripts = _get_config()['scripts'] return scripts.get(script)
def is_script_defined(script): ''' Check if the script is defined in the config. ''' custom_scripts = _get_config()['scripts'] return custom_scripts.has_key(script)