-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1567 from dmach/person-register-search
Add 'person register' and 'person search' commands
- Loading branch information
Showing
4 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import osc.commandline | ||
|
||
|
||
class PersonCommand(osc.commandline.OscCommand): | ||
""" | ||
Manage persons | ||
""" | ||
|
||
name = "person" | ||
|
||
def run(self, args): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import osc.commandline | ||
|
||
|
||
class PersonRegisterCommand(osc.commandline.OscCommand): | ||
""" | ||
Register a new person (user) | ||
""" | ||
|
||
name = "register" | ||
parent = "PersonCommand" | ||
|
||
def init_arguments(self): | ||
self.add_argument( | ||
"--login", | ||
required=True, | ||
help="Login.", | ||
) | ||
self.add_argument( | ||
"--realname", | ||
required=True, | ||
help="Real name of the person.", | ||
) | ||
self.add_argument( | ||
"--email", | ||
required=True, | ||
help="Email address.", | ||
) | ||
self.add_argument( | ||
"--password", | ||
help="Password. An interactive prompt is shown if password is not specified.", | ||
) | ||
self.add_argument( | ||
"--note", | ||
help="Any notes about the person.", | ||
) | ||
self.add_argument( | ||
"--state", | ||
help="State of the account. Defaults to 'unconfirmed'.", | ||
) | ||
|
||
def run(self, args): | ||
from osc import obs_api | ||
from osc.util.helper import raw_input | ||
|
||
if args.password: | ||
password = args.password | ||
else: | ||
password = raw_input(f"Enter password for {args.login}@{args.apiurl}: ") | ||
|
||
obs_api.Person.cmd_register( | ||
args.apiurl, | ||
login=args.login, | ||
realname=args.realname, | ||
email=args.email, | ||
password=password, | ||
note=args.note, | ||
state=args.state, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters