A script to edit the properties of a badge.
This commit is contained in:
parent
985d6408ff
commit
67cf75e706
2 changed files with 73 additions and 0 deletions
72
roles/badges/backend/files/edit-badge
Normal file
72
roles/badges/backend/files/edit-badge
Normal file
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/env python
|
||||
""" This is a CLI script for editing the properties of a badge. """
|
||||
|
||||
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.config
|
||||
|
||||
import fedbadges.utils
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(__doc__)
|
||||
parser.add_argument('--badge', default=None, help="A badge id")
|
||||
parser.add_argument('--description', default=None, help='Description..')
|
||||
parser.add_argument('--criteria', default=None, help='Criteria link')
|
||||
args = parser.parse_args()
|
||||
if not args.badge:
|
||||
print "You must specify a badge id."
|
||||
sys.exit(1)
|
||||
if not args.description and not args.criteria:
|
||||
print "You must specify either description or criteria to edit."
|
||||
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, badge_id, description, criteria):
|
||||
badge = tahrir.get_badge(badge_id)
|
||||
|
||||
if not badge:
|
||||
print "No such badge %r" % badge_id
|
||||
sys.exit(1)
|
||||
|
||||
transaction.begin()
|
||||
|
||||
if description:
|
||||
badge.description = description
|
||||
print "Setting description on %r to %r" % (badge_id, description)
|
||||
|
||||
if criteria:
|
||||
badge.criteria = criteria
|
||||
print "Setting criteria on %r to %r" % (badge_id, criteria)
|
||||
|
||||
transaction.commit()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = parse_args()
|
||||
tahrir = initialize()
|
||||
main(tahrir, args.badge, args.description, args.criteria)
|
|
@ -157,6 +157,7 @@
|
|||
group=sysadmin-badges
|
||||
mode=750
|
||||
with_items:
|
||||
- edit-badge
|
||||
- award-badge
|
||||
- revoke-badge
|
||||
- grant-authorization
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue