mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-14 22:37:16 +01:00
Add 'person search' command
This commit is contained in:
parent
ab749fcaf5
commit
a36c4a9f6f
51
osc/commands/person_search.py
Normal file
51
osc/commands/person_search.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import osc.commandline
|
||||||
|
|
||||||
|
|
||||||
|
class PersonSearchCommand(osc.commandline.OscCommand):
|
||||||
|
"""
|
||||||
|
Search a person (user)
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = "search"
|
||||||
|
parent = "PersonCommand"
|
||||||
|
|
||||||
|
def init_arguments(self):
|
||||||
|
self.add_argument(
|
||||||
|
"--login",
|
||||||
|
help="Search by a login.",
|
||||||
|
)
|
||||||
|
self.add_argument(
|
||||||
|
"--login-contains",
|
||||||
|
metavar="SUBSTR",
|
||||||
|
help="Search by a substring in a login.",
|
||||||
|
)
|
||||||
|
self.add_argument(
|
||||||
|
"--realname-contains",
|
||||||
|
metavar="SUBSTR",
|
||||||
|
help="Search by a substring in a realname.",
|
||||||
|
)
|
||||||
|
self.add_argument(
|
||||||
|
"--email",
|
||||||
|
help="Search by an email address.",
|
||||||
|
)
|
||||||
|
self.add_argument(
|
||||||
|
"--email-contains",
|
||||||
|
metavar="SUBSTR",
|
||||||
|
help="Search by a substring in an email address.",
|
||||||
|
)
|
||||||
|
|
||||||
|
def run(self, args):
|
||||||
|
from .. import obs_api
|
||||||
|
|
||||||
|
persons = obs_api.Person.search(
|
||||||
|
args.apiurl,
|
||||||
|
login=args.login,
|
||||||
|
login__contains=args.login_contains,
|
||||||
|
realname__contains=args.realname_contains,
|
||||||
|
email=args.email,
|
||||||
|
email__contains=args.email_contains,
|
||||||
|
)
|
||||||
|
|
||||||
|
for person in persons:
|
||||||
|
print(person.to_human_readable_string())
|
||||||
|
print()
|
@ -33,6 +33,19 @@ class Person(XmlModel):
|
|||||||
ignore_auth_services: Optional[BoolString] = Field(
|
ignore_auth_services: Optional[BoolString] = Field(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def to_human_readable_string(self) -> str:
|
||||||
|
"""
|
||||||
|
Render the object as a human readable string.
|
||||||
|
"""
|
||||||
|
from ..output import KeyValueTable
|
||||||
|
|
||||||
|
table = KeyValueTable()
|
||||||
|
table.add("Login", self.login, color="bold")
|
||||||
|
table.add("Real name", self.realname)
|
||||||
|
table.add("Email", self.email)
|
||||||
|
table.add("State", self.state)
|
||||||
|
return f"{table}"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_api(cls, apiurl: str, username: str):
|
def from_api(cls, apiurl: str, username: str):
|
||||||
url_path = ["person", username]
|
url_path = ["person", username]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user