Пример #1
0
 def load_yaml(self, value):
     if isinstance(value, TemplateModule):
         value = six.text_type(value)
     try:
         return salt.utils.data.decode(salt.utils.yaml.safe_load(value))
     except salt.utils.yaml.YAMLError as exc:
         msg = "Encountered error loading yaml: "
         try:
             # Reported line is off by one, add 1 to correct it
             line = exc.problem_mark.line + 1
             buf = exc.problem_mark.buffer
             problem = exc.problem
         except AttributeError:
             # No context information available in the exception, fall back
             # to the stringified version of the exception.
             msg += six.text_type(exc)
         else:
             msg += "{0}\n".format(problem)
             msg += salt.utils.stringutils.get_context(
                 buf, line, marker="    <======================")
         raise TemplateRuntimeError(msg)
     except AttributeError:
         raise TemplateRuntimeError(
             "Unable to load yaml from {0}".format(value))
Пример #2
0
def _context_git_source(context, uri, rev='master'):
    """clone the given ref into the output_dir and return the rev"""
    if not utils._has_git():
        raise TemplateRuntimeError("Context function 'git_source' requires"
                                   " gitpython but it could not be imported")

    _context_check_variable(context, CONTEXT_VAR_PYPI_NAME, 'pypi_name')
    prj_name = context.vars[CONTEXT_VAR_PYPI_NAME]
    out_dir = context['output_dir']

    if out_dir:
        src_dir = os.path.join(out_dir, prj_name)
        sha = utils._git_repo(src_dir, uri, rev)

        tarname = '-'.join([prj_name, sha])
        utils._create_archive(tarname, 'gztar', out_dir, prj_name)

        return sha

    return rev
Пример #3
0
 def disable_op(arg):
     raise TemplateRuntimeError('that operator so does not work')
Пример #4
0
 def disable_op(left, right):
     raise TemplateRuntimeError('that operator so does not work')
Пример #5
0
 def _raise(self, msg, caller):
     raise TemplateRuntimeError(msg)
Пример #6
0
 def _raise(self, msg, caller):
     """Helper callback."""
     raise TemplateRuntimeError(msg)
Пример #7
0
 def _raise_error(self, message, caller):
     raise TemplateRuntimeError(message)
Пример #8
0
 def _raise_error(msg, caller):
     raise TemplateRuntimeError(msg)
Пример #9
0
def _context_check_variable(context, var_name, needed_by):
    """check that the context has a given variable"""
    if var_name not in context.vars:
        raise TemplateRuntimeError("Variable '%s' not available in context but"
                                   " needed for '%s'" % (var_name, needed_by))