| |
@@ -1,8 +1,7 @@
|
| |
from __future__ import unicode_literals, print_function
|
| |
|
| |
|
| |
- from argparse import ArgumentParser
|
| |
-
|
| |
+ import click
|
| |
from fedora.client import AppError
|
| |
|
| |
import hubs.app
|
| |
@@ -14,12 +13,10 @@
|
| |
from .api import sync_team_hub, sync_team_hub_roles
|
| |
|
| |
|
| |
- def create_group_from_fas():
|
| |
- parser = ArgumentParser()
|
| |
- parser.add_argument(
|
| |
- "name", help="group to create the hub for")
|
| |
- args = parser.parse_args()
|
| |
- hub_name = args.name
|
| |
+ @click.command("create-team-from-fas")
|
| |
+ @click.argument("name")
|
| |
+ def create_team_from_fas(hub_name):
|
| |
+ """Create the team hub NAME from FAS."""
|
| |
fedmsg_config = get_fedmsg_config()
|
| |
hubs.database.init(fedmsg_config['hubs.sqlalchemy.uri'])
|
| |
hub = Hub.by_name(hub_name, "team")
|
| |
@@ -42,20 +39,18 @@
|
| |
print("It will be synced from FAS in the background.")
|
| |
|
| |
|
| |
- def sync_group_from_fas():
|
| |
- parser = ArgumentParser()
|
| |
- parser.add_argument(
|
| |
- "name", nargs="*", help="team hub to sync")
|
| |
- parser.add_argument(
|
| |
- "--no-roles", action="store_true", help="do not sync roles")
|
| |
- args = parser.parse_args()
|
| |
+ @click.command("sync-teams-from-fas")
|
| |
+ @click.option("--roles/--no-roles", default=False, help="Sync the roles.")
|
| |
+ @click.argument("name", nargs=-1)
|
| |
+ def sync_teams_from_fas(roles, names):
|
| |
+ """Sync all the team hubs NAMEs from FAS."""
|
| |
fedmsg_config = get_fedmsg_config()
|
| |
hubs.database.init(fedmsg_config['hubs.sqlalchemy.uri'])
|
| |
- if not args.name:
|
| |
+ if not names:
|
| |
hubs_to_sync = Hub.query.filter_by(hub_type="team").all()
|
| |
else:
|
| |
hubs_to_sync = []
|
| |
- for hub_name in args.name:
|
| |
+ for hub_name in names:
|
| |
hub = hubs.models.Hub.by_name(hub_name, "team")
|
| |
if hub is None:
|
| |
print("The team hub {} does not exist.".format(hub_name))
|
| |
@@ -67,7 +62,7 @@
|
| |
affected_users = []
|
| |
try:
|
| |
sync_team_hub(hub.id)
|
| |
- if not args.no_roles:
|
| |
+ if roles:
|
| |
affected_users = sync_team_hub_roles(hub.id)
|
| |
except AppError as e:
|
| |
print("Failed syncing hub {}: {}".format(hub.name, e.message))
|
| |
We're starting to have too many command-line scripts for Hubs, this PR introduces a single command
fedora-hubs
managed with click and uses subcommands for the different entry points.