Coverage for bugscpp/processor/search.py : 88%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2Search command.
4Clone a repository into the given directory on the host machine.
5"""
6from textwrap import dedent
7from typing import List
9from errors import DppNoSuchTagError
10from message import message
11from processor.core.argparser import create_common_parser
12from processor.core.command import SimpleCommand
13from taxonomy import Taxonomy
15try:
16 from functools import cached_property
17except ImportError:
18 cached_property = property
21def _get_all_tags():
22 taxonomy = Taxonomy()
23 tags = set()
24 for name in taxonomy:
25 if name == "example":
26 continue
27 for defect in taxonomy[name].defects:
28 tags.update(defect.tags)
29 return sorted(tags)
32all_tags = _get_all_tags()
35def search_by_tags(tag_list=None):
36 if tag_list is None:
37 return None
38 taxonomy = Taxonomy()
39 search_result = []
40 for name in taxonomy:
41 if name == "example":
42 continue
43 for defect in taxonomy[name].defects:
44 if all(tag.lower() in defect.tags for tag in tag_list):
45 search_result.append(f"{name}-{defect.id}")
46 return search_result
49class SearchCommand(SimpleCommand):
50 """
51 Search command which handles VCS commands based on taxonomy information.
52 """
54 def run(self, argv: List[str]) -> bool:
55 pass
57 def __init__(self):
58 self.parser = create_common_parser()
59 self.parser.add_argument("tags", nargs="+", help="Tags to search")
60 self.parser.usage = dedent(
61 """
62 bugcpp.py search TAGS
63 Possible tags are: {}
64 """
65 ).format(", ".join(all_tags))
66 self.parser.description = dedent(
67 """
68 Search defects by tags.
69 """
70 ).format(", ".join(all_tags))
72 def __call__(self, argv: List[str]):
73 """
75 Parameters
76 ----------
77 argv : List[str]
78 Tag lists
80 Returns
81 -------
82 None
83 """
84 args = self.parser.parse_args(argv)
85 args = [arg.lower() for arg in args.tags]
86 args = [arg.replace("_", "-") for arg in args]
87 no_such_tags = [tag for tag in args if tag not in all_tags]
88 if no_such_tags:
89 raise DppNoSuchTagError(no_such_tags)
90 message.stdout_stream(str(" \n".join(search_by_tags(args))) + "\n")
92 @property
93 def help(self) -> str:
94 return "search defects by tags"