Exemplo n.º 1
0
    def add(self, pipe_name, pipe_type, bundle=None, switch=True):
        """Method for adding a new data pipe container to the dictionary.

        This method should be used rather than importing the PipeContainer class and using the statement 'D[pipe] = PipeContainer()', where D is the relax data storage object and pipe is the name of the data pipe.

        @param pipe_name:   The name of the new data pipe.
        @type pipe_name:    str
        @param pipe_type:   The data pipe type.
        @type pipe_type:    str
        @keyword bundle:    The optional data pipe bundle to associate the data pipe with.
        @type bundle:       str or None
        @keyword switch:    A flag which if True will cause the new data pipe to be set to the current data pipe.
        @type switch:       bool
        """

        # Test if the pipe already exists.
        if pipe_name in self.instance:
            raise RelaxPipeError(pipe_name)

        # Create a new container.
        self[pipe_name] = PipeContainer()

        # Add the data pipe type string to the container.
        self[pipe_name].pipe_type = pipe_type

        # The pipe bundle.
        if bundle:
            # A new bundle.
            if bundle not in self.pipe_bundles:
                self.pipe_bundles[bundle] = []

            # Add the pipe to the bundle.
            self.pipe_bundles[bundle].append(pipe_name)

        # Change the current data pipe.
        if switch:
            # Set the current data pipe.
            self.instance.current_pipe = pipe_name
            builtins.cdp = self[pipe_name]

            # Signal the switch.
            status.observers.pipe_alteration.notify()
Exemplo n.º 2
0
    def add(self, pipe_name, pipe_type, bundle=None, switch=True):
        """Method for adding a new data pipe container to the dictionary.

        This method should be used rather than importing the PipeContainer class and using the statement 'D[pipe] = PipeContainer()', where D is the relax data storage object and pipe is the name of the data pipe.

        @param pipe_name:   The name of the new data pipe.
        @type pipe_name:    str
        @param pipe_type:   The data pipe type.
        @type pipe_type:    str
        @keyword bundle:    The optional data pipe bundle to associate the data pipe with.
        @type bundle:       str or None
        @keyword switch:    A flag which if True will cause the new data pipe to be set to the current data pipe.
        @type switch:       bool
        """

        # Test if the pipe already exists.
        if pipe_name in self.instance:
            raise RelaxPipeError(pipe_name)

        # Create a new container.
        self[pipe_name] = PipeContainer()

        # Add the data pipe type string to the container.
        self[pipe_name].pipe_type = pipe_type

        # The pipe bundle.
        if bundle:
            # A new bundle.
            if bundle not in self.pipe_bundles:
                self.pipe_bundles[bundle] = []

            # Add the pipe to the bundle.
            self.pipe_bundles[bundle].append(pipe_name)

        # Change the current data pipe.
        if switch:
            # Set the current data pipe.
            self.instance.current_pipe = pipe_name
            builtins.cdp = self[pipe_name]

            # Signal the switch.
            status.observers.pipe_alteration.notify()