Beispiel #1
0
    def exists(self, remote_path, use_sudo=False):
        """
        Return True if file exists on remote host, otherwise False

        This implementation is based on fabric.files: This function
        adds support for environment variables and expanding tilde
        """

        # NOTE: In case bash shows some output when opened, the files.exists
        # gets broken: In such case, show warning and take last line
        if len(remote_path.splitlines()) > 1:
            logger.warn(
                'Remote path is actually multiliner - taking the last row')
            remote_path = str(remote_path.splitlines()[-1]).strip()

        if '~' in remote_path:
            with api.settings(api.hide('stdout', 'running')):
                homepath = sudo('echo $HOME') if use_sudo else run(
                    'echo $HOME')
                remote_path = remote_path.replace('~', homepath)

        found = files.exists(remote_path, use_sudo=use_sudo)
        logger.debug('Checked if exists: %s = %s' % (remote_path, found))

        return found
Beispiel #2
0
    def __new__(cls):
        auth = AuthBackend()
        sudo_password_path = config.get('sudo_password_path')
        if sudo_password_path:
            logger.debug('Reading sudo from file: %s' % sudo_password_path)
            auth = PassFileAuthentication(sudo_password_path)

        return auth
Beispiel #3
0
 def _read_sudo_password(self, pwdfile):
     """
     Reads the sudo password from the specified location (expects the file contain nothing but password) and
     returns it back. If not found or password is empty, returns empty string
     """
     logger.debug('Using password file: %s' % pwdfile)
     with api.settings(api.hide('stdout', 'running')):
         pwd = api.run('cat %s' % pwdfile)
         return str(pwd.stdout).strip()
Beispiel #4
0
    def exists(self, remote_path, use_sudo=False):
        """
        Return True if file exists on remote host, otherwise False

        This implementation is based on fabric.files: This function
        adds support for environment variables and expanding tilde
        """

        # NOTE: In case bash shows some output when opened, the files.exists
        # gets broken: In such case, show warning and take last line
        if len(remote_path.splitlines()) > 1:
            logger.warn("Remote path is actually multiliner - taking the last row")
            remote_path = str(remote_path.splitlines()[-1]).strip()

        if "~" in remote_path:
            with api.settings(api.hide("stdout", "running")):
                homepath = sudo("echo $HOME") if use_sudo else run("echo $HOME")
                remote_path = remote_path.replace("~", homepath)

        found = files.exists(remote_path, use_sudo=use_sudo)
        logger.debug("Checked if exists: %s = %s" % (remote_path, found))

        return found