Browse Source

don't push up the doUpdate unless we did something...

[git-p4: depot-paths = "//depot/": change = 822]
v0.3
John-Mark Gurney 19 years ago
parent
commit
0118d07ee4
2 changed files with 22 additions and 7 deletions
  1. +6
    -1
      FSStorage.py
  2. +16
    -6
      ZipStorage.py

+ 6
- 1
FSStorage.py View File

@@ -110,6 +110,7 @@ def dofileadd(cd, parent, path, name):
except: except:
pass pass


#log.msg('testing:', `i`, `fsname`, `fobj`)
klass, kwargs = i(fsname, fobj) klass, kwargs = i(fsname, fobj)
if klass is not None: if klass is not None:
break break
@@ -137,9 +138,11 @@ class FSDirectory(FSObject, StorageFolder):
def doUpdate(self): def doUpdate(self):
# We need to rescan this dir, and see if our children has # We need to rescan this dir, and see if our children has
# changed any. # changed any.
doupdate = False
children = sets.Set(os.listdir(self.FSpath)) children = sets.Set(os.listdir(self.FSpath))
for i in self.pathObjmap.keys(): for i in self.pathObjmap.keys():
if i not in children: if i not in children:
doupdate = True
# delete # delete
self.cd.delItem(self.pathObjmap[i]) self.cd.delItem(self.pathObjmap[i])
del self.pathObjmap[i] del self.pathObjmap[i]
@@ -152,10 +155,12 @@ class FSDirectory(FSObject, StorageFolder):
nf = dofileadd(self.cd, self.id, self.FSpath, i) nf = dofileadd(self.cd, self.id, self.FSpath, i)


if nf is not None: if nf is not None:
doupdate = True
self.pathObjmap[i] = nf self.pathObjmap[i] = nf


# sort our children # sort our children
self.sort(lambda x, y: cmp(x.title, y.title)) self.sort(lambda x, y: cmp(x.title, y.title))


# Pass up to handle UpdateID # Pass up to handle UpdateID
StorageFolder.doUpdate(self) if doupdate:
StorageFolder.doUpdate(self)

+ 16
- 6
ZipStorage.py View File

@@ -17,7 +17,7 @@ import FileDIDL
from DIDLLite import StorageFolder, Item, VideoItem, AudioItem, TextItem, ImageItem, Resource from DIDLLite import StorageFolder, Item, VideoItem, AudioItem, TextItem, ImageItem, Resource
from FSStorage import FSObject, registerklassfun from FSStorage import FSObject, registerklassfun


from twisted.python import threadable, log from twisted.python import log, threadable
from twisted.spread import pb from twisted.spread import pb
from twisted.web import http from twisted.web import http
from twisted.web import server from twisted.web import server
@@ -156,11 +156,11 @@ class ZipFile(ZipItem, Item):
self.mimetype) self.mimetype)
Item.__init__(self, *args, **kwargs) Item.__init__(self, *args, **kwargs)
self.url = '%s/%s' % (self.cd.urlbase, self.id) self.url = '%s/%s' % (self.cd.urlbase, self.id)

def doUpdate(self):
self.res = Resource(self.url, 'http-get:*:%s:*' % self.mimetype) self.res = Resource(self.url, 'http-get:*:%s:*' % self.mimetype)
self.res.size = self.zi.file_size self.res.size = self.zi.file_size
Item.doUpdate(self) def doUpdate(self):
pass


class ZipChildDir(ZipItem, StorageFolder): class ZipChildDir(ZipItem, StorageFolder):
'''This is to represent a child dir of the zip file.''' '''This is to represent a child dir of the zip file.'''
@@ -176,10 +176,12 @@ class ZipChildDir(ZipItem, StorageFolder):
self.pathObjmap = {} self.pathObjmap = {}


def doUpdate(self): def doUpdate(self):
doupdate = False
children = sets.Set(self.hier.keys()) children = sets.Set(self.hier.keys())
for i in self.pathObjmap.keys(): for i in self.pathObjmap.keys():
if i not in children: if i not in children:
# delete # delete
doupdate = True
self.cd.delItem(self.pathObjmap[i]) self.cd.delItem(self.pathObjmap[i])
del self.pathObjmap[i] del self.pathObjmap[i]


@@ -201,9 +203,12 @@ class ZipChildDir(ZipItem, StorageFolder):
self.pathObjmap[i] = self.cd.addItem(self.id, self.pathObjmap[i] = self.cd.addItem(self.id,
klass, i, zf = self.zf, zo = self, klass, i, zf = self.zf, zo = self,
name = pathname, mimetype = mt) name = pathname, mimetype = mt)
doupdate = True


# sort our children # sort our children
self.sort(lambda x, y: cmp(x.title, y.title)) self.sort(lambda x, y: cmp(x.title, y.title))
if doupdate:
StorageFolder.doUpdate(self)


def __repr__(self): def __repr__(self):
return '<ZipChildDir: len: %d>' % len(self.pathObjmap) return '<ZipChildDir: len: %d>' % len(self.pathObjmap)
@@ -216,7 +221,6 @@ def genZipFile(path):
#traceback.print_exc(file=log.logfile) #traceback.print_exc(file=log.logfile)
pass pass


log.msg('trying tar now:', `path`)
try: try:
# Try to see if it's a tar file # Try to see if it's a tar file
if path[-2:] == 'gz': if path[-2:] == 'gz':
@@ -248,9 +252,11 @@ class ZipObject(FSObject, StorageFolder):
self.zip = genZipFile(self.FSpath) self.zip = genZipFile(self.FSpath)
hier = buildNameHier(self.zip.namelist(), self.zip.infolist()) hier = buildNameHier(self.zip.namelist(), self.zip.infolist())


doupdate = False
children = sets.Set(hier.keys()) children = sets.Set(hier.keys())
for i in self.pathObjmap.keys(): for i in self.pathObjmap.keys():
if i not in children: if i not in children:
doupdate = True
# delete # delete
self.cd.delItem(self.pathObjmap[i]) self.cd.delItem(self.pathObjmap[i])
del self.pathObjmap[i] del self.pathObjmap[i]
@@ -272,12 +278,16 @@ class ZipObject(FSObject, StorageFolder):
self.pathObjmap[i] = self.cd.addItem(self.id, self.pathObjmap[i] = self.cd.addItem(self.id,
klass, i, zf = self.zip, zo = self, klass, i, zf = self.zip, zo = self,
name = i, mimetype = mt) name = i, mimetype = mt)
doupdate = True


# sort our children # sort our children
self.sort(lambda x, y: cmp(x.title, y.title)) self.sort(lambda x, y: cmp(x.title, y.title))


if doupdate:
StorageFolder.doUpdate(self)

def __repr__(self): def __repr__(self):
return '<ZipObject: path: %s>' % len(self.path) return '<ZipObject: path: %s>' % self.FSpath


def detectzipfile(path, fobj): def detectzipfile(path, fobj):
try: try:


||||||
x
 
000:0
Loading…
Cancel
Save