Author: dmeyer
Date: Mon Apr 24 16:52:15 2006
New Revision: 1490
Modified:
trunk/beacon/TODO
trunk/beacon/src/db.py
trunk/beacon/src/directory.py
trunk/beacon/src/file.py
Log:
make file mtime checking faster as suggested by Tack
Modified: trunk/beacon/TODO
==============================================================================
--- trunk/beacon/TODO (original)
+++ trunk/beacon/TODO Mon Apr 24 16:52:15 2006
@@ -35,5 +35,4 @@
(that doesn't need to be scanned but needs inotify) we need to
rescan the directory itself.
-A. Make listdir much faster. One idea is to have a fixed list of possible
- extentions that should trigger a new scan.
+A. Move special_exts in File._beacon_mtime to kaa.metadata
Modified: trunk/beacon/src/db.py
==============================================================================
--- trunk/beacon/src/db.py (original)
+++ trunk/beacon/src/db.py Mon Apr 24 16:52:15 2006
@@ -335,7 +335,7 @@
# no disk access is needed.)
pos = -1
- for pos, (f, fullname, overlay, stat_res) in
enumerate(parent._beacon_listdir()):
+ for pos, (f, fullname, overlay, stat_res) in
enumerate(parent._beacon_listdir()[0]):
isdir = stat.S_ISDIR(stat_res[stat.ST_MODE])
if pos == len(items):
# new file at the end
Modified: trunk/beacon/src/directory.py
==============================================================================
--- trunk/beacon/src/directory.py (original)
+++ trunk/beacon/src/directory.py Mon Apr 24 16:52:15 2006
@@ -125,7 +125,7 @@
self._beacon_listdir_cache[0] + 3 > time.time():
# use cached result if we have and caching time is less than
# three seconds ago
- return self._beacon_listdir_cache[1]
+ return self._beacon_listdir_cache[1:]
try:
# Try to list the overlay directory
@@ -140,8 +140,8 @@
fs_results = os.listdir(self.filename)
except OSError, e:
log.warning(e)
- self._beacon_listdir_cache = time.time(), []
- return []
+ self._beacon_listdir_cache = time.time(), [], {}
+ return [], {}
results_file_map = {}
for is_overlay, prefix, results in ((False, self.filename,
fs_results),
@@ -177,8 +177,8 @@
keys.sort()
result = [ results_file_map[x] for x in keys ]
# store in cache
- self._beacon_listdir_cache = time.time(), result
- return result
+ self._beacon_listdir_cache = time.time(), result, results_file_map
+ return result, results_file_map
def __repr__(self):
Modified: trunk/beacon/src/file.py
==============================================================================
--- trunk/beacon/src/file.py (original)
+++ trunk/beacon/src/file.py Mon Apr 24 16:52:15 2006
@@ -84,14 +84,36 @@
mtime of foo.jpg is the sum of the mtime of foo.jpg and foo.jpg.xml
or for foo.mp3 the mtime is the sum of foo.mp3 and foo.jpg.
"""
- search = self._beacon_data['name']
- if search.rfind('.') > 0:
- search = search[:search.rfind('.')]
- mtime = 0
- for basename, filename, overlay, stat_res in \
- self._beacon_parent._beacon_listdir(cache=True):
- if basename.startswith(search):
- mtime += stat_res[stat.ST_MTIME]
+ fullname = self._beacon_data['name']
+ basename, ext = fullname, ''
+ pos = basename.rfind('.')
+ if pos > 0:
+ ext = basename[pos:]
+ basename = basename[:pos]
+
+ # FIXME: move this logic to kaa.metadata. The best way would be to
+ # use the info modules for that kind of information, but we may not
+ # know the type here. This code here is only for testing.
+ # FIXME: this also only supports ext in lower case
+ if ext in ('.avi',):
+ # subtitles for avi + cover
+ special_exts = ( '.srt', '.png', '.jpg' )
+ elif ext in ('.gif', '.png', '.jpg', '.jpeg'):
+ # bins xml files
+ special_exts = ( '.xml', )
+ else:
+ # cover
+ special_exts = ( '.png', '.jpg' )
+
+ listdir_file_map = self._beacon_parent._beacon_listdir(cache=True)[1]
+
+ # calculate the new modification time
+ mtime = listdir_file_map[fullname][3][stat.ST_MTIME]
+ for ext in special_exts:
+ if basename+ext in listdir_file_map:
+ mtime += listdir_file_map[basename+ext][3][stat.ST_MTIME]
+ if fullname+ext in listdir_file_map:
+ mtime += listdir_file_map[fullname+ext][3][stat.ST_MTIME]
return mtime
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog