def _create_configuration_for_twistd(args):
    """ Creates a suitable configuration for twisted based on the parsed arguments. """
    # twistd uses a dict-based configuration format instead of the argparse namespace-based one:
    config = dict(args.__dict__)

    config['python'] = util.sibpath(__file__, 'service.tac')
    config['no_save'] = True

    conf_without_extension = os.path.basename(config['conf']).rsplit('.', 1)[0]
    default_pidfile = '%s.pid'%conf_without_extension

    if not config.get('pidfile') and not config.get('pidfile') == '':
        config['pidfile'] = default_pidfile

    config['pidfile'] = config['pidfile'].replace('%d', default_pidfile)

    twistd_config = twistd.ServerOptions()
    twistd_config.update(config)

    if config['help_reactors']:
        twistd_config.opt_help_reactors()

    if config['reactor']:
        twistd_config.opt_reactor(config['reactor'])

    from piped import log
    twistd_config['logger'] = lambda: log.observer.emit
    return twistd_config
dataset/ETHPy150Open foundit/Piped/piped/scripts.py/_create_configuration_for_twistd/original