Exemplo n.º 1
0
def get(remote_path, local_path, use_sudo=False):
    use_sudo = parse_bool(use_sudo)

    if dconf.HOST_CONN == 'remote':
        res = _get(remote_path, local_path, use_sudo=use_sudo)
    elif dconf.HOST_CONN == 'local':
        pre_cmd = 'sudo ' if use_sudo else ''
        opts = '-r' if os.path.isdir(remote_path) else ''
        res = local('{}cp {} {} {}'.format(pre_cmd, opts, remote_path,
                                           local_path))
    else:  # docker or remote_docker
        docker_cmd = 'docker cp -L {}:{} {}'.format(dconf.CONTAINER_NAME,
                                                    remote_path, local_path)
        if dconf.HOST_CONN == 'docker':
            if dconf.DB_CONF_MOUNT is True:
                pre_cmd = 'sudo ' if use_sudo else ''
                opts = '-r' if os.path.isdir(remote_path) else ''
                res = local('{}cp {} {} {}'.format(pre_cmd, opts, remote_path,
                                                   local_path))
            else:
                res = local(docker_cmd)
        elif dconf.HOST_CONN == 'remote_docker':
            if dconf.DB_CONF_MOUNT is True:
                res = _get(remote_path, local_path, use_sudo=use_sudo)
            else:
                res = sudo(docker_cmd, remote_only=True)
                res = _get(local_path, local_path, use_sudo)
        else:
            raise Exception('wrong HOST_CONN type {}'.format(dconf.HOST_CONN))
    return res
Exemplo n.º 2
0
def get(remote_path, local_path, use_sudo=False):
    use_sudo = parse_bool(use_sudo)

    if dconf.HOST_CONN == 'remote':
        res = _get(remote_path, local_path, use_sudo=use_sudo)
    elif dconf.HOST_CONN == 'local':
        pre_cmd = 'sudo ' if use_sudo else ''
        opts = '-r' if os.path.isdir(remote_path) else ''
        res = local('{}cp {} {} {}'.format(pre_cmd, opts, remote_path,
                                           local_path))
    else:  # docker
        res = local('docker cp {}:{} {}'.format(dconf.CONTAINER_NAME,
                                                remote_path, local_path))
    return res
Exemplo n.º 3
0
    def __init__(self, fqfn, mode='r'):
        super(RemoteFile, self).__init__() # causes instantiation error?
        
        assert mode in ('r', 'w', 'a'), 'Invalid mode: %s' % mode
        
        self.mode = mode
            
        # Due to the singleton-nature of __new__, this may be called multiple times,
        # so we check for and avoid duplicate calls.
        if not hasattr(self, 'fqfn'):
            
            self.fqfn = fqfn
            self.content = ''
            self.fresh = True
            
            if mode in 'ra':
    
                _, tmp_fn = tempfile.mkstemp()
                os.remove(tmp_fn)
                ret = _get(remote_path=fqfn, local_path=tmp_fn, use_sudo=True)
                #ret = get_or_dryrun(remote_path=fqfn, local_path=tmp_fn, use_sudo=True)
#                 print('ret:', ret)
                _fn = ret[0]
#                 print('reading:', _fn)
                fin = open(_fn, 'rb')
#                 print('reading2:', _fn)
                self.content = fin.read()
#                 print('closing')
                fin.close()
                #print('removing:', tmp_fn)
                os.remove(tmp_fn)#TODO:memory leak?
#                 print('done init load')
                
            if mode in 'wa':
                
                # Update file system cache.
                _fs_cache['is_file'][fqfn] = True
Exemplo n.º 4
0
    def __init__(self, fqfn, mode='r'):
        super(RemoteFile, self).__init__()  # causes instantiation error?

        assert mode in ('r', 'w', 'a'), 'Invalid mode: %s' % mode

        self.mode = mode

        # Due to the singleton-nature of __new__, this may be called multiple times,
        # so we check for and avoid duplicate calls.
        if not hasattr(self, 'fqfn'):

            self.fqfn = fqfn
            self.content = ''
            self.fresh = True

            if mode in 'ra':

                _, tmp_fn = tempfile.mkstemp()
                os.remove(tmp_fn)
                ret = _get(remote_path=fqfn, local_path=tmp_fn, use_sudo=True)
                #ret = get_or_dryrun(remote_path=fqfn, local_path=tmp_fn, use_sudo=True)
                #                 print('ret:', ret)
                _fn = ret[0]
                #                 print('reading:', _fn)
                fin = open(_fn, 'rb')
                #                 print('reading2:', _fn)
                self.content = fin.read()
                #                 print('closing')
                fin.close()
                #print('removing:', tmp_fn)
                os.remove(tmp_fn)  #TODO:memory leak?
#                 print('done init load')

            if mode in 'wa':

                # Update file system cache.
                _fs_cache['is_file'][fqfn] = True