Пример #1
0
 def _file_name ( self ):
     """ Gets the current trait data base file name.
     """
     if self.file_name != '':
         return self.file_name
     return join( traits_home(), DB_NAME )
Пример #2
0
 def _file_name(self):
     """ Gets the current trait data base file name.
     """
     if self.file_name != '':
         return self.file_name
     return join(traits_home(), DB_NAME)
Пример #3
0
    def export ( self, package ):
        """Exports all of the traits in a specified package from the master
           traits data base to a traits data base in the package's directory, or
           to a data base called <package>_traits_db in the master traits data
           base's directory if the package directory is not writable. The name
           of the export file is returned as the result.
       """
        # Substitute the global package for an empty package name:
        if package == '':
            package = 'global'

        # Get the set of traits to be exported:
        exported = {}
        rdb      = self.rdb
        for name in self.names( package ):
            exported[ name ] = rdb[ name ]
        self.rdb = None

        wdb       = None
        file_name = self.file_name
        if package != 'global':
            # Iterate over all elements of the Python path looking for the
            # matching package directory to export to:
            result = None
            dirs   = package.split( '.' )
            for path in sys.path:
                for dir in dirs:
                    path = join( path, dir )
                    if ((not exists( path )) or
                        (not exists( join( path, '__init__.py' ) ))):
                        break
                else:
                    result = path
                    break

            # If we found the package directory, attempt to set up a writable
            # data base:
            if result is not None:
                self.file_name = result
                try:
                    wdb = self.wdb
                except:
                    pass

        # If we could not create the data base in a package directory, then
        # create it in the master trait data base directory:
        if wdb is None:
            result = join( traits_home(),
                           package.replace( '.', '_' ) + DB_NAME )
            self.file_name = result

        # Copy all of the trait definitions into the export data base:
        self._batch_update = True
        for name, trait in exported.items():
            self( name, trait )

        # Restore the original state and close the export data base:
        self._batch_update = False
        self.wdb           = None
        self.file_name     = file_name

        # Return the name of the export data base as the result:
        return result
Пример #4
0
    def export(self, package):
        """Exports all of the traits in a specified package from the master
           traits data base to a traits data base in the package's directory, or
           to a data base called <package>_traits_db in the master traits data
           base's directory if the package directory is not writable. The name
           of the export file is returned as the result.
       """
        # Substitute the global package for an empty package name:
        if package == '':
            package = 'global'

        # Get the set of traits to be exported:
        exported = {}
        rdb = self.rdb
        for name in self.names(package):
            exported[name] = rdb[name]
        self.rdb = None

        wdb = None
        file_name = self.file_name
        if package != 'global':
            # Iterate over all elements of the Python path looking for the
            # matching package directory to export to:
            result = None
            dirs = package.split('.')
            for path in sys.path:
                for dir in dirs:
                    path = join(path, dir)
                    if ((not exists(path))
                            or (not exists(join(path, '__init__.py')))):
                        break
                else:
                    result = path
                    break

            # If we found the package directory, attempt to set up a writable
            # data base:
            if result is not None:
                self.file_name = result
                try:
                    wdb = self.wdb
                except:
                    pass

        # If we could not create the data base in a package directory, then
        # create it in the master trait data base directory:
        if wdb is None:
            result = join(traits_home(), package.replace('.', '_') + DB_NAME)
            self.file_name = result

        # Copy all of the trait definitions into the export data base:
        self._batch_update = True
        for name, trait in exported.items():
            self(name, trait)

        # Restore the original state and close the export data base:
        self._batch_update = False
        self.wdb = None
        self.file_name = file_name

        # Return the name of the export data base as the result:
        return result