def setup_radio_edit(cfg=None):
    etc_cfg = "/etc/radioedit.cfg"
    cwd_path_cfg = os.path.join(
        get_base(),
        "radioedit.cfg")

    if not cfg and os.path.exists(etc_cfg):
        cfg = etc_cfg
    elif not cfg and os.path.exists(cwd_path_cfg):
        cfg = cwd_path_cfg
    else:
        raise Exception("No config file.")

    cp = SafeConfigParser()
    cp.read([cfg])
    username = cp.get("rackspacecloud", "user")
    apikey = cp.get("rackspacecloud", "apikey")
    prefix = cp.get("radioedit", "prefix")
    pubkey = cp.get("radioedit", "pubkey")
    try:
        server_size = cp.get("rackspacecloud", "server_size")
    except KeyError:
        server_size = 512
    except ConfigParser.NoOptionError:
        server_size = 512

    config_slash = {}
    password_protected = False
    try:
        if cp.get("radioedit", "password_protected").lower() in \
                ('no', 'false', 'off', '0'):
            password_protected = False
    except(__HOLE__, ConfigParser.NoOptionError):
        password_protected = True
    if password_protected:
        re_admin = cp.get("radioedit", "admin")
        re_admin_pass = cp.get("radioedit", "adminpass")
        users = {re_admin: re_admin_pass}
        config_slash = {'tools.basic_auth.on': True,
                        'tools.basic_auth.realm': 'Radioedit',
                        'tools.basic_auth.users': users,
                        'tools.basic_auth.encrypt': lambda x: x}

    try:
        auth_url = cp.get("rackspacecloud", "auth_url")
    except(KeyError, ConfigParser.NoOptionError):
        auth_url = "https://auth.api.rackspacecloud.com/v1.0"

    try:
        private_key = cp.get("radioedit", "privatekey")
    except(KeyError, ConfigParser.NoOptionError):
        private_key = os.path.expanduser('~/.ssh/id_rsa')

    conf = {'/': config_slash,
            '/static':
                 {'tools.staticdir.on': True,
                  'tools.staticdir.root': get_base(),
                  'tools.staticdir.dir': "static"},
           }
    return cherrypy.Application(
               RadioEdit(username,
                         apikey,
                         pubkey,
                         prefix=prefix,
                         auth_url=auth_url,
                         server_size=server_size,
                         private_key=private_key,
                         ),
               script_name=None, config=conf)
dataset/ETHPy150Open cloudbuilders/radioedit/radioedit.py/setup_radio_edit