Esempio n. 1
0
    def check_manifest_integrity(self, req, resp):
        headers = resp.headers

        rmtime = headers.get('x-amz-meta-mtime', None)

        if rmtime is None:
            rmtime = headers.get('last-modified', None)
            if rmtime is not None:
                rmtime = net.http_date_to_timestamp(rmtime)

        if rmtime is not None:
            try:
                rmtime = int(rmtime)
            except (TypeError, ValueError):
                rmtime = None

        prog_dir = util.program_dir()
        self.local_manifest_path = path.path(prog_dir) / path.path(self.remote_manifest_path).splitpath()[-1]

        needs_update = True

        if self.local_manifest_path.isfile():
            lmtime = int(self.local_manifest_path.mtime)
        else:
            lmtime = 0

        if sys.opts.force_update or lmtime != rmtime:
            log.info("MTime mismatch or sys.opts.force_update is True. Downloading manifest. (local=%r, remote=%r)", lmtime, rmtime)
            downloader.httpopen(self.remote_manifest_path, success = self.got_manifest_response, error = self.manifest_request_error)
        else:
            log.info("Local MTime matches remote. Not downloading manifest. (local=%r, remote=%r)", lmtime, rmtime)
            self.update_check_complete(False, None)
Esempio n. 2
0
    def check_manifest_integrity(self, req, resp):
        headers = resp.headers

        rmtime = headers.get('x-amz-meta-mtime', None)

        if rmtime is None:
            rmtime = headers.get('last-modified', None)
            if rmtime is not None:
                rmtime = net.http_date_to_timestamp(rmtime)

        if rmtime is not None:
            try:
                rmtime = int(rmtime)
            except (TypeError, ValueError):
                rmtime = None

        prog_dir = util.program_dir()
        self.local_manifest_path = path.path(prog_dir) / path.path(
            self.remote_manifest_path).splitpath()[-1]

        needs_update = True

        if self.local_manifest_path.isfile():
            lmtime = int(self.local_manifest_path.mtime)
        else:
            lmtime = 0

        if sys.opts.force_update or lmtime != rmtime:
            log.info(
                "MTime mismatch or sys.opts.force_update is True. Downloading manifest. (local=%r, remote=%r)",
                lmtime, rmtime)
            downloader.httpopen(self.remote_manifest_path,
                                success=self.got_manifest_response,
                                error=self.manifest_request_error)
        else:
            log.info(
                "Local MTime matches remote. Not downloading manifest. (local=%r, remote=%r)",
                lmtime, rmtime)
            self.update_check_complete(False, None)
Esempio n. 3
0
    def preprocess_resp_default(self, name, resp, **req_options):
        code = resp.code

        server_time = net.http_date_to_timestamp(resp.headers.get('Date', None))
        if server_time is not None:
            time_diff = int(time.time() - server_time)
            self._server_time_offset = time_diff
            log.info("Got server time offset: %r", time_diff)

        if self._server_time_offset is None:
            log.error("Server does not report Date header.")

        log.info('response for %r: code = %r, headers = %r', name, code, str(resp.headers))
        log.debug_s('\tcontent: %s', repr(resp.content)[:5000])
        document = load_document(resp, expected = req_options.get('format'))

        if code not in (200, 201, 204, 401):
            # check for oauth error, parse it out and raise as an exception
            raise Exception(document)

        resp.document = document
        return resp
Esempio n. 4
0
    def _create_filemeta_from_http(self, resp, callback):
        headers = resp.headers

        rmtime = headers.get('x-amz-meta-mtime', None)

        if rmtime is None:
            rmtime = headers.get('last-modified', None)
            if rmtime is not None:
                rmtime = net.http_date_to_timestamp(rmtime)

        if rmtime is not None:
            try:
                rmtime = int(rmtime)
            except (TypeError, ValueError):
                rmtime = None


        import digsby_updater.file_integrity as file_integrity
        mtime = file_integrity.MTime()
        mtime._val = rmtime or 0
        hashes = dict(mtime = mtime.hexdigest())

        self.meta = file_integrity.FileMeta(self.content_location.name, hashes = hashes)
        callback.success(self.meta)
Esempio n. 5
0
    def preprocess_resp_default(self, name, resp, **req_options):
        code = resp.code

        server_time = net.http_date_to_timestamp(resp.headers.get(
            'Date', None))
        if server_time is not None:
            time_diff = int(time.time() - server_time)
            self._server_time_offset = time_diff
            log.info("Got server time offset: %r", time_diff)

        if self._server_time_offset is None:
            log.error("Server does not report Date header.")

        log.info('response for %r: code = %r, headers = %r', name, code,
                 str(resp.headers))
        log.debug_s('\tcontent: %s', repr(resp.content)[:5000])
        document = load_document(resp, expected=req_options.get('format'))

        if code not in (200, 201, 204, 401):
            # check for oauth error, parse it out and raise as an exception
            raise Exception(document)

        resp.document = document
        return resp