Add a script to retrieve a persons ID from the badges db on badges-backend01.
This commit is contained in:
parent
26f73f413c
commit
9270a82044
2 changed files with 61 additions and 0 deletions
60
roles/badges-backend/files/get-badges-person-id
Normal file
60
roles/badges-backend/files/get-badges-person-id
Normal file
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env python
|
||||
""" This is a CLI script for retrieving a person's id in the badges db given
|
||||
their FAS username.
|
||||
"""
|
||||
|
||||
import __main__
|
||||
__main__.__requires__ = __requires__ = ["tahrir-api", "sqlalchemy>=0.7"];
|
||||
import pkg_resources
|
||||
pkg_resources.require(__requires__)
|
||||
|
||||
import argparse
|
||||
import transaction
|
||||
import sys
|
||||
|
||||
from tahrir_api.dbapi import TahrirDatabase
|
||||
|
||||
import fedmsg
|
||||
import fedmsg.config
|
||||
|
||||
import fedbadges.utils
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(__doc__)
|
||||
parser.add_argument('--user', default=None, help="A FAS username")
|
||||
args = parser.parse_args()
|
||||
if not args.user:
|
||||
print "You must specify a FAS username."
|
||||
sys.exit(1)
|
||||
return args
|
||||
|
||||
|
||||
def initialize():
|
||||
fm_config = fedmsg.config.load_config()
|
||||
fm_config['cert_prefix'] = 'fedbadges'
|
||||
fm_config['name'] = 'relay_inbound'
|
||||
fm_config['active'] = True
|
||||
fedmsg.init(**fm_config)
|
||||
uri = fm_config['badges_global']['database_uri']
|
||||
tahrir = TahrirDatabase(
|
||||
uri,
|
||||
notification_callback=fedbadges.utils.notification_callback,
|
||||
)
|
||||
return tahrir
|
||||
|
||||
|
||||
def main(tahrir, nickname, badge_id):
|
||||
person = tahrir.get_person(nickname=nickname)
|
||||
|
||||
if not person:
|
||||
print "No such person %r" % nickname
|
||||
sys.exit(1)
|
||||
|
||||
print person.nickname, "has the id", person.id
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = parse_args()
|
||||
tahrir = initialize()
|
||||
main(tahrir, args.user, args.badge)
|
|
@ -129,5 +129,6 @@
|
|||
mode=750
|
||||
with_items:
|
||||
- award-badge
|
||||
- get-badges-person-id
|
||||
tags:
|
||||
- scripts
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue