Example #1
0
    def create_data(self, name="Data"):
        """
        Create a new data within this project.

        The new data is initialized with the specified trait values and is
        automatically added to this project.

        """

        # Ensure the name we associate with the data within this project is
        # unique.
        name = make_unique_name(name, self.keys())

        # Create the new data
        data = Data(name)

        # Add it to ourself.
        self.bind_dynamic(data, "context_name")

        logger.debug(
            "Added new data (%s) to EnvProject (%s) with " "name (%s)",
            data,
            self,
            name,
        )

        return data
    def _save_saved_contexts_to_project(self, project_dir):
        """ Saving saved_contexts to a project

            Parameters:
            -----------
            project_dir: Str

            Returns:
            --------
            script: Str
                Details of the saved contexts. This script to be added to
                the project file script.

        """

        # Return if there are no saved contexts.
        if not len(self.exec_context.saved_contexts):
            return ''

        # Prepare the directory to save pickled saved contexts.
        saved_contexts_dir = os.path.join(project_dir, 'saved_contexts')
        if not os.path.exists(saved_contexts_dir):
            os.mkdir(saved_contexts_dir)
        elif not os.path.isdir(saved_contexts_dir):
            try:
                os.remove(saved_contexts_dir)
            except OSError, (errno, strerror):
                logger.error('Error removing %s, %s' % (saved_contexts_dir,
                                                        strerror))
                dir_name = make_unique_name('saved_contexts',
                                                     os.listdir(project_dir))
                saved_contexts_dir = os.path.join(project_dir, dir_name)
Example #3
0
    def create_data(self, name='Data'):
        """
        Create a new data within this project.

        The new data is initialized with the specified trait values and is
        automatically added to this project.

        """

        # Ensure the name we associate with the data within this project is
        # unique.
        name = make_unique_name(name, self.keys())

        # Create the new data
        data = Data(name)

        # Add it to ourself.
        self.bind_dynamic(data, 'context_name')

        logger.debug('Added new data (%s) to EnvProject (%s) with '
            'name (%s)', data, self, name)

        return data