Пример #1
0
	def __init__(self, opt):
		super(NodeService, self).__init__()

		# local state
		self.options = opt
		self.config_version = 0
		self.new_config_version = 0
		self.config = options.load_config(self.options)
		self.aws = aws.AWS(self.options, self.config)

		# services
		self.kernelservice = KernelService(self)
		self.addService(self.kernelservice)

		self.incoming_queue = self.kernelservice.incoming_queue
		self.outgoing_queue = self.kernelservice.outgoing_queue

		self.peerservice = PeerService(self)
		self.addService(self.peerservice)
Пример #2
0
def main(library_path, logger=None):
    if not logger:
        logger = setup_logging()

    logger.debug("ctypesgencore version is {0}".format(ctypesgencore.__version__))

    # this is where the generated files are placed
    bindings_path = os.path.join(library_path, "_bindings")
    logger.debug("bindings_path is {0}".format(bindings_path))

    # read configuration
    config = load_config()
    # install from cached directory if the config file requests it and the bindings are already there
    # you will want to enable this in ~/.python-brlcad.cfg when developing higher level features to
    # avoid the time consuming re-installation of the BRL-CAD bindings
    # in the stock python-brlcad.cfg file it will be set to False
    cache_bindings = config.has_option("brlcad", "cached-reinstall") and config.getboolean("brlcad", "cached-reinstall")
    cached_bindings_path = os.path.join(os.path.dirname(__file__), "..", "_bindings")
    if cache_bindings and os.path.isdir(cached_bindings_path):
        logger.debug("installing cached _bindings from {}".format(cached_bindings_path))
        shutil.copytree(cached_bindings_path, bindings_path)
        return
    else:
        cleanup_bindings_dir(bindings_path, cached_bindings_path, logger=logger)
    # find brl-cad installation and set up ctypesgen options
    ctypesgen_library_options, options_map, brlcad_info = load_ctypesgen_options(bindings_path, config, logger)

    # Holds the name of a module and the names that the module defines.
    symbol_map = {}

    # List of libraries that have been generated by the following for loop.
    generated_libraries = []

    for ctypesgen_options in ctypesgen_library_options:
        lib_name = ctypesgen_options.brlcad_lib_name

        logger.debug("Processing library: {0}".format(lib_name))
        logger.debug("Options: {0}".format(ctypesgen_options))

        # HACK: This is how ctypesgen is told to not re-define the same types.
        # The basic concept is to look through dependency_modules and see which
        # modules have already been generated (all of them should be generated
        # by now unless there's a dependency loop in BRL-CAD libraries...). The
        # symbols from each of the generated modules are passed in as
        # other_known_names so that ctypesgen doesn't redefine the
        # previously-generated names. The list of module names is passed in as
        # "modules" so that ctypesgen generates a python file that actually
        # imports those symbols.

        # Construct the list of types and other variables that are already
        # defined by other ctypesgen-generated files.
        ctypesgen_options.other_known_names = []
        for module in ctypesgen_options.modules:
            ctypesgen_options.other_known_names.extend(symbol_map[module])

        # TODO: the ctypesgen printer might need to re-arrange when it imports
        # modules. It should probably happen before the preamble is printed, so
        # that the preamble is just cached instead of always redefining
        # everything. I think now that the preamble is an import line, the
        # types are already cached, so it's probably okay for the moment.

        # generate the wrapper bindings (woot)
        generate_wrapper(ctypesgen_options, logger=logger)
        generated_libraries.append(lib_name)
        logger.debug("Done generating the wrapper file for {0}".format(lib_name))

        # HACK: Load this latest generated library. Create the appropriate
        # __init__.py file and then import the current module. Add module ->
        # dir(module) to the list of known names. On the next pass, if
        # ctypesgen_options.modules has any values, then include the
        # list of known names from the data structure as "other_known_names".

        # 1) generate the appropriate __init__.py file (__all__ will need to be constructed)
        logger.debug("About to write the __init__.py file")
        generate_init_file(bindings_path, generated_libraries, brlcad_info["version"], logger)
        logger.debug("Okay, __init__.py has been updated.")

        # 2) load the latest generated module
        logger.debug("Loading the __init__.py module from {0}".format(bindings_path))
        imp.load_source("_bindings", os.path.join(bindings_path, "__init__.py"))

        logger.debug("Loading the {0} module from {1}.".format(lib_name, ctypesgen_options.output))
        latest_module = imp.load_source(lib_name, ctypesgen_options.output)
        symbols = dir(latest_module)

        # 3) store the list of defined names from that module by running dir(loaded_module)
        symbol_map[lib_name] = symbols

        # TODO: confirm the following TODO statement. It looks like this should
        # be working now?
        # TODO: ctypesgen needs to support "other_known_names" being passed in
        # through options (right now it just overrides this value).

    # always cache bindings, it helps during development and while running python from the brlcad dir:
    logger.debug("Caching _bindings to: {}".format(cached_bindings_path))
    shutil.copytree(bindings_path, cached_bindings_path)
Пример #3
0
def main(library_path, logger=None):
    if not logger:
        logger = setup_logging()

    logger.debug("ctypesgencore version is {0}".format(
        ctypesgencore.__version__))

    # this is where the generated files are placed
    bindings_path = os.path.join(library_path, "_bindings")
    logger.debug("bindings_path is {0}".format(bindings_path))

    # read configuration
    config = load_config()
    # install from cached directory if the config file requests it and the bindings are already there
    # you will want to enable this in ~/.python-brlcad.cfg when developing higher level features to
    # avoid the time consuming re-installation of the BRL-CAD bindings
    # in the stock python-brlcad.cfg file it will be set to False
    cache_bindings = config.has_option(
        "brlcad", "cached-reinstall") and config.getboolean(
            "brlcad", "cached-reinstall")
    cached_bindings_path = os.path.join(os.path.dirname(__file__), "..",
                                        "_bindings")
    if cache_bindings and os.path.isdir(cached_bindings_path):
        logger.debug(
            "installing cached _bindings from {}".format(cached_bindings_path))
        shutil.copytree(cached_bindings_path, bindings_path)
        return
    else:
        cleanup_bindings_dir(bindings_path,
                             cached_bindings_path,
                             logger=logger)
    # find brl-cad installation and set up ctypesgen options
    ctypesgen_library_options, options_map, brlcad_info = load_ctypesgen_options(
        bindings_path, config, logger)

    # Holds the name of a module and the names that the module defines.
    symbol_map = {}

    # List of libraries that have been generated by the following for loop.
    generated_libraries = []

    for ctypesgen_options in ctypesgen_library_options:
        lib_name = ctypesgen_options.brlcad_lib_name

        logger.debug("Processing library: {0}".format(lib_name))
        logger.debug("Options: {0}".format(ctypesgen_options))

        # HACK: This is how ctypesgen is told to not re-define the same types.
        # The basic concept is to look through dependency_modules and see which
        # modules have already been generated (all of them should be generated
        # by now unless there's a dependency loop in BRL-CAD libraries...). The
        # symbols from each of the generated modules are passed in as
        # other_known_names so that ctypesgen doesn't redefine the
        # previously-generated names. The list of module names is passed in as
        # "modules" so that ctypesgen generates a python file that actually
        # imports those symbols.

        # Construct the list of types and other variables that are already
        # defined by other ctypesgen-generated files.
        ctypesgen_options.other_known_names = []
        for module in ctypesgen_options.modules:
            ctypesgen_options.other_known_names.extend(symbol_map[module])

        # TODO: the ctypesgen printer might need to re-arrange when it imports
        # modules. It should probably happen before the preamble is printed, so
        # that the preamble is just cached instead of always redefining
        # everything. I think now that the preamble is an import line, the
        # types are already cached, so it's probably okay for the moment.

        # generate the wrapper bindings (woot)
        generate_wrapper(ctypesgen_options, logger=logger)
        generated_libraries.append(lib_name)
        logger.debug(
            "Done generating the wrapper file for {0}".format(lib_name))

        # HACK: Load this latest generated library. Create the appropriate
        # __init__.py file and then import the current module. Add module ->
        # dir(module) to the list of known names. On the next pass, if
        # ctypesgen_options.modules has any values, then include the
        # list of known names from the data structure as "other_known_names".

        # 1) generate the appropriate __init__.py file (__all__ will need to be constructed)
        logger.debug("About to write the __init__.py file")
        generate_init_file(bindings_path, generated_libraries,
                           brlcad_info["version"], logger)
        logger.debug("Okay, __init__.py has been updated.")

        # 2) load the latest generated module
        logger.debug(
            "Loading the __init__.py module from {0}".format(bindings_path))
        imp.load_source("_bindings", os.path.join(bindings_path,
                                                  "__init__.py"))

        logger.debug("Loading the {0} module from {1}.".format(
            lib_name, ctypesgen_options.output))
        latest_module = imp.load_source(lib_name, ctypesgen_options.output)
        symbols = dir(latest_module)

        # 3) store the list of defined names from that module by running dir(loaded_module)
        symbol_map[lib_name] = symbols

        # TODO: confirm the following TODO statement. It looks like this should
        # be working now?
        # TODO: ctypesgen needs to support "other_known_names" being passed in
        # through options (right now it just overrides this value).

    # always cache bindings, it helps during development and while running python from the brlcad dir:
    logger.debug("Caching _bindings to: {}".format(cached_bindings_path))
    shutil.copytree(bindings_path, cached_bindings_path)