Пример #1
0
 def create(cls,
            context: interfaces.context.ContextInterface,
            module_name: str,
            layer_name: str,
            offset: int,
            **kwargs) -> 'Module':
     pathjoin = interfaces.configuration.path_join
     # Check if config_path is None
     free_module_name = context.modules.free_module_name(module_name)
     config_path = kwargs.get('config_path', None)
     if config_path is None:
         config_path = pathjoin('temporary', 'modules', free_module_name)
     # Populate the configuration
     context.config[pathjoin(config_path, 'layer_name')] = layer_name
     context.config[pathjoin(config_path, 'offset')] = offset
     # This is important, since the module_name may be changed in case it is already in use
     if 'symbol_table_name' not in kwargs:
         kwargs['symbol_table_name'] = module_name
     for arg in kwargs:
         context.config[pathjoin(config_path, arg)] = kwargs.get(arg, None)
     # Construct the object
     return_val = cls(context, config_path, free_module_name)
     context.add_module(return_val)
     context.config[config_path] = return_val.name
     # Add the module to the context modules collection
     return return_val
Пример #2
0
    def construct(self, context: interfaces.context.ContextInterface,
                  config_path: str) -> None:
        """Constructs the appropriate layer and adds it based on the class parameter."""
        config_path = interfaces.configuration.path_join(
            config_path, self.name)

        # Determine the layer name
        name = self.name
        counter = 2
        while name in context.modules:
            name = self.name + str(counter)
            counter += 1

        args = {"context": context, "config_path": config_path, "name": name}

        if any([
                subreq.unsatisfied(context, config_path)
                for subreq in self.requirements.values() if not subreq.optional
        ]):
            return None

        obj = self._construct_class(context, config_path, args)
        if obj is not None and isinstance(obj,
                                          interfaces.context.ModuleInterface):
            context.add_module(obj)
            # This should already be done by the _construct_class method
            # context.config[config_path] = obj.name
        return None