Author: dmeyer
Date: Sun Oct 29 16:17:12 2006
New Revision: 1936

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

Log:
Recheck images on startup, make sure they are valid.
Also rename 'image' if a file is renamed and the image
is the file itself.


Modified: trunk/beacon/src/crawl.py
==============================================================================
--- trunk/beacon/src/crawl.py   (original)
+++ trunk/beacon/src/crawl.py   Sun Oct 29 16:17:12 2006
@@ -133,6 +133,7 @@
         self._scan_dict = {}
         self._scan_function = None
         self._scan_restart_timer = None
+        self._startup = True
 
 
     def append(self, item):
@@ -212,6 +213,9 @@
                 changes['parent'] = move._beacon_parent._beacon_id
             if item._beacon_data['name'] != move._beacon_data['name']:
                 # New name, set name to item
+                if move._beacon_data['image'] == move._beacon_data['name']:
+                    # update image to new filename
+                    changes['image'] = move._beacon_data['name']
                 changes['name'] = move._beacon_data['name']
             if changes:
                 log.info('move: %s', changes)
@@ -378,6 +382,7 @@
             return
         # crawler finished
         self._scan_function = None
+        self._startup = False
         log.info('crawler %s finished', self.num)
         Crawler.active -= 1
         self.db.commit()
@@ -412,7 +417,7 @@
         log.info('scan directory %s', directory.filename)
 
         # parse directory
-        if parse(self.db, directory):
+        if parse(self.db, directory, check_image=self._startup):
             yield kaa.notifier.YieldContinue
 
         # check if it is still a directory
@@ -429,7 +434,7 @@
             self.monitoring.add(directory.filename, use_inotify=False)
             dirname = os.path.realpath(directory.filename)
             directory = self.db.query(filename=dirname)
-            if parse(self.db, directory):
+            if parse(self.db, directory, check_image=self._startup):
                 yield kaa.notifier.YieldContinue
 
         # add to monitor list using inotify
@@ -444,7 +449,7 @@
                 subdirs.append(child)
                 continue
             # check file
-            counter += parse(self.db, child) * 20
+            counter += parse(self.db, child, check_image=self._startup) * 20
 
             # TODO: If the file is unchanged, check if we have the defined
             # thumbnail generated. If not, do it.
@@ -458,5 +463,5 @@
         # stuff. If all items have the same Artist/Album/Image, set this
         # for the directory, too. Also sum up all 'length' values of the
         # items and set it for directory
-        
+
         yield subdirs

Modified: trunk/beacon/src/parser.py
==============================================================================
--- trunk/beacon/src/parser.py  (original)
+++ trunk/beacon/src/parser.py  Sun Oct 29 16:17:12 2006
@@ -74,7 +74,7 @@
     extention_plugins[ext].append(function)
 
 
-def parse(db, item, store=False):
+def parse(db, item, store=False, check_image=False):
     """
     Main beacon parse function. Return the load this function produced:
     0 == nothing done
@@ -104,7 +104,18 @@
             raise AttributeError('parent for %s has no dbid' % item)
     if item._beacon_data.get('mtime') == mtime:
         log.debug('up-to-date %s' % item)
-        return 0
+        if check_image and item._beacon_data.get('image'):
+            image = item._beacon_data.get('image')
+            if os.path.isfile(image):
+                t = thumbnail.Thumbnail(image, item._beacon_media)
+                if not t.get(thumbnail.LARGE, check_mtime=True):
+                    log.info('create missing image %s for %s', image, item)
+                    t.create(thumbnail.LARGE, thumbnail.PRIORITY_LOW)
+                return 0
+            else:
+                log.info('image "%s" for %s is gone, rescan', image, item)
+        else:
+            return 0
 
     if not item._beacon_id:
         # New file, maybe already added? Do a small check to be sure we don't
@@ -118,7 +129,7 @@
 
     t1 = time.time()
 
-    attributes = { 'mtime': mtime }
+    attributes = { 'mtime': mtime, 'image': None }
     # FIXME: add force parameter from config file:
     # - always force (slow but best result)
     # - never force (faster but maybe wrong)

-------------------------------------------------------------------------
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

Reply via email to