73 lines
1.4 KiB
Python
73 lines
1.4 KiB
Python
# Bryan Schumaker (10/1/2010)
|
|
|
|
import libsaria
|
|
import collection
|
|
|
|
from libsaria import data
|
|
|
|
save = data.save
|
|
load = data.load
|
|
|
|
sep = libsaria.path.sep
|
|
walk = libsaria.path.walk
|
|
join = libsaria.path.join
|
|
splitext = libsaria.path.splitext
|
|
|
|
badfiles = set()
|
|
|
|
def set_badfiles():
|
|
global badfiles
|
|
bf = load("badfiles")
|
|
if bf != None:
|
|
badfiles = bf
|
|
|
|
class Library(collection.Collection):
|
|
def __init__(self):
|
|
collection.Collection.__init__(self, "DLTree_test")
|
|
self.filtered = False
|
|
self.visible = None
|
|
|
|
def scan(self, path):
|
|
print "Library scanning %s" % path
|
|
set_badfiles()
|
|
self.reset()
|
|
self.update(path)
|
|
self.save()
|
|
save(badfiles, "badfiles", "")
|
|
self.disp()
|
|
|
|
def filter(self, text):
|
|
if len(text) > 0:
|
|
self.visible = self.index.filter(text)
|
|
self.filtered = True
|
|
else:
|
|
self.visible = None
|
|
self.filtered = False
|
|
|
|
def is_visible(self, id):
|
|
if self.filtered == False:
|
|
return True
|
|
return id in self.visible
|
|
|
|
def update(self, path):
|
|
global badfiles
|
|
FileRef = libsaria.collection.FileRef
|
|
|
|
for root,dirs,files in walk(path):
|
|
stripped_root = root.strip(sep)
|
|
split_root = stripped_root.split(sep)
|
|
for file in files:
|
|
ext = splitext(file)[1]
|
|
if ext in badfiles:
|
|
continue
|
|
path = join(root, file)
|
|
try:
|
|
ref = FileRef(path)
|
|
except:
|
|
badfiles.add(ext)
|
|
continue
|
|
try:
|
|
self.insert_allocate(split_root + [file], ref)
|
|
except UnicodeEncodeError:
|
|
pass
|