Пример #1
0
 def startup(self):
     """ Starts a repository and reads in a directory structure.
     Raise RepositoryError"""
     self._load_timestamp = {}
     self._cache_load_timestamp = {}
     self.known_bad_ids = []
     if "XML" in self.registry.type:
         self.to_file = xml_to_file
         self.from_file = xml_from_file
     elif "Pickle" in self.registry.type:
         self.to_file = pickle_to_file
         self.from_file = pickle_from_file
     else:
         raise RepositoryError(self.repo, "Unknown Repository type: %s"%self.registry.type)
     self.sessionlock = SessionLockManager(self, self.lockroot, self.registry.name)
     self.sessionlock.startup()
     # Load the list of files, this time be verbose and print out a summary of errors
     self.update_index(verbose = True)
Пример #2
0
class GangaRepositoryLocal(GangaRepository):
    """GangaRepository Local"""

    def __init__(self, registry):
        super(GangaRepositoryLocal,self).__init__(registry)
        self.sub_split = "subjobs"
        self.root = os.path.join(self.registry.location,"6.0",self.registry.name)
        self.lockroot = os.path.join(self.registry.location,"6.0")

    def startup(self):
        """ Starts a repository and reads in a directory structure.
        Raise RepositoryError"""
        self._load_timestamp = {}
        self._cache_load_timestamp = {}
        self.known_bad_ids = []
        if "XML" in self.registry.type:
            self.to_file = xml_to_file
            self.from_file = xml_from_file
        elif "Pickle" in self.registry.type:
            self.to_file = pickle_to_file
            self.from_file = pickle_from_file
        else:
            raise RepositoryError(self.repo, "Unknown Repository type: %s"%self.registry.type)
        self.sessionlock = SessionLockManager(self, self.lockroot, self.registry.name)
        self.sessionlock.startup()
        # Load the list of files, this time be verbose and print out a summary of errors
        self.update_index(verbose = True)


    def shutdown(self):
        """Shutdown the repository. Flushing is done by the Registry
        Raise RepositoryError"""
        self.sessionlock.shutdown()

    def get_fn(self,id):
        """ Returns the file name where the data for this object id is saved"""
        return os.path.join(self.root,"%ixxx"%(id/1000), "%i"%id, "data")

    def get_idxfn(self,id):
        """ Returns the file name where the data for this object id is saved"""
        return os.path.join(self.root,"%ixxx"%(id/1000), "%i.index"%id)

    def index_load(self,id): 
        """ load the index file for this object if necessary
            Loads if never loaded or timestamp changed. Creates object if necessary
            Returns True if this object has been changed, False if not
            Raise IOError on access or unpickling error 
            Raise OSError on stat error
            Raise PluginManagerError if the class name is not found"""
        logger.debug("Loading index %s" % id)
        fn = self.get_idxfn(id)
        if self._cache_load_timestamp.get(id,0) != os.stat(fn).st_ctime: # index timestamp changed
            fobj = file(fn)
            try:
                try:
                    cat,cls,cache = pickle_from_file(fobj)[0]
                except Exception, x:
                    raise IOError("Error on unpickling: %s %s" % (x.__class__.__name__, x))
                if id in self.objects:
                    obj = self.objects[id]
                    if obj._data:
                        obj.__dict__["_registry_refresh"] = True
                else:
                    obj = self._make_empty_object_(id,cat,cls)
                obj._index_cache = cache
            finally: