示例#1
0
def main(inargs=None):
    """Start consuming messages."""
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-c',
                        '--config',
                        dest='configfile',
                        metavar='FILE',
                        default=None,
                        help='Use a custom configuration file')
    parser = add_commit_args(parser)

    logutils.options.install_subparser(parser)
    args = parser.parse_args(inargs)
    logutils.autoconf('cronjob', args)

    prog_name = parser.prog.rsplit('.', 1)
    database = Factory.get('Database')()
    database.cl_init(change_program=parser.prog)
    config = load_config(filepath=args.configfile)

    if not args.commit:
        database.commit = database.rollback

    logger.info('Starting %s', prog_name)
    consumer = get_consumer(functools.partial(callback, database),
                            prog_name,
                            config=config.consumer)
    with consumer:
        try:
            consumer.start()
        except KeyboardInterrupt:
            consumer.stop()
        consumer.close()
    logger.info('Stopping %s', prog_name)
示例#2
0
def main(args=None):
    """Start consuming messages."""
    import argparse
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-c', '--config',
                        dest='configfile',
                        metavar='FILE',
                        default=None,
                        help='Use a custom configuration file')
    parser.add_argument(u'-m', u'--mock',
                        dest=u'mock',
                        metavar=u'FILE',
                        default=None,
                        help=u'Load person object from JSON file')
    parser.add_argument(u'--dryrun',
                        dest=u'dryrun',
                        action=u'store_true',
                        default=False,
                        help=u'Do not commit changes')
    args = parser.parse_args(args)
    prog_name = parser.prog.rsplit(u'.', 1)[0]

    import functools
    from Cerebrum.modules.event_consumer import get_consumer

    database = Factory.get('Database')(client_encoding='UTF-8')
    database.cl_init(change_program=prog_name)
    source_system = Factory.get('Constants')(database).system_sap

    config = load_config(filepath=args.configfile)

    if args.dryrun:
        database.commit = database.rollback

    if args.mock:
        import json
        mock_data = load_mock(args.mock)
        parsed_mock_data = _parse_hr_person(database,
                                            source_system,
                                            mock_data)
        body = json.dumps({u'sub': None})
        callback(database, source_system, u'', u'', body,
                 datasource=lambda *x: parsed_mock_data)
    else:
        logger.info('Starting {}'.format(prog_name))
        consumer = get_consumer(functools.partial(callback,
                                                  database, source_system,
                                                  datasource=functools.partial(
                                                      get_hr_person,
                                                      config.ws)),
                                config=config.consumer)
        with consumer:
            try:
                consumer.start()
            except KeyboardInterrupt:
                consumer.stop()
            consumer.close()
        logger.info('Stopping {}'.format(prog_name))
示例#3
0
def main():
    """Start consuming messages."""
    import argparse
    consumer = get_consumer(callback,
                            argparse.ArgumentParser().prog.rsplit('.', 1)[0])

    try:
        consumer.start()
    except KeyboardInterrupt:
        consumer.stop()
        consumer.close()
def main(args=None):
    """Start consuming messages."""
    import argparse
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-c', '--config',
                        dest='configfile',
                        metavar='FILE',
                        default=None,
                        help='Use a custom configuration file')
    parser.add_argument(u'--commit',
                        dest=u'commit',
                        action=u'store_true',
                        default=False,
                        help=u'Commit changes')
    parser.add_argument(u'--send-notification',
                        dest=u'send_notification',
                        action=u'store_true',
                        default=False,
                        help=u'Send information about forward removal')
    args = parser.parse_args(args)
    prog_name = parser.prog.rsplit(u'.', 1)[0]

    import functools
    from Cerebrum.modules.event_consumer import get_consumer

    database = Factory.get('Database')()
    database.cl_init(change_program=prog_name)

    config = load_config(filepath=args.configfile)

    co = Factory.get('Constants')(database)
    source_system = co.human2constant(config.fpe.source_system)
    affiliation = co.human2constant(config.fpe.affiliation)
    assert int(source_system) and int(affiliation), \
        "Error, source system or affiliation identifier is non-existent"

    if not args.commit:
        database.commit = database.rollback

    logger.info('Starting {}'.format(prog_name))
    consumer = get_consumer(functools.partial(callback,
                                              database,
                                              source_system,
                                              affiliation,
                                              args.send_notification,
                                              config.email_config),
                            config=config.consumer)
    with consumer:
        try:
            consumer.start()
        except KeyboardInterrupt:
            consumer.stop()
        consumer.close()
    logger.info('Stopping {}'.format(prog_name))
示例#5
0
def main():
    """Start consuming messages."""
    import argparse
    consumer = get_consumer(callback,
                            argparse.ArgumentParser().prog.rsplit('.', 1)[0])

    try:
        consumer.start()
    except KeyboardInterrupt:
        consumer.stop()
        consumer.close()
def main(args=None):
    """Start consuming messages."""
    import argparse
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-c',
                        '--config',
                        dest='configfile',
                        metavar='FILE',
                        default=None,
                        help='Use a custom configuration file')
    parser.add_argument(u'--commit',
                        dest=u'commit',
                        action=u'store_true',
                        default=False,
                        help=u'Commit changes')
    parser.add_argument(u'--send-notification',
                        dest=u'send_notification',
                        action=u'store_true',
                        default=False,
                        help=u'Send information about forward removal')
    args = parser.parse_args(args)
    prog_name = parser.prog.rsplit(u'.', 1)[0]

    import functools
    from Cerebrum.modules.event_consumer import get_consumer

    database = Factory.get('Database')()
    database.cl_init(change_program=prog_name)

    config = load_config(filepath=args.configfile)

    co = Factory.get('Constants')(database)
    source_system = co.human2constant(config.fpe.source_system)
    affiliation = co.human2constant(config.fpe.affiliation)
    assert int(source_system) and int(affiliation), \
        "Error, source system or affiliation identifier is non-existent"

    if not args.commit:
        database.commit = database.rollback

    logger.info('Starting {}'.format(prog_name))
    consumer = get_consumer(functools.partial(callback, database,
                                              source_system, affiliation,
                                              args.send_notification,
                                              config.email_config),
                            config=config.consumer)
    with consumer:
        try:
            consumer.start()
        except KeyboardInterrupt:
            consumer.stop()
        consumer.close()
    logger.info('Stopping {}'.format(prog_name))
示例#7
0
def main(args=None):
    """Start consuming messages."""
    import argparse
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-c',
                        '--config',
                        dest='configfile',
                        metavar='FILE',
                        default=None,
                        help='Use a custom configuration file')
    parser.add_argument(u'-m',
                        u'--mock',
                        dest=u'mock',
                        metavar=u'FILE',
                        default=None,
                        help=u'Load person object from JSON file')
    parser.add_argument(u'--dryrun',
                        dest=u'dryrun',
                        action=u'store_true',
                        default=False,
                        help=u'Do not commit changes')
    args = parser.parse_args(args)
    prog_name = parser.prog.rsplit(u'.', 1)[0]

    import functools
    from Cerebrum.modules.event_consumer import get_consumer

    database = Factory.get('Database')(client_encoding='UTF-8')
    database.cl_init(change_program=prog_name)
    source_system = Factory.get('Constants')(database).system_sap

    config = load_config(filepath=args.configfile)

    if args.dryrun:
        database.commit = database.rollback

    if args.mock:
        import json
        mock_data = load_mock(args.mock)
        parsed_mock_data = _parse_hr_person(database, source_system, mock_data)
        body = json.dumps({u'sub': None})
        callback(database,
                 source_system,
                 u'',
                 u'',
                 body,
                 datasource=lambda *x: parsed_mock_data)
    else:
        logger.info('Starting {}'.format(prog_name))
        consumer = get_consumer(functools.partial(callback,
                                                  database,
                                                  source_system,
                                                  datasource=functools.partial(
                                                      get_hr_person,
                                                      config.ws)),
                                config=config.consumer)
        with consumer:
            try:
                consumer.start()
            except KeyboardInterrupt:
                consumer.stop()
            consumer.close()
        logger.info('Stopping {}'.format(prog_name))