Пример #1
0
    def LoadFrom(cls, **kwargs):
        options = cls.parse_options(**kwargs)
        if options['path'] == '':
            raise iDBError(EIDBNODIR,
                           'Please specify the database directory first!')
        vData = None
        #vType = None #see LoadItem
        if options['storeInXattr']:
            vData = cls.get_by_xattr(options['path'], options['key'],
                                     **options)
            #vType = cls.get_by_xattr(options['path'], options['key'], IDB_KEY_TYPE_NAME)
        else:
            options['storeInFile'] = True
        if vData == None and options['storeInFile']:
            vData = cls.get_by_file(options['path'], options['key'], **options)
            #vType = cls.get_by_file(options['path'], options['key'], IDB_KEY_TYPE_NAME)
        if vData == None:
            raise iDBError(
                EIDBNOSUCHKEY, "Error: No Such Key(%s) Exists." %
                path.join(options['path'], options['key']))

        # create a new instance
        result = cls(cls.__data__(vData), **kwargs)
        #result.data = vData

        return result
Пример #2
0
    def GetType(cls,  ** kwargs):
        options = cls.parse_options(** kwargs)
        if options['path']  ==  '':
            raise iDBError(EIDBNODIR, 'Please specify the database directory first!')
        data = Item.get_by_xattr(options['path'], options['key'], IDB_KEY_TYPE_NAME)
        if data == None and options['storeInFile']:
            data = Item.get_by_file(options['path'], options['key'], IDB_KEY_TYPE_NAME)
        if data  == None:
            raise iDBError(EIDBNOSUCHKEY, "Error: No Such Key(%s) Exists." % path.join(options['path'], options['key']))

        return data
Пример #3
0
    def GetType(cls, **kwargs):
        options = cls.parse_options(**kwargs)
        if options['path'] == '':
            raise iDBError(EIDBNODIR,
                           'Please specify the database directory first!')
        data = Item.get_by_xattr(options['path'], options['key'],
                                 IDB_KEY_TYPE_NAME)
        if data == None and options['storeInFile']:
            data = Item.get_by_file(options['path'], options['key'],
                                    IDB_KEY_TYPE_NAME)
        if data == None:
            raise iDBError(
                EIDBNOSUCHKEY, "Error: No Such Key(%s) Exists." %
                path.join(options['path'], options['key']))

        return data
Пример #4
0
 def LoadFromFile(self, aKey=None):
     if aKey == None:
         aKey = self.key
     result = self.get_by_file(self.path, aKey,  ** self._options )
     if result  == None:
         raise iDBError(EIDBNOSUCHKEY, "Error: No Such Key(%s) Exists." % path.join(self.path, self.key))
         return result
     self.data = self.__data__(result)
     return self
Пример #5
0
 def LoadFromXattr(self, aKey=None):
     # load the item from the aKey
     if aKey == None:
         aKey = self.key
     result = self.get_by_xattr(self.path, aKey,  ** self._options)
     if result  == None:
         raise iDBError(EIDBNOSUCHKEY, "Error: No Such Key(%s) Exists." % path.join(self.path, aKey))
         return result
     self.data = self.__data__(result)
     return self
Пример #6
0
 def LoadFromFile(self, aKey=None):
     if aKey == None:
         aKey = self.key
     result = self.get_by_file(self.path, aKey, **self._options)
     if result == None:
         raise iDBError(
             EIDBNOSUCHKEY, "Error: No Such Key(%s) Exists." %
             path.join(self.path, self.key))
         return result
     self.data = self.__data__(result)
     return self
Пример #7
0
 def LoadFromXattr(self, aKey=None):
     # load the item from the aKey
     if aKey == None:
         aKey = self.key
     result = self.get_by_xattr(self.path, aKey, **self._options)
     if result == None:
         raise iDBError(
             EIDBNOSUCHKEY,
             "Error: No Such Key(%s) Exists." % path.join(self.path, aKey))
         return result
     self.data = self.__data__(result)
     return self
Пример #8
0
 def new(cls,  aData, aNewFunc, **kwargs):
     result = aNewFunc(aData)
     # the path is the database path
     # the key is the list's key
     options = cls.parse_options(** kwargs)
     result.ApplyOptions( ** options)
     #for key, value in options.iteritems():
     #    setattr(result, '_' + key, value)
     if result.path  ==  '':
         raise iDBError(EIDBNODIR, 'Please specify the database directory first!')
     result.key = result._key
     return result
Пример #9
0
 def new(cls, aData, aNewFunc, **kwargs):
     result = aNewFunc(aData)
     # the path is the database path
     # the key is the list's key
     options = cls.parse_options(**kwargs)
     result.ApplyOptions(**options)
     #for key, value in options.iteritems():
     #    setattr(result, '_' + key, value)
     if result.path == '':
         raise iDBError(EIDBNODIR,
                        'Please specify the database directory first!')
     result.key = result._key
     return result
Пример #10
0
    def LoadFrom(cls, **kwargs):
        options = cls.parse_options(** kwargs)
        if options['path']  ==  '':
            raise iDBError(EIDBNODIR, 'Please specify the database directory first!')
        vData = None
        #vType = None #see LoadItem
        if options['storeInXattr']:
            vData = cls.get_by_xattr(options['path'], options['key'],  ** options)
            #vType = cls.get_by_xattr(options['path'], options['key'], IDB_KEY_TYPE_NAME)
        else:
            options['storeInFile'] = True
        if vData == None and options['storeInFile']:
            vData = cls.get_by_file(options['path'], options['key'],  ** options)
            #vType = cls.get_by_file(options['path'], options['key'], IDB_KEY_TYPE_NAME)
        if vData  == None:
            raise iDBError(EIDBNOSUCHKEY, "Error: No Such Key(%s) Exists." % path.join(options['path'], options['key']))

        # create a new instance
        result  = cls(cls.__data__(vData),  ** kwargs)
        #result.data = vData

        return result
Пример #11
0
    def Open(self, aSkipDBConfig = False):
        if self.path  ==  '':
            raise iDBError(EIDBNODIR, 'Please specify the database directory first!')
        vMetaInfo = Dict(path=self.path, key='.db', storeInFile=True, storeInXattr=False)
        if vMetaInfo.Exists():
            vMetaInfo.Load()
            self._version = vMetaInfo['version']
            #if vMetaInfo.has_key('version')
            if not aSkipDBConfig:
                self.ApplyOptions(**  vMetaInfo['config']);
        else:
            vMetaInfo['config'] = self.GetOptions()
            vMetaInfo['version']  =  self.version
            vMetaInfo.Save()

        self.opened = True