本文整理汇总了Python中CodernityDB.database.Database.all方法的典型用法代码示例。如果您正苦于以下问题:Python Database.all方法的具体用法?Python Database.all怎么用?Python Database.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodernityDB.database.Database
的用法示例。
在下文中一共展示了Database.all方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import all [as 别名]
def main():
db = Database('/tmp/tut_update')
db.create()
x_ind = WithXIndex(db.path, 'x')
db.add_index(x_ind)
# full examples so we had to add first the data
# the same code as in previous step
for x in xrange(100):
db.insert(dict(x=x))
for y in xrange(100):
db.insert(dict(y=y))
# end of insert part
print db.count(db.all, 'x')
for curr in db.all('x', with_doc=True):
doc = curr['doc']
if curr['key'] % 7 == 0:
db.delete(doc)
elif curr['key'] % 5 == 0:
doc['updated'] = True
db.update(doc)
print db.count(db.all, 'x')
for curr in db.all('x', with_doc=True):
print curr
示例2: main
# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import all [as 别名]
def main():
db = Database('/tmp/tut1')
db.create()
for x in xrange(100):
print db.insert(dict(x=x))
for curr in db.all('id'):
print curr
示例3: __init__
# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import all [as 别名]
class DBImport:
'''
import scan: scans existing self.db and rebuilds config file
create self.db: creates self.db file, master index, question index and table index
'''
def __init__(self,passkey,xtraDB):
self.key = passkey
self.dbName = xtraDB
self.db=Database(self.dbName)
self.importScan()
def __del__(self):
if (self.db.opened):
self.db.close()
# ADD REBUILD OPTION
def importScan(self):
#read from config, as a check
self.db=Database(self.dbName)
if(self.db.exists()):
self.db.open()
self.db.id_ind.enc_key = self.key
for curr in self.db.all('id'): #since first passkey in self.db should be only one there, function only perfomed once
if curr['t'] == 'master':
masterKey=''.join(curr['_id'])
self.DBConfig = AppConfig()
self.DBConfig.putmap('databaseinfo','indexkey',masterKey)#masterkey=value
self.DBConfig.putmap('databaseinfo','databasename',self.dbName)
break
#add else statement for errors if couldnt be written for found
self.db.close()
return True
示例4: test_all
# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import all [as 别名]
def test_all(self, tmpdir, sh_nums):
db = Database(str(tmpdir) + '/db')
db.create(with_id_index=False)
n = globals()['ShardedUniqueHashIndex%d' % sh_nums]
db.add_index(n(db.path, 'id'))
l = []
for x in xrange(10000):
l.append(db.insert(dict(x=x))['_id'])
for curr in db.all('id'):
l.remove(curr['_id'])
assert l == []
示例5: migrate
# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import all [as 别名]
def migrate(source, destination):
"""
Very basic for now
"""
dbs = Database(source)
dbt = Database(destination)
dbs.open()
dbt.create()
dbt.close()
for curr in os.listdir(os.path.join(dbs.path, "_indexes")):
if curr != "00id.py":
shutil.copyfile(os.path.join(dbs.path, "_indexes", curr), os.path.join(dbt.path, "_indexes", curr))
dbt.open()
for c in dbs.all("id"):
del c["_rev"]
dbt.insert(c)
return True
示例6: main
# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import all [as 别名]
def main():
db = Database('/tmp/demo_secure')
key = 'abcdefgh'
id_ind = EncUniqueHashIndex(db.path, 'id', storage_class='Salsa20Storage')
db.set_indexes([id_ind])
db.create()
db.id_ind.enc_key = key
for x in xrange(100):
db.insert(dict(x=x, data='testing'))
db.close()
dbr = Database('/tmp/demo_secure')
dbr.open()
dbr.id_ind.enc_key = key
for curr in dbr.all('id', limit=5):
print curr
示例7: main
# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import all [as 别名]
def main():
db = Database("/tmp/demo_secure")
key = "abcdefgh"
id_ind = EncUniqueHashIndex(db.path, "id")
db.set_indexes([id_ind])
db.create()
db.id_ind.enc_key = key
print db.id_ind.storage
for x in xrange(100):
db.insert(dict(x=x, data="testing"))
db.close()
dbr = Database("/tmp/demo_secure")
dbr.open()
dbr.id_ind.enc_key = key
for curr in dbr.all("id", limit=5):
print curr
示例8: main
# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import all [as 别名]
def main():
db2 = pickledb.load('examlple.db', True)
db2.set('test', 'test')
db = Database('/home/papaja/Zaloha/target/store.db')
db.open()
# db.create()
# print database
# x_ind = WithHashIndex(db.path, 'hash')
# pointer_ind = WithHashIndex(db.path, 'pointer')
# db.add_index(x_ind)
# db.add_index(pointer_ind)
# db.insert({'hash':'3f8ee76c84d95c3f4ed061db98694be57e7d33da', 'pointer':1})
# # for x in xrange(100):
# db.insert(dict(x='3f8ee76c84d95c3f4ed061db98694be57e7d33da'))
# for curr in db.all('id'):
# curr['x'] = 1
# db.update(curr)
# print curr
for curr in db.all('id'):
print curr
try:
test = db.get('hash', '3f8ee76c84d95c3f4ed061db98694be57e7d33da', with_doc=True)
print test
except RecordNotFound:
print "Nieje rekord"
exit()
test['doc']['pointer'] = test['doc']['pointer'] + 1
db.update(test['doc'])
for curr in db.all('id'):
print curr
exit()
lstat = os.lstat("/home/papaja/.cache/keyring-SZ5Lrw/gpg")
mode = lstat.st_mode
if S_ISDIR(mode):
print("dir")
elif S_ISREG(mode):
print("file")
elif S_ISLNK(mode):
print("link")
else:
print("None")
print(mode)
print(lstat)
print(S_ISFIFO(mode))
exit()
#print(os.readlink('/home/papaja/Zaloha/target/objects/test'))
#shutil.move("/home/papaja/Zaloha/target/journal/objects/a3fe40b52ec03a7e2d8c8c0ca86baaf0192038c5.meta", "/home/papaja/Zaloha/target/objects")
#shutil.rmtree(os.path.join("/home/papaja/", "objects"))
# myFile = MyFile('/home/papaja/third')
# print(myFile.readline().decode("UTF-8"))
# dst = open('/home/mint/Diplomovka/first', 'wb')
# src = open('second', 'rb')
# synced = open('/home/papaja/third', 'wb')
# signatureFile = open('signature', 'wb')
# deltaFile = open('/home/papaja/delta', 'rb');
# hashes = pyrsync2.blockchecksums(dst)
# hashes_save = {
# weak: (index, strong) for index, (weak, strong)
# in enumerate(hashes)
# }
# signature.write(bytes('gz\n', "UTF-8"))
# pickle.dump(hashes_save, signature, pickle.HIGHEST_PROTOCOL)
# type = signature.readline().decode("UTF-8")
# print("Typ {}".format(type.strip()))
# signature.readline()
# hashes_save = pickle.load(signature)
# print(hashes_save)
# delta = pyrsync2.rsyncdelta(src, hashes_save)
# pyrsync2.patchstream(dst, synced, delta)
# io.FileIO
# signature = librsync.signature(dst)
# delta = librsync.delta(src, signature)
# librsync.patch(dst, delta, synced)
# synced.close()
temp = tempfile.NamedTemporaryFile()
skuska = open(temp.name, "wb")
dst = open('/home/mint/Diplomovka/first', 'rb')
velkost = open('/home/mint/Diplomovka/velkost', 'rb')
retazec = 'ahoj'
print(len(retazec))
print(velkost.readline())
print(velkost.read(3))
#velkost.write(str(sys.getsizeof(retazec)))
dst_data = dst.read(16)
while dst_data:
skuska.write(dst_data)
dst_data = dst.read(16)
skuska.close()
patchProcess = subprocess.Popen(['rdiff', 'patch', temp.name, '/home/mint/Diplomovka/delta'], stdout=subprocess.PIPE)
patchFile, patchError = patchProcess.communicate()
# print patchFile
# dst_data = dst.read(16)
while dst_data:
#patchProcess.stdin.write(dst_data)
dst_data = dst.read(16)
# # patchProcess.stdin.write(dst_data)
#patchProcess.stdin.write(dst_data)
#patchProcess.stdin.close()
#.........这里部分代码省略.........
示例9: get
# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import all [as 别名]
def get(self, key):
return super(MultiIndex, self).get(key)
def make_key_value(self, data):
return data['l'], None
if __name__ == '__main__':
from CodernityDB.database import Database
db = Database('/tmp/db_test')
db.create()
db.add_index(MultiIndex(db.path, 'multi'))
for x in xrange(2):
d = dict(l=range(10 * x, 10 * (x + 1)))
db.insert(d)
for curr in db.all('multi'):
print curr
for curr in db.all('id'):
nl = map(lambda x: x * 10, curr['l'])
curr['l'] = nl
db.update(curr)
for curr in db.all('multi'):
print curr
for curr in db.all('id'):
nl = map(lambda x: x % 3, curr['l'])
curr['l'] = nl
print nl
db.update(curr)
示例10: __init__
# 需要导入模块: from CodernityDB.database import Database [as 别名]
# 或者: from CodernityDB.database.Database import all [as 别名]
#.........这里部分代码省略.........
"""
self.cache=None;
self.db.close();
def update(self):
"""update data base """
#~ pass
for word in self.cache:
self.add_checked(word, self.cache[word])
def is_already_checked(self, word):
try:
return bool(self.db.get('a', word))
except:
return False
#~ except: return False;
def get_checked(self, word):
try:
x = self.db.get('a', word, with_doc=True)
y = x.get('doc',False);
if y:
return y.get('d',[])
else: return []
except:
return []
def add_checked(self, word, data):
idata = {"a":word,'d':data}
try:
saved = self.db.get('a', word, with_doc=True)
except:
saved = False
if saved:
saved['doc']['d'] = data
doc = saved['doc']
doc['update'] = True
self.db.update(doc)
else:
self.db.insert(idata)
def exists_cache_word(self, word):
""" test if word exists in cache"""
#if exists in cache dictionary
if word in self.cache:
return True
else: # test in database
if self.is_already_checked(word):
stored_data = self.get_checked(word)
self.cache[word] = stored_data
return bool(self.cache[word])
else:
# add null dict to the word index to avoid multiple database check
self.cache[word] = {}
return {}
def get_relation_freq(self, word_prev, word_cur, relation):
self.exists_cache_word(word_prev)
return self.cache.get(word_prev, {}).get(word_cur, {}).get(relation, 0);
def is_related(self, word_prev, word_cur):
""" test if two words are related"""
#serach in cache
self.exists_cache_word(word_prev)
# if exists in cache or database
return self.cache.get(word_prev, {}).get(word_cur, {});
def add_relation(self, word_prev, word_cur, relation):
#~ relation ='r'+str(relation)
if word_prev not in self.cache:
# test first that is in db cache
if self.is_already_checked(word_prev):
stored_data = self.get_checked(word_prev)
self.cache[word_prev] = stored_data
else: # create an new entry
self.cache[word_prev] = {word_cur:{relation:1, }, }
# word_prev exists
# add word_cur to previous dict
elif word_cur not in self.cache[word_prev]:
self.cache[word_prev][word_cur] = {relation:1,}
elif relation not in self.cache[word_prev][word_cur]:
self.cache[word_prev][word_cur][relation] = 1
else:
self.cache[word_prev][word_cur][relation] += 1
def display_all(self):
""" display all contents of data base """
#~ pass
print "aranasyn.cache: dislay all records in Thaalib Database """
for curr in self.db.all('a', with_doc=True):
print curr['doc']['a'], arepr(curr['doc']['d'])