Пример #1
0
    def _downloader(self, url, rpath, fheaders, lfile, source, skip=False):
        """Download a specified object in the container.

        :param url:
        :param rpath:
        :param fheaders:
        :param lfile:
        :param skip:
        """

        resp = None

        if source is None:
            local_f = lfile
        else:
            local_f = basic.jpath(root=source, inode=lfile)

        if self._checker(url, rpath, local_f, fheaders, skip) is True:
            report.reporter(
                msg='Downloading remote %s to local file %s' % (rpath, lfile),
                prt=False,
                lvl='debug',
            )

            # Perform Object GET
            resp = http.get_request(url=url,
                                    rpath=rpath,
                                    headers=fheaders,
                                    stream=True)
            self.resp_exception(resp=resp)
            local_f = basic.collision_rename(file_name=local_f)

            # Open our source file and write it
            with open(local_f, 'wb') as f_name:
                for chunk in resp.iter_content(chunk_size=2048):
                    if chunk:
                        f_name.write(chunk)
                        f_name.flush()
            resp.close()

        if ARGS.get('restore_perms') is not None:
            # Make a connection
            if resp is None:
                resp = self._header_getter(url=url,
                                           rpath=rpath,
                                           fheaders=fheaders)

            all_headers = resp.headers

            if all([
                    'x-object-meta-group' in all_headers, 'x-object-meta-owner'
                    in all_headers, 'x-object-meta-perms' in all_headers
            ]):
                basic.restor_perms(local_file=local_f, headers=all_headers)
            else:
                report.reporter(
                    msg=('No Permissions were restored, because none were'
                         ' saved on the object "%s"' % rpath),
                    lvl='warn',
                    log=True)
Пример #2
0
    def _downloader(self, url, rpath, fheaders, lfile, source,
                    skip=False):
        """Download a specified object in the container.

        :param url:
        :param rpath:
        :param fheaders:
        :param lfile:
        :param skip:
        """

        resp = None

        if source is None:
            local_f = lfile
        else:
            local_f = basic.jpath(root=source, inode=lfile)

        if self._checker(url, rpath, local_f, fheaders, skip) is True:
            report.reporter(
                msg='Downloading remote %s to local file %s' % (rpath, lfile),
                prt=False,
                lvl='debug',
            )

            # Perform Object GET
            resp = http.get_request(
                url=url, rpath=rpath, headers=fheaders, stream=True
            )
            self.resp_exception(resp=resp)
            local_f = basic.collision_rename(file_name=local_f)

            # Open our source file and write it
            with open(local_f, 'wb') as f_name:
                for chunk in resp.iter_content(chunk_size=2048):
                    if chunk:
                        f_name.write(chunk)
                        f_name.flush()
            resp.close()

        if ARGS.get('restore_perms') is not None:
            # Make a connection
            if resp is None:
                resp = self._header_getter(
                    url=url, rpath=rpath, fheaders=fheaders
                )

            all_headers = resp.headers

            if all(['x-object-meta-group' in all_headers,
                    'x-object-meta-owner' in all_headers,
                    'x-object-meta-perms' in all_headers]):
                basic.restor_perms(local_file=local_f, headers=all_headers)
            else:
                report.reporter(
                    msg=('No Permissions were restored, because none were'
                         ' saved on the object "%s"' % rpath),
                    lvl='warn',
                    log=True
                )
Пример #3
0
    def _downloader(self,
                    conn,
                    rpath,
                    fheaders,
                    lfile,
                    source,
                    retry,
                    skip=False):
        """Download a specified object in the container.

        :param conn:
        :param rpath:
        :param fheaders:
        :param lfile:
        :param retry:
        :param skip:
        """

        if source is None:
            local_f = lfile
        else:
            local_f = basic.jpath(root=source, inode=lfile)

        if self._checker(conn, rpath, local_f, fheaders, retry, skip) is True:
            report.reporter(
                msg='Downloading remote %s to local file %s' % (rpath, lfile),
                prt=False,
                lvl='debug',
            )

            # Perform Object GET
            conn.request('GET', rpath, headers=fheaders)
            # Open our source file and write it
            with open(local_f, 'ab') as f_name:
                resp = http.response_get(conn=conn,
                                         retry=retry,
                                         resp_only=True)
                self.resp_exception(resp=resp, rty=retry)
                if resp is None:
                    report.reporter(msg='API Response Was NONE. resp was: %s' %
                                    resp.msg,
                                    prt=True,
                                    lvl='error',
                                    log=True)
                    retry()
                else:
                    while True:
                        chunk = resp.read(2048)
                        if not chunk:
                            break
                        else:
                            f_name.write(chunk)

            report.reporter(msg=('OBJECT %s MESSAGE %s %s %s' %
                                 (rpath, resp.status, resp.reason, resp.msg)),
                            prt=False,
                            lvl='debug')

        if ARGS.get('restore_perms') is not None:
            # Make a connection
            resp = self._header_getter(conn=conn,
                                       rpath=rpath,
                                       fheaders=fheaders,
                                       retry=retry)
            all_headers = dict(resp.getheaders())
            if all([
                    'x-object-meta-group' in all_headers, 'x-object-meta-owner'
                    in all_headers, 'x-object-meta-perms' in all_headers
            ]):
                basic.restor_perms(local_file=local_f, headers=all_headers)
            else:
                report.reporter(
                    msg=('No Permissions were restored, because none were'
                         ' saved on the object "%s"' % rpath),
                    lvl='warn',
                    log=True)
Пример #4
0
    def _downloader(self, conn, rpath, fheaders, lfile, source, retry,
                    skip=False):
        """Download a specified object in the container.

        :param conn:
        :param rpath:
        :param fheaders:
        :param lfile:
        :param retry:
        :param skip:
        """

        if source is None:
            local_f = lfile
        else:
            local_f = basic.jpath(root=source, inode=lfile)

        if self._checker(conn, rpath, local_f, fheaders, retry, skip) is True:
            report.reporter(
                msg='Downloading remote %s to local file %s' % (rpath, lfile),
                prt=False,
                lvl='debug',
            )

            # Perform Object GET
            conn.request('GET', rpath, headers=fheaders)
            local_f = basic.collision_rename(file_name=local_f)

            # Open our source file and write it
            with open(local_f, 'ab') as f_name:
                resp = http.response_get(conn=conn,
                                         retry=retry,
                                         resp_only=True)
                self.resp_exception(resp=resp, rty=retry)
                if resp is None:
                    report.reporter(
                        msg='API Response Was NONE. resp was: %s' % resp.msg,
                        prt=True,
                        lvl='error',
                        log=True
                    )
                    retry()
                else:
                    while True:
                        chunk = resp.read(2048)
                        if not chunk:
                            break
                        else:
                            f_name.write(chunk)

            report.reporter(
                msg=('OBJECT %s MESSAGE %s %s %s'
                     % (rpath, resp.status, resp.reason, resp.msg)),
                prt=False,
                lvl='debug'
            )

        if ARGS.get('restore_perms') is not None:
            # Make a connection
            resp = self._header_getter(conn=conn,
                                       rpath=rpath,
                                       fheaders=fheaders,
                                       retry=retry)
            all_headers = dict(resp.getheaders())
            if all(['x-object-meta-group' in all_headers,
                    'x-object-meta-owner' in all_headers,
                    'x-object-meta-perms' in all_headers]):
                basic.restor_perms(local_file=local_f, headers=all_headers)
            else:
                report.reporter(
                    msg=('No Permissions were restored, because none were'
                         ' saved on the object "%s"' % rpath),
                    lvl='warn',
                    log=True
                )