def main(): config = _make_parser().parse_args() ephorte_ws_client, ecfg = make_ephorte_client(config.config) pop = PopulateEphorte(ephorte_ws_client) if config.populate_roles: pop.populate_roles() if config.populate_permissions: pop.populate_permissions() if config.mail_warnings_to: mail_warnings(config.mail_warnings_to, debug=config.dryrun) if config.dryrun: db.rollback() logger.info("DRYRUN: Roll back changes") else: db.commit() logger.info("Committing changes")
def main(args=None): args = _make_parser().parse_args(args) ephorte_ws_client, ecfg = make_ephorte_client(args.config) pop = PopulateEphorte(ephorte_ws_client) if args.populate_roles: pop.populate_roles() if args.depopulate: pop.depopulate() if args.mail_warnings_to: mail_warnings(args.mail_warnings_to, debug=not args.commit) if args.commit: db.commit() logger.info("Committing changes") else: db.rollback() logger.info("DRYRUN: Rolling back changes")
def main(): """User-interface and configuration.""" # Parse args parser = argparse.ArgumentParser( description='Update and provision users, ' + 'roles and permissions in ePhorte') parser.add_argument('--config', metavar='<config>', type=str, default='sync_ephorte.cfg', help='Config file to use (default: sync_ephorte.cfg)') cmdgrp = parser.add_mutually_exclusive_group() cmdgrp.add_argument('--full-persons', help='Full sync of persons', action='store_true') cmdgrp.add_argument('--full-sync-account', type=str, metavar="<account_name>", help='Full sync of a single account/person') cmdgrp.add_argument('--full-roles-perms', help='Full sync of roles and permissions', action='store_true') cmdgrp.add_argument('--quick-roles-perms', help='Quick sync of roles and permissions', action='store_true') cmdgrp.add_argument('--disable-users', help='Disable users', action='store_true') cmdgrp.add_argument('--show-org-units', help='Print org units currently in ePhorte', action='store_true') cmdgrp.add_argument('--config-help', help='Show configuration help', action='store_true') cmdgrp.add_argument('--permission-report', help="Generate permission report", action="store", type=argparse.FileType(mode="w")) parser.add_argument('--commit', help='Run in commit mode', action='store_true') args = parser.parse_args() if args.config_help: print("""Example configuration: [DEFAULT] wsdl=http://example.com/?wsdl customer_id=CustomerID database=DatabaseName client_key=None client_cert=None ca_certs=None selection_spread=ePhorte_person change_key=eph_sync_foo changes_too_old_days=30""") sys.exit(0) # Select proper client depending on commit-argument if args.commit: logger.info('Running in commit mode') else: logger.info('Not running in commit mode. Using mock client') from Cerebrum.modules.no.uio.EphorteWS import make_ephorte_client client, config = make_ephorte_client(args.config, mock=not args.commit) try: selection_spread = co.Spread(config.selection_spread) int(selection_spread) logger.info('Using spread %s as selection criteria', str(selection_spread)) except Errors.NotFoundError: logger.error('Spread %s could not be found, aborting.', config.selection_spread) sys.exit(1) try: config.change_key except AttributeError: logger.error('Missing change_key in configuration.') sys.exit(1) if args.quick_roles_perms: logger.info("Quick sync of roles and permissions started") quicksync_roles_and_perms(client=client, config=config, selection_spread=selection_spread, commit=args.commit) logger.info('Quick sync of roles and permissions finished') elif args.full_roles_perms: logger.info("Full sync of roles and permissions started") fullsync_roles_and_perms(client=client, selection_spread=selection_spread) logger.info('Full sync of roles and permissions finished') elif args.full_sync_account: logger.info("Syncing person info, roles and permissions for %s", args.full_sync_account) fullsync_account(client=client, selection_spread=selection_spread, account_name=args.full_sync_account) logger.info("Done syncing person info, roles and permissions for %s", args.full_sync_account) elif args.disable_users: logger.info('Starting to disable users') disable_users(client=client, selection_spread=selection_spread) logger.info('Finished disabling users') elif args.full_persons: logger.info("Full sync of persons started") fullsync_persons(client=client, selection_spread=selection_spread) logger.info('Full sync of persons finished') elif args.permission_report: logger.info("Permission report generation started") report_perms(client, selection_spread, args.permission_report) logger.info("Permission report generation finished") elif args.show_org_units: show_org_units(client)