コード例 #1
0
def read_listeners_in_config(config_file, apns_daemon, service_parent):
    """
    Reads the config file and return all the listeners in it one by one.
    """
    if not os.path.isfile(config_file):
        import sys
        print >> sys.stderr, "Config Path: %s" % os.environ("APNSD_CONFIG_DIR")
        raise errors.ConfigFileError(config_file,
                                     "File not found: %s" % config_file)

    configs = eval(open(config_file).read())
    if 'listeners' not in configs:
        raise errors.ConfigFileError(config_file,
                                     "'listeners' section not found")

    listeners = configs['listeners']
    for listener_name in listeners:
        listener_data = listeners[listener_name]
        listener_class = listener_data['class']
        listener_class = importClass(listener_class)
        logging.debug("Creating listener: " + str(listener_class))
        listener = listener_class(apns_daemon, **listener_data)

        if listener_data.get("secure", False):
            server = internet.SSLServer(listener_data["port"], listener)
        else:
            server = internet.TCPServer(listener_data["port"], listener)
        server.setServiceParent(service_parent)

        logging.debug("Listener Created: " + str(listener))
        apns_daemon.registerListener(listener_name, listener)
コード例 #2
0
def read_config_file(apns_daemon, config_file):
    """
    Reads the config file and loads config data about all the apps we want
    to support.
    """
    import os
    if not os.path.isfile(config_file):
        raise errors.ConfigFileError(config_file, "File not found")

    configs = eval(open(config_file).read())
    if 'clients' not in configs:
        raise errors.ConfigFileError(config_file,
                                     "'clients' section not found")

    if 'apps' not in configs:
        raise errors.ConfigFileError(config_file, "'apps' section not found")

    clients = configs['clients']
    for client_name in clients:
        client_data = clients[client_name]
        client_class = client_data['class']
        parts = client_class.split(".")
        if len(parts) > 1:
            client_pkg = ".".join(parts[:-1])
            client_module = __import__(client_pkg, {}, {}, [''])
            client_class = getattr(client_module, parts[-1])
        else:
            client_class = eval(parts[-1])

        client = client_class(apns_daemon, **client_data)
        print "Loading client: ", client
コード例 #3
0
ファイル: schema.py プロジェクト: zbskii/schema-tool
def _load_config(file_name):
    """
    Given a file name for a config, attempt to load and parse it as JSON. If the file
    is not found, then an empty dict will be returned.
    """
    if not os.path.isfile(file_name):
        return {}

    try:
        config_file = open(file_name, 'r')
        try:
            config = json.load(config_file)
        except ValueError, ex:
            raise errors.ConfigFileError("Could not parse config file '%s': %s\n" % (
                file_name, ex.message))
    except IOError, ex:
        sys.stderr.write("Error reading config: %s\n" % ex.strerror)
        sys.stderr.write("Tried reading: %s\n" % file_name)
        raise errors.ConfigFileError("could not read config file")
コード例 #4
0
def read_apps_in_config(config_file, apns_daemon):
    """
    Reads the config file and loads config data about all the apps we want
    to support.
    """
    """
    Reads the config file and return all the listeners in it one by one.
    """
    if not os.path.isfile(config_file):
        raise errors.ConfigFileError(config_file, "File not found")

    configs = eval(open(config_file).read())
    if 'apps' not in configs:
        raise errors.ConfigFileError(config_file, "'apps' section not found")

    apps = configs['apps']
    for app_name in apps:
        app = apps[app_name]
        for app_mode in app:
            app_data = app[app_mode]
            app_class = app_data["app_class"]
            app_class = importClass(app_class)

            logging.debug("Creating App Factory: " + str(app_class))
            # app_data is things like app_id, apns_host, apns_port
            app_factory = app_class(apns_daemon.reactor,
                                    app_name,
                                    app_mode,
                                    connListener=apns_daemon,
                                    **app_data)

            feedbackService = None
            if "fs_class" in app_data:
                fs_class = app_data["fs_class"]
                fs_class = importClass(fs_class)
                logging.debug("Creating Feedback Service: " + str(fs_class))
                feedbackService = fs_class(apns_daemon.reactor, app_name,
                                           app_mode, **app_data)

            apns_daemon.registerApp(app_name, app_mode, app_factory,
                                    feedbackService)