50 lines
1.0 KiB
Python
50 lines
1.0 KiB
Python
# Bryan Schumaker (10/1/2010)
|
|
|
|
import libsaria
|
|
import collection
|
|
|
|
from libsaria import data
|
|
|
|
sep = libsaria.path.sep
|
|
walk = libsaria.path.walk
|
|
join = libsaria.path.join
|
|
splitext = libsaria.path.splitext
|
|
|
|
class Library(collection.Collection2):
|
|
def __init__(self):
|
|
collection.Collection2.__init__(self, "DLTree_test")
|
|
self.badfiles = set()
|
|
pass
|
|
|
|
def scan(self, path):
|
|
print "Library scanning %s" % path
|
|
self.reset()
|
|
self.update(path)
|
|
self.save()
|
|
self.disp()
|
|
|
|
def update(self, path):
|
|
badfiles = self.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
|
|
#except Exception, e:
|
|
# print e
|
|
# pass
|