Author: dmeyer
Date: Wed Jan 10 11:38:31 2007
New Revision: 2374

Modified:
   trunk/beacon/src/server/crawl.py
   trunk/beacon/src/server/parser.py
   trunk/beacon/src/server/utils.py

Log:
handle thumbnail info in the same bursthandler

Modified: trunk/beacon/src/server/crawl.py
==============================================================================
--- trunk/beacon/src/server/crawl.py    (original)
+++ trunk/beacon/src/server/crawl.py    Wed Jan 10 11:38:31 2007
@@ -159,9 +159,8 @@
             self._scan_function.stop()
             self._scan_function = None
             self._scan_stop([], False)
-        # stop inotify and inotify timer
+        # stop inotify
         self._inotify = None
-        self._bursthandler.stop()
         # stop restart timer
         if self._scan_restart_timer:
             self._scan_restart_timer.stop()
@@ -180,7 +179,7 @@
         """
         Callback for inotify.
         """
-        if mask & INotify.MODIFY and self._bursthandler.active(name):
+        if mask & INotify.MODIFY and self._bursthandler.is_growing(name):
             # A file was modified. Do this check as fast as we can because the
             # events may come in bursts when a file is just copied. In this 
case
             # a timer is already active and we can return. It still uses too

Modified: trunk/beacon/src/server/parser.py
==============================================================================
--- trunk/beacon/src/server/parser.py   (original)
+++ trunk/beacon/src/server/parser.py   Wed Jan 10 11:38:31 2007
@@ -46,6 +46,7 @@
 # kaa.beacon imports
 from kaa.beacon import thumbnail
 from kaa.beacon.utils import get_title
+import utils
 
 # get logging object
 log = logging.getLogger('beacon.parser')
@@ -237,7 +238,8 @@
 
     if attributes.get('image'):
         t = thumbnail.Thumbnail(attributes.get('image'), item._beacon_media)
-        if not t.get(thumbnail.LARGE, check_mtime=True):
+        if not t.get(thumbnail.LARGE, check_mtime=True) and \
+               not hasattr(item, 'filename') or 
utils.do_thumbnail(item.filename):
             t.create(thumbnail.LARGE, thumbnail.PRIORITY_LOW)
 
     if not metadata.get('title'):

Modified: trunk/beacon/src/server/utils.py
==============================================================================
--- trunk/beacon/src/server/utils.py    (original)
+++ trunk/beacon/src/server/utils.py    Wed Jan 10 11:38:31 2007
@@ -29,32 +29,42 @@
 #
 # -----------------------------------------------------------------------------
 
-__all__ = [ 'BurstHandler' ]
+__all__ = [ 'BurstHandler', 'do_thumbnail' ]
 
 # kaa imports
 import kaa.notifier
 
-class BurstHandler(dict):
+class BurstHandler(object):
+    """
+    Monitor growing files.
+    """
+
+    _all_instances = []
 
     def __init__(self, interval, callback):
         self._ts = {}
+        self._thumb = {}
         self._timer = kaa.notifier.WeakTimer(self._poll)
         self._timer.start(interval)
         self._callback = callback
-
-
-    def stop(self):
-        self._timer.stop()
-        self._ts = {}
+        self._all_instances.append(self)
 
 
     def remove(self, name):
-        if not name in self._ts:
-            return
-        del self._ts[name]
+        """
+        Remove a file from the list of growing files.
+        """
+        if name in self._ts:
+            del self._ts[name]
+        if name in self._thumb:
+            del self._thumb[name]
 
 
-    def active(self, name):
+    def is_growing(self, name):
+        """
+        Return True if the file is growing. Detection is based on the
+        frequency this function is called.
+        """
         if not name in self._ts:
             self._ts[name] = False
             return False
@@ -62,8 +72,36 @@
         return True
 
 
+    def _do_thumbnail(self, name):
+        """
+        Check if a thumbnail should be created.
+        """
+        if not name in self._ts:
+            # not in the list of growing files
+            return True
+        if not name in self._thumb:
+            self._thumb[name] = 0
+            # first time is always ok
+            return True
+        self._thumb[name] += 1
+        return (self._thumb[name] % 10) == 0
+
+
     def _poll(self):
+        """
+        Run callback on all growing files.
+        """
         ts = self._ts
         self._ts = {}
         for name in [ name for name, needed in ts.items() if needed ]:
             self._callback(name)
+
+
+def do_thumbnail(name):
+    """
+    Global function to check if a thumbnail should be created.
+    """
+    for i in BurstHandler._all_instances:
+        if i._do_thumbnail(name):
+            return True
+    return False

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to