Пример #1
0
def upload_template(filename, destination, context=None, **kwargs):
    kwargs['use_jinja'] = True
    kwargs['template_dir'] = os.path.join(
        os.path.dirname(os.path.realpath(__file__)), 'templates')
    kwargs['context'] = context
    kwargs['use_sudo'] = False
    kwargs['backup'] = False
    _upload_template(filename, destination, **kwargs)
Пример #2
0
def upload_template(filename, template, context=None, use_sudo=False, user="******", mkdir=False, chown=False):
    """
    Upload a template file.
    """
    if mkdir:
        d = os.path.dirname(filename)
        if use_sudo:
            sudo('mkdir -p "%s"' % d, user=user)
        else:
            run('mkdir -p "%s"' % d)
    _upload_template(os.path.join("templates", template), filename, context=context, use_sudo=use_sudo)
    if chown:
        run_as_root('chown %s:%s "%s"' % (user, user, filename))
Пример #3
0
    def upload_template(self,
                        filename,
                        destination,
                        context=None,
                        use_jinja=False,
                        template_dir=None,
                        use_sudo=False,
                        backup=True,
                        mirror_local_mode=False,
                        mode=None,
                        mkdir=False,
                        chown=False,
                        user=None):
        """
        Upload a template file.

        This is a wrapper around :func:`fabric.contrib.files.upload_template`
        that adds some extra parameters.

        If ``mkdir`` is True, then the remote directory will be created, as
        the current user or as ``user`` if specified.

        If ``chown`` is True, then it will ensure that the current user (or
        ``user`` if specified) is the owner of the remote file.
        """

        if mkdir:
            remote_dir = os.path.dirname(destination)
            if use_sudo:
                self.sudo('mkdir -p %s' % quote(remote_dir), user=user)
            else:
                self.run('mkdir -p %s' % quote(remote_dir))

        if not self.dryrun:
            _upload_template(
                filename=filename,
                destination=destination,
                context=context,
                use_jinja=use_jinja,
                template_dir=template_dir,
                use_sudo=use_sudo,
                backup=backup,
                mirror_local_mode=mirror_local_mode,
                mode=mode,
            )

        if chown:
            if user is None:
                user = self.genv.user
            run_as_root('chown %s: %s' % (user, quote(destination)))
Пример #4
0
def upload_template(
    filename,
    destination,
    context=None,
    use_jinja=False,
    template_dir=None,
    use_sudo=False,
    backup=True,
    mirror_local_mode=False,
    mode=None,
    mkdir=False,
    chown=False,
    user=None,
):
    """
    Upload a template file.

    This is a wrapper around :func:`fabric.contrib.files.upload_template`
    that adds some extra parameters.

    If ``mkdir`` is True, then the remote directory will be created, as
    the current user or as ``user`` if specified.

    If ``chown`` is True, then it will ensure that the current user (or
    ``user`` if specified) is the owner of the remote file.
    """

    if mkdir:
        remote_dir = os.path.dirname(destination)
        if use_sudo:
            sudo("mkdir -p %s" % quote(remote_dir), user=user)
        else:
            run("mkdir -p %s" % quote(remote_dir))

    _upload_template(
        filename=filename,
        destination=destination,
        context=context,
        use_jinja=use_jinja,
        template_dir=template_dir,
        use_sudo=use_sudo,
        backup=backup,
        mirror_local_mode=mirror_local_mode,
        mode=mode,
    )

    if chown:
        if user is None:
            user = env.user
        run_as_root("chown %s: %s" % (user, quote(destination)))
Пример #5
0
def upload_template(filename, template, context=None, use_sudo=False,
                  user="******", mkdir=False, chown=False):
    """
    Upload a template file.
    """
    if mkdir:
        d = os.path.dirname(filename)
        if use_sudo:
            sudo('mkdir -p "%s"' % d, user=user)
        else:
            run('mkdir -p "%s"' % d)
    _upload_template(os.path.join("templates", template), filename,
                    context=context, use_sudo=use_sudo)
    if chown:
        sudo('chown %s:%s "%s"' % (user, user, filename))
Пример #6
0
def upload_template(*args, **kwargs):
    """
    Wrapper around ``fabric.contrib.files.upload_template`` to change ownership after upload
    http://docs.fabfile.org/en/1.8/api/contrib/files.html

    additionnal parameters:
      user  : '******'
      group : 'root'
    """

    destination = args[1]
    user  = kwargs.pop('user', 'root')
    group = kwargs.pop('group', 'root')

    _upload_template(*args, **kwargs)
    with settings(hide('stdout')):
        run_as_root('chown %s:%s %s' % (user, group, destination))