def test_update_from_resources_with_content(self): resources = [] for resource in self.cmpt.get_indexes(): resource["content"] = utils._read(resource["url"][len("file://") :]) resources.append(resource) self.cmpt.update_from_indexes(resources) self.assertEquals(len(self.cmpt.data["packages"]), 3)
def get_index_content(obj, **kw): """ Get the index content based on obj """ path = obj # NOTE: It's already a read content list if isinstance(obj, list): return obj elif isinstance(obj, dict): # NOTE: It's a resource with content inside... if 'content' in obj: return obj['content'] # NOTE: It's a resource with a path that should be read. elif 'path' in obj: path = obj['path'] # NOTE: It's just a path, read it return utils._read(path, **kw)
def download_resources(self, resources, progress_report, in_memory=False): # Only do one query for this implementation progress_report.query_finished_count = 0 progress_report.query_total_count = (len(resources)) progress_report.update_progress() for resource in resources: progress_report.current_query = resource['url'] path = resource['url'][len('file://'):] if not os.path.exists(path): # The caller will take care of stuffing this error into the # progress report raise FileNotFoundException(resource['url']) if in_memory: resource['content'] = utils._read(path, as_list=True) else: resource['path'] = resource['url'][len('file://'):] progress_report.query_finished_count += 1 progress_report.update_progress() return resources