Пример #1
0
    def load(self, id_):
        # if __debug__:
        #     global _lvl
        #     _lvl += '<'
        #     gc3libs.log.debug("%s Store %s: Loading task %s %r ...", _lvl, self, id_, type(id_))

        # return cached copy, if any
        try:
            obj = self._loaded[str(id_)]
            # if __debug__:
            #     if _lvl:
            #         _lvl = _lvl[:-1]
            #     gc3libs.log.debug("%s Store %s: Returning cached object %r@%x as task %s", _lvl, self, obj, id(obj), id_)
            return obj
        except KeyError:
            pass

        # no cached copy, load from disk
        q = sql.select([self._tables.c.data]).where(self._tables.c.id == id_)
        with self._engine.begin() as conn:
            rawdata = conn.execute(q).fetchone()
        if not rawdata:
            raise gc3libs.exceptions.LoadError(
                "Unable to find any object with ID '%s'" % id_)
        obj = make_unpickler(self, BytesIO(rawdata[0])).load()
        super(SqlStore, self)._update_to_latest_schema()
        assert str(id_) not in self._loaded
        self._loaded[str(id_)] = obj
        # if __debug__:
        #     if _lvl:
        #         _lvl = _lvl[:-1]
        #     gc3libs.log.debug("%s Store %s: Done loading task %s as %r@%x.", _lvl, self, id_, obj, id(obj))
        return obj
Пример #2
0
 def _load_from_file(self, path):
     """Auxiliary method for `load`."""
     # gc3libs.log.debug("Loading object from file '%s' ...", path)
     with open(path, 'rb') as src:
         unpickler = make_unpickler(self, src)
         obj = unpickler.load()
         return obj
Пример #3
0
 def load(self, id_):
     with closing(self._engine.connect()) as conn:
         q = sql.select([self._tables.c.data]).where(self._tables.c.id == id_)
         rawdata = conn.execute(q).fetchone()
         if not rawdata:
             raise gc3libs.exceptions.LoadError(
                 "Unable to find any object with ID '%s'" % id_)
         obj = make_unpickler(self, StringIO(rawdata[0])).load()
     super(SqlStore, self)._update_to_latest_schema()
     return obj
Пример #4
0
 def load(self, id_):
     with closing(self._engine.connect()) as conn:
         q = sql.select([self._tables.c.data
                         ]).where(self._tables.c.id == id_)
         rawdata = conn.execute(q).fetchone()
         if not rawdata:
             raise gc3libs.exceptions.LoadError(
                 "Unable to find any object with ID '%s'" % id_)
         obj = make_unpickler(self, StringIO(rawdata[0])).load()
     super(SqlStore, self)._update_to_latest_schema()
     return obj
Пример #5
0
    def load(self, id_):
        q = sql.select([self.t_store.c.data]).where(self.t_store.c.id == id_)
        conn = self._engine.connect()
        r = conn.execute(q)
        rawdata = r.fetchone()
        if not rawdata:
            raise gc3libs.exceptions.LoadError(
                "Unable to find any object with ID '%s'" % id_)
        unpickler = make_unpickler(self, StringIO.StringIO(rawdata[0]))
        obj = unpickler.load()
        conn.close()

        return obj
Пример #6
0
    def load(self, id_):
        q = sql.select([self.t_store.c.data]).where(self.t_store.c.id == id_)
        conn = self._engine.connect()
        r = conn.execute(q)
        rawdata = r.fetchone()
        if not rawdata:
            raise gc3libs.exceptions.LoadError(
                "Unable to find any object with ID '%s'" % id_)
        unpickler = make_unpickler(self, StringIO.StringIO(rawdata[0]))
        obj = unpickler.load()
        conn.close()

        return obj
Пример #7
0
 def _load_from_file(self, path):
     """Auxiliary method for `load`."""
     src = None
     try:
         src = open(path, 'rb')
         unpickler = make_unpickler(self, src)
         obj = unpickler.load()
         src.close()
         return obj
     except Exception:
         if src is not None:
             try:
                 src.close()
             except:
                 pass  # ignore errors
         raise
Пример #8
0
 def _load_from_file(self, path):
     """Auxiliary method for `load`."""
     with open(path, 'rb') as src:
         unpickler = make_unpickler(self, src)
         obj = unpickler.load()
         return obj
Пример #9
0
 def _load_from_file(self, path):
     """Auxiliary method for `load`."""
     with open(path, 'rb') as src:
         unpickler = make_unpickler(self, src)
         obj = unpickler.load()
         return obj