Example #1
0
def runExternalScriptWithTimeout(script, allow_insecure=False,\
        script_args=(), timeout=30):
    """Run a script (e.g. preflight/postflight) and return its exit status.

    Args:
      script: string path to the script to execute.
      allow_insecure: bool skip the permissions check of executable.
      args: args to pass to the script.
    Returns:
      Tuple. (integer exit status from script, str stdout, str stderr).
    Raises:
      ScriptNotFoundError: the script was not found at the given path.
      RunExternalScriptError: there was an error running the script.
    """
    from munkilib import utils

    if not os.path.exists(script):
        raise ScriptNotFoundError('script does not exist: %s' % script)

    if not allow_insecure:
        try:
            utils.verifyFileOnlyWritableByMunkiAndRoot(script)
        except utils.VerifyFilePermissionsError, e:
            msg = ('Skipping execution due to failed file permissions '
                   'verification: %s\n%s' % (script, str(e)))
            raise utils.RunExternalScriptError(msg)
Example #2
0
def runExternalScriptWithTimeout(script, allow_insecure=False,\
        script_args=(), timeout=10):
    """Run a script (e.g. preflight/postflight) and return its exit status.

    Args:
      script: string path to the script to execute.
      allow_insecure: bool skip the permissions check of executable.
      args: args to pass to the script.
    Returns:
      Tuple. (integer exit status from script, str stdout, str stderr).
    Raises:
      ScriptNotFoundError: the script was not found at the given path.
      RunExternalScriptError: there was an error running the script.
    """
    from munkilib import utils

    if not os.path.exists(script):
        raise ScriptNotFoundError('script does not exist: %s' % script)

    if not allow_insecure:
        try:
            utils.verifyFileOnlyWritableByMunkiAndRoot(script)
        except utils.VerifyFilePermissionsError, e:
            msg = ('Skipping execution due to failed file permissions '
                   'verification: %s\n%s' % (script, str(e)))
            raise utils.RunExternalScriptError(msg)