diff --git a/swh/indexer/ctags.py b/swh/indexer/ctags.py --- a/swh/indexer/ctags.py +++ b/swh/indexer/ctags.py @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2017 The Software Heritage developers +# Copyright (C) 2015-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -6,6 +6,8 @@ import subprocess import json +from typing import Dict, List + from swh.model import hashutil from .indexer import ContentIndexer, write_to_temp @@ -135,17 +137,18 @@ return ctags - def persist_index_computations(self, results, policy_update): + def persist_index_computations( + self, results: List[Dict], policy_update: str) -> Dict: """Persist the results in storage. Args: - results ([dict]): list of content_mimetype, dict with the + results: list of content_mimetype, dict with the following keys: - id (bytes): content's identifier (sha1) - ctags ([dict]): ctags list of symbols - policy_update ([str]): either 'update-dups' or 'ignore-dups' to + policy_update: either 'update-dups' or 'ignore-dups' to respectively update duplicates or ignore them """ - self.idx_storage.content_ctags_add( + return self.idx_storage.content_ctags_add( results, conflict_update=(policy_update == 'update-dups')) diff --git a/swh/indexer/fossology_license.py b/swh/indexer/fossology_license.py --- a/swh/indexer/fossology_license.py +++ b/swh/indexer/fossology_license.py @@ -1,17 +1,21 @@ -# Copyright (C) 2016-2018 The Software Heritage developers +# Copyright (C) 2016-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +import logging import subprocess -from typing import Optional +from typing import Any, Dict, List, Optional from swh.model import hashutil from .indexer import ContentIndexer, ContentRangeIndexer, write_to_temp -def compute_license(path, log=None): +logger = logging.getLogger(__name__) + + +def compute_license(path): """Determine license from file at path. Args: @@ -38,10 +42,9 @@ 'path': path, } except subprocess.CalledProcessError: - if log: - from os import path as __path - log.exception('Problem during license detection for sha1 %s' % - __path.basename(path)) + from os import path as __path + logger.exception('Problem during license detection for sha1 %s' % + __path.basename(path)) return { 'licenses': [], 'path': path, @@ -68,12 +71,15 @@ } CONFIG_BASE_FILENAME = 'indexer/fossology_license' # type: Optional[str] + tool: Any + idx_storage: Any def prepare(self): super().prepare() self.working_directory = self.config['workdir'] - def index(self, id, data): + def index(self, id: bytes, data: Optional[bytes] = None, + **kwargs) -> Dict[str, Any]: """Index sha1s' content and store result. Args: @@ -90,33 +96,35 @@ """ assert isinstance(id, bytes) + assert data is not None with write_to_temp( filename=hashutil.hash_to_hex(id), # use the id as pathname data=data, working_directory=self.working_directory) as content_path: - properties = compute_license(path=content_path, log=self.log) + properties = compute_license(path=content_path) properties.update({ 'id': id, 'indexer_configuration_id': self.tool['id'], }) return properties - def persist_index_computations(self, results, policy_update): + def persist_index_computations( + self, results: List[Dict], policy_update: str) -> Dict: """Persist the results in storage. Args: - results ([dict]): list of content_license, dict with the + results: list of content_license dict with the following keys: - id (bytes): content's identifier (sha1) - license (bytes): license in bytes - path (bytes): path - policy_update ([str]): either 'update-dups' or 'ignore-dups' to + policy_update: either 'update-dups' or 'ignore-dups' to respectively update duplicates or ignore them """ - self.idx_storage.content_fossology_license_add( + return self.idx_storage.content_fossology_license_add( results, conflict_update=(policy_update == 'update-dups')) diff --git a/swh/indexer/indexer.py b/swh/indexer/indexer.py --- a/swh/indexer/indexer.py +++ b/swh/indexer/indexer.py @@ -10,8 +10,9 @@ import tempfile from contextlib import contextmanager -from typing import Any, Dict, Tuple, Generator, Union, List -from typing import Set +from typing import ( + Any, Dict, Iterator, List, Optional, Set, Tuple, Union +) from swh.scheduler import CONFIG as SWH_CONFIG @@ -26,8 +27,7 @@ @contextmanager def write_to_temp( - filename: str, data: bytes, working_directory: str -) -> Generator[str, None, None]: + filename: str, data: bytes, working_directory: str) -> Iterator[str]: """Write the sha1's content in a temporary file. Args: @@ -238,9 +238,8 @@ else: return [] - def index( - self, id: bytes, data: bytes - ) -> Dict[str, Any]: + def index(self, id: bytes, data: Optional[bytes] = None, + **kwargs) -> Dict[str, Any]: """Index computation for the id and associated raw data. Args: @@ -255,7 +254,7 @@ """ raise NotImplementedError() - def filter(self, ids: List[bytes]) -> Generator[bytes, None, None]: + def filter(self, ids: List[bytes]) -> Iterator[bytes]: """Filter missing ids for that particular indexer. Args: @@ -268,7 +267,7 @@ yield from ids @abc.abstractmethod - def persist_index_computations(self, results, policy_update): + def persist_index_computations(self, results, policy_update) -> Dict: """Persist the computation resulting from the index. Args: @@ -279,27 +278,10 @@ respectively update duplicates or ignore them Returns: - None + a summary dict of what has been inserted in the storage """ - pass - - @abc.abstractmethod - def run(self, ids, policy_update, **kwargs): - """Given a list of ids: - - - retrieves the data from the storage - - executes the indexing computations - - stores the results (according to policy_update) - - Args: - ids ([bytes]): id's identifier list - policy_update (str): either 'update-dups' or 'ignore-dups' to - respectively update duplicates or ignore them - **kwargs: passed to the `index` method - - """ - pass + return {} class ContentIndexer(BaseIndexer): @@ -313,8 +295,8 @@ methods mentioned in the :class:`BaseIndexer` class. """ - - def run(self, ids, policy_update, **kwargs): + def run(self, ids: Union[List[bytes], bytes, str], policy_update: str, + **kwargs) -> Dict: """Given a list of ids: - retrieve the content from the storage @@ -328,12 +310,17 @@ them **kwargs: passed to the `index` method + Returns: + A summary Dict of the task's status + """ - ids = [hashutil.hash_to_bytes(id_) if isinstance(id_, str) else id_ - for id_ in ids] + status = 'uneventful' + sha1s = [hashutil.hash_to_bytes(id_) if isinstance(id_, str) else id_ + for id_ in ids] results = [] + summary: Dict = {} try: - for sha1 in ids: + for sha1 in sha1s: try: raw_content = self.objstorage.get(sha1) except ObjNotFoundError: @@ -343,14 +330,18 @@ res = self.index(sha1, raw_content, **kwargs) if res: # If no results, skip it results.append(res) - - self.persist_index_computations(results, policy_update) + status = 'eventful' + summary = self.persist_index_computations(results, policy_update) self.results = results except Exception: if not self.catch_exceptions: raise self.log.exception( 'Problem when reading contents metadata.') + status = 'failed' + finally: + summary['status'] = status + return summary class ContentRangeIndexer(BaseIndexer): @@ -383,7 +374,7 @@ def _list_contents_to_index( self, start: bytes, end: bytes, indexed: Set[bytes] - ) -> Generator[bytes, None, None]: + ) -> Iterator[bytes]: """Compute from storage the new contents to index in the range [start, end]. The already indexed contents are skipped. @@ -411,7 +402,7 @@ def _index_contents( self, start: bytes, end: bytes, indexed: Set[bytes], **kwargs: Any - ) -> Generator[Dict, None, None]: + ) -> Iterator[Dict]: """Index the contents from within range [start, end] Args: @@ -430,7 +421,7 @@ self.log.warning('Content %s not found in objstorage' % hashutil.hash_to_hex(sha1)) continue - res = self.index(sha1, raw_content, **kwargs) # type: ignore + res = self.index(sha1, raw_content, **kwargs) if res: if not isinstance(res['id'], bytes): raise TypeError( @@ -439,8 +430,7 @@ yield res def _index_with_skipping_already_done( - self, start: bytes, end: bytes - ) -> Generator[Dict, None, None]: + self, start: bytes, end: bytes) -> Iterator[Dict]: """Index not already indexed contents in range [start, end]. Args: @@ -460,47 +450,55 @@ start, _end, contents) start = indexed_page['next'] - def run(self, start, end, skip_existing=True, **kwargs): + def run(self, start: Union[bytes, str], end: Union[bytes, str], + skip_existing: bool = True, **kwargs) -> Dict: """Given a range of content ids, compute the indexing computations on the contents within. Either the indexer is incremental (filter out existing computed data) or not (compute everything from scratch). Args: - start (Union[bytes, str]): Starting range identifier - end (Union[bytes, str]): Ending range identifier - skip_existing (bool): Skip existing indexed data + start: Starting range identifier + end: Ending range identifier + skip_existing: Skip existing indexed data (default) or not **kwargs: passed to the `index` method Returns: - bool: True if data was indexed, False otherwise. + A dict with the task's status """ - with_indexed_data = False + status = 'uneventful' + summary: Dict = {} try: - if isinstance(start, str): - start = hashutil.hash_to_bytes(start) - if isinstance(end, str): - end = hashutil.hash_to_bytes(end) + range_start = hashutil.hash_to_bytes(start) \ + if isinstance(start, str) else start + range_end = hashutil.hash_to_bytes(end) \ + if isinstance(end, str) else end if skip_existing: - gen = self._index_with_skipping_already_done(start, end) + gen = self._index_with_skipping_already_done( + range_start, range_end) else: - gen = self._index_contents(start, end, indexed=[]) - - for results in utils.grouper(gen, - n=self.config['write_batch_size']): - self.persist_index_computations( - results, policy_update='update-dups') - with_indexed_data = True + gen = self._index_contents( + range_start, range_end, indexed=set([])) + + for contents in utils.grouper( + gen, n=self.config['write_batch_size']): + res = self.persist_index_computations( + contents, policy_update='update-dups') + summary['content_mimetype:add'] += res.get( + 'content_mimetype:add') + status = 'eventful' except Exception: if not self.catch_exceptions: raise self.log.exception( 'Problem when computing metadata.') + status = 'failed' finally: - return with_indexed_data + summary['status'] = status + return summary class OriginIndexer(BaseIndexer): @@ -513,8 +511,8 @@ class. """ - def run(self, origin_urls, policy_update='update-dups', - next_step=None, **kwargs): + def run(self, origin_urls: List[str], + policy_update: str = 'update-dups', **kwargs) -> Dict: """Given a list of origin urls: - retrieve origins from storage @@ -522,17 +520,16 @@ - store the results (according to policy_update) Args: - origin_urls ([str]): list of origin urls. - policy_update (str): either 'update-dups' or 'ignore-dups' to + origin_urls: list of origin urls. + policy_update: either 'update-dups' or 'ignore-dups' to respectively update duplicates (default) or ignore them - parse_ids (bool): Do we need to parse id or not (default) **kwargs: passed to the `index` method """ results = self.index_list(origin_urls, **kwargs) - - self.persist_index_computations(results, policy_update) + summary = self.persist_index_computations(results, policy_update) self.results = results + return summary def index_list(self, origins: List[Any], **kwargs: Any) -> List[Dict]: results = [] @@ -560,7 +557,7 @@ class. """ - def run(self, ids, policy_update): + def run(self, ids: Union[str, bytes], policy_update: str) -> Dict: """Given a list of sha1_gits: - retrieve revisions from storage @@ -568,15 +565,15 @@ - store the results (according to policy_update) Args: - ids ([bytes or str]): sha1_git's identifier list - policy_update (str): either 'update-dups' or 'ignore-dups' to + ids: sha1_git's identifier list + policy_update: either 'update-dups' or 'ignore-dups' to respectively update duplicates or ignore them """ results = [] - ids = [hashutil.hash_to_bytes(id_) if isinstance(id_, str) else id_ - for id_ in ids] - revs = self.storage.revision_get(ids) + revs = self.storage.revision_get( + hashutil.hash_to_bytes(id_) if isinstance(id_, str) else id_ + for id_ in ids) for rev in revs: if not rev: @@ -592,5 +589,6 @@ raise self.log.exception( 'Problem when processing revision') - self.persist_index_computations(results, policy_update) + summary = self.persist_index_computations(results, policy_update) self.results = results + return summary diff --git a/swh/indexer/metadata.py b/swh/indexer/metadata.py --- a/swh/indexer/metadata.py +++ b/swh/indexer/metadata.py @@ -5,7 +5,7 @@ from copy import deepcopy -from typing import Any, List, Dict, Tuple, Callable, Generator +from typing import Any, Callable, Dict, Iterator, List, Tuple from swh.core.utils import grouper @@ -26,7 +26,7 @@ def call_with_batches( f: Callable[[List[Dict[str, Any]]], Dict['str', Any]], args: List[Dict[str, str]], batch_size: int -) -> Generator[str, None, None]: +) -> Iterator[str]: """Calls a function with batches of args, and concatenates the results. """ groups = grouper(args, batch_size) @@ -89,7 +89,7 @@ def persist_index_computations( self, results: List[Dict], policy_update: str - ) -> None: + ) -> Dict: """Persist the results in storage. Args: @@ -101,7 +101,7 @@ respectively update duplicates or ignore them """ - self.idx_storage.content_metadata_add( + return self.idx_storage.content_metadata_add( results, conflict_update=(policy_update == 'update-dups')) @@ -188,7 +188,7 @@ def persist_index_computations( self, results: List[Dict], policy_update: str - ) -> None: + ) -> Dict: """Persist the results in storage. Args: @@ -203,7 +203,7 @@ """ # TODO: add functions in storage to keep data in # revision_intrinsic_metadata - self.idx_storage.revision_intrinsic_metadata_add( + return self.idx_storage.revision_intrinsic_metadata_add( results, conflict_update=(policy_update == 'update-dups')) def translate_revision_intrinsic_metadata( @@ -327,7 +327,7 @@ def persist_index_computations( self, results: List[Dict], policy_update: str - ) -> None: + ) -> Dict: conflict_update = (policy_update == 'update-dups') # Deduplicate revisions @@ -335,6 +335,7 @@ orig_metadata: List[Any] = [] revs_to_delete: List[Any] = [] origs_to_delete: List[Any] = [] + summary: Dict = {} for (orig_item, rev_item) in results: assert rev_item['metadata'] == orig_item['metadata'] if not rev_item['metadata'] or \ @@ -352,17 +353,25 @@ orig_metadata.append(orig_item) if rev_metadata: - self.idx_storage.revision_intrinsic_metadata_add( + summary_rev = self.idx_storage.revision_intrinsic_metadata_add( rev_metadata, conflict_update=conflict_update) + summary.update(summary_rev) if orig_metadata: - self.idx_storage.origin_intrinsic_metadata_add( + summary_ori = self.idx_storage.origin_intrinsic_metadata_add( orig_metadata, conflict_update=conflict_update) + summary.update(summary_ori) # revs_to_delete should always be empty unless we changed a mapping # to detect less files or less content. # However, origs_to_delete may be empty whenever an upstream deletes # a metadata file. if origs_to_delete: - self.idx_storage.origin_intrinsic_metadata_delete(origs_to_delete) + summary_ori = self.idx_storage.origin_intrinsic_metadata_delete( + origs_to_delete) + summary.update(summary_ori) if revs_to_delete: - self.idx_storage.revision_intrinsic_metadata_delete(revs_to_delete) + summary_rev = self.idx_storage.revision_intrinsic_metadata_delete( + revs_to_delete) + summary.update(summary_ori) + + return summary diff --git a/swh/indexer/mimetype.py b/swh/indexer/mimetype.py --- a/swh/indexer/mimetype.py +++ b/swh/indexer/mimetype.py @@ -55,7 +55,8 @@ CONFIG_BASE_FILENAME = 'indexer/mimetype' # type: Optional[str] - def index(self, id: bytes, data: bytes) -> Dict[str, Any]: + def index(self, id: bytes, data: Optional[bytes] = None, + **kwargs) -> Dict[str, Any]: """Index sha1s' content and store result. Args: @@ -70,6 +71,7 @@ - encoding: encoding in bytes """ + assert data is not None properties = compute_mimetype_encoding(data) properties.update({ 'id': id, @@ -78,8 +80,8 @@ return properties def persist_index_computations( - self, results: List[Dict], policy_update: List[str] - ) -> None: + self, results: List[Dict], policy_update: str + ) -> Dict: """Persist the results in storage. Args: @@ -90,7 +92,7 @@ respectively update duplicates or ignore them """ - self.idx_storage.content_mimetype_add( + return self.idx_storage.content_mimetype_add( results, conflict_update=(policy_update == 'update-dups')) diff --git a/swh/indexer/origin_head.py b/swh/indexer/origin_head.py --- a/swh/indexer/origin_head.py +++ b/swh/indexer/origin_head.py @@ -24,10 +24,10 @@ def persist_index_computations( self, results: Any, policy_update: str - ) -> None: + ) -> Dict: """Do nothing. The indexer's results are not persistent, they should only be piped to another indexer.""" - pass + return {} # Dispatch diff --git a/swh/indexer/rehash.py b/swh/indexer/rehash.py --- a/swh/indexer/rehash.py +++ b/swh/indexer/rehash.py @@ -145,19 +145,25 @@ content.update(content_hashes) yield content, checksums_to_compute - def run(self, contents: List[Dict[str, Any]]) -> None: + def run(self, contents: List[Dict[str, Any]]) -> Dict: """Given a list of content: - (re)compute a given set of checksums on contents available in our object storage - update those contents with the new metadata - Args: - contents: contents as dictionary with necessary keys. - key present in such dictionary should be the ones defined in - the 'primary_key' option. + Args: + contents: contents as dictionary with necessary keys. + key present in such dictionary should be the ones defined in + the 'primary_key' option. + + Returns: + A summary dict with key 'status', task' status and 'count' the + number of updated contents. """ + status = 'uneventful' + count = 0 for data in utils.grouper( self.get_new_contents_metadata(contents), self.batch_size_update): @@ -172,6 +178,13 @@ try: self.storage.content_update(contents, keys=keys) + count += len(contents) + status = 'eventful' except Exception: self.log.exception('Problem during update.') continue + + return { + 'status': status, + 'count': count, + } diff --git a/swh/indexer/storage/__init__.py b/swh/indexer/storage/__init__.py --- a/swh/indexer/storage/__init__.py +++ b/swh/indexer/storage/__init__.py @@ -172,7 +172,7 @@ @db_transaction() def content_mimetype_add( self, mimetypes: List[Dict], conflict_update: bool = False, - db=None, cur=None) -> Dict: + db=None, cur=None) -> Dict[str, int]: """Add mimetypes to the storage (if conflict_update is True, this will override existing data if any). @@ -214,8 +214,8 @@ @process_metrics @db_transaction() def content_language_add( - self, languages: List[Dict], - conflict_update: bool = False, db=None, cur=None) -> Dict: + self, languages: List[Dict], conflict_update: bool = False, + db=None, cur=None) -> Dict[str, int]: check_id_duplicates(languages) languages.sort(key=lambda m: m['id']) db.mktemp_content_language(cur) @@ -251,7 +251,7 @@ @db_transaction() def content_ctags_add( self, ctags: List[Dict], conflict_update: bool = False, - db=None, cur=None) -> Dict: + db=None, cur=None) -> Dict[str, int]: check_id_duplicates(ctags) ctags.sort(key=lambda m: m['id']) @@ -300,7 +300,7 @@ @db_transaction() def content_fossology_license_add( self, licenses: List[Dict], conflict_update: bool = False, - db=None, cur=None) -> Dict: + db=None, cur=None) -> Dict[str, int]: check_id_duplicates(licenses) licenses.sort(key=lambda m: m['id']) db.mktemp_content_fossology_license(cur) @@ -346,7 +346,7 @@ @db_transaction() def content_metadata_add( self, metadata: List[Dict], conflict_update: bool = False, - db=None, cur=None) -> Dict: + db=None, cur=None) -> Dict[str, int]: check_id_duplicates(metadata) metadata.sort(key=lambda m: m['id']) @@ -379,7 +379,7 @@ @db_transaction() def revision_intrinsic_metadata_add( self, metadata: List[Dict], conflict_update: bool = False, - db=None, cur=None) -> Dict: + db=None, cur=None) -> Dict[str, int]: check_id_duplicates(metadata) metadata.sort(key=lambda m: m['id']) @@ -418,7 +418,7 @@ @db_transaction() def origin_intrinsic_metadata_add( self, metadata: List[Dict], conflict_update: bool = False, - db=None, cur=None) -> Dict: + db=None, cur=None) -> Dict[str, int]: check_id_duplicates(metadata) metadata.sort(key=lambda m: m['id']) diff --git a/swh/indexer/storage/in_memory.py b/swh/indexer/storage/in_memory.py --- a/swh/indexer/storage/in_memory.py +++ b/swh/indexer/storage/in_memory.py @@ -230,7 +230,7 @@ def content_mimetype_add( self, mimetypes: List[Dict], - conflict_update: bool = False) -> Dict: + conflict_update: bool = False) -> Dict[str, int]: check_id_types(mimetypes) added = self._mimetypes.add(mimetypes, conflict_update) return {'content_mimetype:add': added} @@ -246,7 +246,7 @@ def content_language_add( self, languages: List[Dict], - conflict_update: bool = False) -> Dict: + conflict_update: bool = False) -> Dict[str, int]: check_id_types(languages) added = self._languages.add(languages, conflict_update) return {'content_language:add': added} @@ -264,7 +264,8 @@ } def content_ctags_add( - self, ctags: List[Dict], conflict_update: bool = False) -> Dict: + self, ctags: List[Dict], + conflict_update: bool = False) -> Dict[str, int]: check_id_types(ctags) added = self._content_ctags.add_merge(ctags, conflict_update, 'ctags') return {'content_ctags:add': added} @@ -300,7 +301,8 @@ yield {id_: facts} def content_fossology_license_add( - self, licenses: List[Dict], conflict_update: bool = False) -> Dict: + self, licenses: List[Dict], + conflict_update: bool = False) -> Dict[str, int]: check_id_types(licenses) added = self._licenses.add_merge(licenses, conflict_update, 'licenses') return {'fossology_license_add:add': added} @@ -317,7 +319,8 @@ yield from self._content_metadata.get(ids) def content_metadata_add( - self, metadata: List[Dict], conflict_update: bool = False) -> Dict: + self, metadata: List[Dict], + conflict_update: bool = False) -> Dict[str, int]: check_id_types(metadata) added = self._content_metadata.add(metadata, conflict_update) return {'content_metadata:add': added} @@ -329,7 +332,8 @@ yield from self._revision_intrinsic_metadata.get(ids) def revision_intrinsic_metadata_add( - self, metadata: List[Dict], conflict_update: bool = False) -> Dict: + self, metadata: List[Dict], + conflict_update: bool = False) -> Dict[str, int]: check_id_types(metadata) added = self._revision_intrinsic_metadata.add( metadata, conflict_update) @@ -343,7 +347,8 @@ yield from self._origin_intrinsic_metadata.get(ids) def origin_intrinsic_metadata_add( - self, metadata: List[Dict], conflict_update: bool = False) -> Dict: + self, metadata: List[Dict], + conflict_update: bool = False) -> Dict[str, int]: added = self._origin_intrinsic_metadata.add(metadata, conflict_update) return {'origin_intrinsic_metadata:add': added} diff --git a/swh/indexer/storage/interface.py b/swh/indexer/storage/interface.py --- a/swh/indexer/storage/interface.py +++ b/swh/indexer/storage/interface.py @@ -91,7 +91,7 @@ @remote_api_endpoint('content_mimetype/add') def content_mimetype_add(self, mimetypes: List[Dict], - conflict_update: bool = False) -> Dict: + conflict_update: bool = False) -> Dict[str, int]: """Add mimetypes not present in storage. Args: @@ -168,7 +168,7 @@ @remote_api_endpoint('content_language/add') def content_language_add( self, languages: List[Dict], - conflict_update: bool = False) -> Dict: + conflict_update: bool = False) -> Dict[str, int]: """Add languages not present in storage. Args: @@ -227,7 +227,7 @@ @remote_api_endpoint('content/ctags/add') def content_ctags_add(self, ctags: List[Dict], - conflict_update: bool = False) -> Dict: + conflict_update: bool = False) -> Dict[str, int]: """Add ctags not present in storage Args: @@ -278,7 +278,8 @@ @remote_api_endpoint('content/fossology_license/add') def content_fossology_license_add( - self, licenses: List[Dict], conflict_update: bool = False) -> Dict: + self, licenses: List[Dict], + conflict_update: bool = False) -> Dict[str, int]: """Add licenses not present in storage. Args: @@ -359,7 +360,8 @@ @remote_api_endpoint('content_metadata/add') def content_metadata_add( - self, metadata: List[Dict], conflict_update: bool = False) -> Dict: + self, metadata: List[Dict], + conflict_update: bool = False) -> Dict[str, int]: """Add metadata not present in storage. Args: @@ -415,7 +417,8 @@ @remote_api_endpoint('revision_intrinsic_metadata/add') def revision_intrinsic_metadata_add( - self, metadata: List[Dict], conflict_update: bool = False) -> Dict: + self, metadata: List[Dict], + conflict_update: bool = False) -> Dict[str, int]: """Add metadata not present in storage. Args: @@ -475,7 +478,8 @@ @remote_api_endpoint('origin_intrinsic_metadata/add') def origin_intrinsic_metadata_add( - self, metadata: List[Dict], conflict_update: bool = False) -> Dict: + self, metadata: List[Dict], + conflict_update: bool = False) -> Dict[str, int]: """Add origin metadata not present in storage. Args: diff --git a/swh/indexer/tasks.py b/swh/indexer/tasks.py --- a/swh/indexer/tasks.py +++ b/swh/indexer/tasks.py @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2019 The Software Heritage developers +# Copyright (C) 2016-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -17,41 +17,34 @@ @app.task(name=__name__ + '.OriginMetadata') def origin_metadata(*args, **kwargs): - results = OriginMetadataIndexer().run(*args, **kwargs) - return getattr(results, 'results', results) + return OriginMetadataIndexer().run(*args, **kwargs) @app.task(name=__name__ + '.Ctags') def ctags(*args, **kwargs): - results = CtagsIndexer().run(*args, **kwargs) - return getattr(results, 'results', results) + return CtagsIndexer().run(*args, **kwargs) @app.task(name=__name__ + '.ContentFossologyLicense') def fossology_license(*args, **kwargs): - results = FossologyLicenseIndexer().run(*args, **kwargs) - return getattr(results, 'results', results) + return FossologyLicenseIndexer().run(*args, **kwargs) @app.task(name=__name__ + '.RecomputeChecksums') def recompute_checksums(*args, **kwargs): - results = RecomputeChecksums().run(*args, **kwargs) - return getattr(results, 'results', results) + return RecomputeChecksums().run(*args, **kwargs) @app.task(name=__name__ + '.ContentMimetype') def mimetype(*args, **kwargs): - results = MimetypeIndexer().run(*args, **kwargs) - return {'status': 'eventful' if results else 'uneventful'} + return MimetypeIndexer().run(*args, **kwargs) @app.task(name=__name__ + '.ContentRangeMimetype') def range_mimetype(*args, **kwargs): - results = MimetypeRangeIndexer().run(*args, **kwargs) - return {'status': 'eventful' if results else 'uneventful'} + return MimetypeRangeIndexer().run(*args, **kwargs) @app.task(name=__name__ + '.ContentRangeFossologyLicense') def range_license(*args, **kwargs): - results = FossologyLicenseRangeIndexer().run(*args, **kwargs) - return {'status': 'eventful' if results else 'uneventful'} + return FossologyLicenseRangeIndexer().run(*args, **kwargs) diff --git a/swh/indexer/tests/test_fossology_license.py b/swh/indexer/tests/test_fossology_license.py --- a/swh/indexer/tests/test_fossology_license.py +++ b/swh/indexer/tests/test_fossology_license.py @@ -36,7 +36,7 @@ ['GPL', 'AGPL'])]: mock_subprocess.check_output.return_value = intermediary_result - actual_result = compute_license(path, log=None) + actual_result = compute_license(path) self.assertEqual(actual_result, { 'licenses': output, @@ -44,7 +44,7 @@ }) -def mock_compute_license(path, log=None): +def mock_compute_license(path): """path is the content identifier """ diff --git a/swh/indexer/tests/utils.py b/swh/indexer/tests/utils.py --- a/swh/indexer/tests/utils.py +++ b/swh/indexer/tests/utils.py @@ -746,12 +746,12 @@ start, end = map(hashutil.hash_to_bytes, (_start, _end)) # given - actual_results = self.indexer.run( # checks the bytes input this time + actual_results = self.indexer.run( start, end, skip_existing=False) # no already indexed data so same result as prior test # then - self.assertTrue(actual_results) + self.assertEquals(actual_results, {'status': 'uneventful'}) def test_generate_content_get_no_result(self): """No result indexed returns False""" @@ -759,8 +759,7 @@ '0000000000000000000000000000000000000001'] start, end = map(hashutil.hash_to_bytes, (_start, _end)) # given - actual_results = self.indexer.run( - start, end, incremental=False) + actual_results = self.indexer.run(start, end, incremental=False) # then - self.assertFalse(actual_results) + self.assertEquals(actual_results, {'status': 'uneventful'})