Beispiel #1
0
    def render_file(self, fd):
        """render a file from a file descriptor. A file descriptor is a dict:

        .. code-block:: python

            {'src': path, 'dst': path}
        """
        src = fd['src']
        with codecs.open(src, 'r', 'utf8') as fd_:
            data = fd_.read()
        fd['data'] = data
        if 'executable' not in fd:
            fd['executable'] = utils.isexecutable(src)
Beispiel #2
0
    def render_template(self, fd):
        """render a template from a file descriptor:

        .. code-block:: python

            {'src': path, 'dst': path}
        """
        src = fd['src']
        ctx = dict(self.args, **self.args.get('ctx', {}))
        ctx.update(host=self.host, env=config, **fd)
        engine = config.get_template_engine()
        template = engine.get_template(src)
        fd['data'] = template.render(ctx)
        if 'executable' not in fd:
            fd['executable'] = utils.isexecutable(src)
Beispiel #3
0
    def render_file(self, fd):
        """render a file from a file descriptor. A file descriptor is a dict:

        .. code-block:: python

            {'src': path, 'dst': path}
        """
        src = fd['src']
        if src.endswith('.gpg'):
            _, data = gpg.decrypt(src, 'utf8')
        elif src.endswith(utils.ARCHIVE_EXTS):
            with open(
                    src,
                    'rb',
            ) as fd_:
                data = fd_.read()
                data = base64.b64encode(data).decode('utf8')
        else:
            with codecs.open(src, 'r', 'utf8') as fd_:
                data = fd_.read()
        fd['data'] = data
        if 'executable' not in fd:
            fd['executable'] = utils.isexecutable(src)