本文整理汇总了Python中PyDbLite.Base.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Base.delete方法的具体用法?Python Base.delete怎么用?Python Base.delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyDbLite.Base
的用法示例。
在下文中一共展示了Base.delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Queue
# 需要导入模块: from PyDbLite import Base [as 别名]
# 或者: from PyDbLite.Base import delete [as 别名]
class Queue(object):
""" Simple queue with PyDbLite backend. """
def __init__(self, queue_type=0, config=None):
if config is not None:
# copy config
pass
else:
self.commit = False
self.db_filename = "/tmp/queue.pydb"
self.mode = "override"
self.queue = Base(self.db_filename)
def create_queue(self):
self.queue.create('id', 'item', mode = self.mode)
self.queue.create_index('id')
return None
def push(self, item):
self.queue.insert(self.length(), item)
return None
def pop(self):
if not self.is_empty():
id = self.length() - 1
r = self.queue._id[id]
self.queue.delete(r)
return r
else:
return None
def list(self):
return self.queue.records
def length(self):
return len(self.queue)
def is_empty(self):
return self.length() == 0
def commit(self):
if self.commit is True:
self.queue.commit()
return None
示例2: Organizer
# 需要导入模块: from PyDbLite import Base [as 别名]
# 或者: from PyDbLite.Base import delete [as 别名]
class Organizer(Cacheable):
"""
This is the base class for organizers
"""
def __init__(self, cache, recursive=True):
Cacheable.__init__(self)
self.cache = cache
self.recursive = recursive
self.transformed = None
# Do not call reset here, it is called from fs.py when the fs is
# already started
def reset(self):
if not self.transformed:
self.transformed = Base(DB_TRANSFORMED)
self.transformed.create('realpath', 'path', 'dirname', mode='override')
self.transformed.create_index('realpath')
self.transformed.create_index('path')
self.transformed.create_index('dirname')
self.cache.reset()
Cacheable.reset(self)
def updatecache(self):
self.generateallpaths()
def deletefromcache(self, path):
realpath = self.realpath(path)
logger.debug("deletefromcache(%s)" % realpath)
self.cache.deletefromcache(realpath)
for item in self.transformed.get_index('realpath')[realpath]:
self.transformed.delete(item)
def addtocache(self, path):
if not self.transformed.get_index('path')[path]:
realpath = self.realpath(path)
self.cache.addtocache(realpath)
self.addfile(realpath)
############################################
# Overwritable functions
def dirlist(self, path): #IGNORE:W0613
"""
Returns a list of (non-existent, generated, virtual) directories for a
given path. Default implementation.
"""
return []
def generatepaths(self, realpath):
"""
Generates paths for a given real path. A file can have more than one
transformed path. Default implementation.
"""
yield util.addtrailingslash(util.removeroot(realpath,
self.cache.filter.root))
def generaterealpath(self, path):
"""
Generates a real path for a inexistent path. Default implementation.
"""
return os.path.join(self.cache.filter.root, path[1:])
############################################
# General functions
def generateallpaths(self):
"""
Generates paths for all the files given by the cache and stores them
in self.transformed
"""
for realpath in self.cache.filelist():
if self.recursive:
# Add all sub-directories first
currentpath = self.cache.filter.root
for pathpart in util.pathparts(util.removeroot(realpath,
self.cache.filter.root)):
currentpath = os.path.join(currentpath, pathpart)
self.addfile(currentpath)
else:
self.addfile(realpath)
def addfile(self, realpath):
"""
Stores a file in self.transformed if not there already and returns the
paths for that file in the proxy file system
"""
logger.debug('addfile(%s)' % realpath)
if not util.ignoretag(util.removeroot(realpath,
self.cache.filter.root)):
return []
self.refreshcache()
transformed = self.transformed.get_index('realpath')[realpath]
if transformed:
return (record['path'] for record in transformed)
else:
paths = []
#.........这里部分代码省略.........
示例3: TagOrganizer
# 需要导入模块: from PyDbLite import Base [as 别名]
# 或者: from PyDbLite.Base import delete [as 别名]
class TagOrganizer(Organizer):
def __init__(self, cache, category=None):
self.tags = None
self.category = category
Organizer.__init__(self, cache, False)
def reset(self):
if not self.tags:
self.tags = Base(DB_FILE_TAGS)
self.tags.create('realpath', 'category', 'tag', mode = 'override')
self.tags.create_index('realpath')
self.tags.create_index('category')
Organizer.reset(self)
def updatecache(self):
self._generatetags()
Organizer.updatecache(self)
def _deletefromcache(self, path):
realpath = self.realpath(path)
logger.debug("_deletefromcache(%s)" % realpath)
for tag in self.tags.get_index('realpath')[realpath]:
self.tags.delete(tag)
def deletefromcache(self, path):
self._deletefromcache(path)
Organizer.deletefromcache(self, path)
def addtocache(self, path):
self._deletefromcache(path)
self.generatetags(self.realpath(path))
Organizer.addtocache(self, path)
def generatepaths(self, realpath):
for record in self.tags.get_index('realpath')[realpath]:
yield os.path.join(os.sep, record['tag'],
os.path.basename(realpath))
def dirlist(self, path):
if path == '/':
return self.taglist(self.category)
else:
return []
############################################
# Tag functions
def _generatetags(self):
for filename in filter(util.ignoretag, #IGNORE:W0141
self.cache.filelist()):
self.generatetags(filename)
def generatetags(self, filename):
pass
def tag(self, realpath, category, tag):
logger.debug('tag(%s, %s, %s)' % (realpath, category, tag))
if not tag == None and not tag == '':
self.tags.insert(realpath, category, tag)
def filelistbytags(self, category, tags):
self.refreshcache()
for record in self.tags.get_index('category')[category]:
if record['tag'] in tags:
yield os.path.basename(record['realpath'])
def taglist(self, category):
self.refreshcache()
return util.unique([record['tag'] for record in
self.tags.get_index('category')[category]])
示例4: __init__
# 需要导入模块: from PyDbLite import Base [as 别名]
# 或者: from PyDbLite.Base import delete [as 别名]
class BARTSIDEE_CONFIG:
def __init__(self):
self.path_temp = mc.GetTempDir()
self.path_module = os.path.join(CWD, "modules")
if not os.path.exists(self.path_module):
os.makedirs(self.path_module)
sys.path.append(self.path_module)
self.app_version = VERSION
self.db_version = 11
self.initDB()
GA.debug = self.get("debug")
def initDB(self):
self.db = Base("maindb")
self.db.create("id", "data", mode="open")
self.searchdb = Base("searchdb")
self.searchdb.create("module", "id", "timestamp", "data", mode="open")
self.cache = tools.storage()
try:
if len(self.db) < 3:
self.default()
except:
self.default()
records = self.db(id="version")
if records[0]["data"] < self.db_version:
self.default()
def get(self, key):
records = self.db(id=key)
if records:
return records[0]["data"]
else:
return False
def set(self, key, data):
records = self.db(id=key)
if records:
self.db.update(records, data=data)
else:
self.db.insert(id=key, data=data)
self.db.commit()
def default(self):
self.clearDB()
try:
pointer = os.path.join(CWD, "settings.json")
file = open(pointer, "r")
defaults = json.load(file)
file.close()
except:
print traceback.format_exc()
defaults = {}
for key in defaults.keys():
self.db.insert(str(key), defaults[key])
self.db.insert("version", self.db_version)
self.db.commit()
def clearDB(self):
try:
records = self.db()
self.db.delete(records)
except:
self.db.create("id", "data", mode="override")
self.db.commit()
def clearCache(self):
self.cache.empty()
def clearSearch(self):
try:
records = self.searchdb()
self.searchdb.delete(records)
except:
self.searchdb.create("module", "id", "timestamp", "data", mode="override")
self.searchdb.commit()
def clearAll(self):
self.default()
self.clearCache()
self.clearSearch()