Author: dmeyer
Date: Thu Jun 28 20:00:43 2007
New Revision: 2746

Modified:
   trunk/WIP/beacon2/src/db.py
   trunk/WIP/beacon2/src/server/crawl.py
   trunk/WIP/beacon2/src/server/hwmon/client.py
   trunk/WIP/beacon2/src/server/monitor.py
   trunk/WIP/beacon2/src/server/parser.py
   trunk/WIP/beacon2/src/server/server.py

Log:
commit cleanup

Modified: trunk/WIP/beacon2/src/db.py
==============================================================================
--- trunk/WIP/beacon2/src/db.py (original)
+++ trunk/WIP/beacon2/src/db.py Thu Jun 28 20:00:43 2007
@@ -136,10 +136,6 @@
         query functions ins this class depending on the query. This function
         may raise an AsyncProcess exception.
         """
-        # make sure db is ok
-        if not self.client:
-            self.commit()
-
         qlen = len(query)
         if not 'media' in query:
             # query only media we have right now
@@ -461,30 +457,25 @@
     # (Except get_db_info which is only for debugging)
     # -------------------------------------------------------------------------
 
-    def commit(self, force=False):
+    def commit(self):
         """
         Commit changes to the database. All changes in the internal list
         are done first.
         """
-        if self.client or (not self.changes and not force):
-            return
-
-        # get time for debugging
-        t1 = time.time()
-        # set internal variables
-        changes = self.changes
-        self.changes = []
-
+        if self.client:
+            raise RuntimeError('unable to commit for a client')
+        
         # db commit
-        t2 = time.time()
+        t1 = time.time()
         self._db.commit()
-        t3 = time.time()
-
-        # NOTE: Database is unlocked again
+        t2 = time.time()
 
         # some time debugging
-        log.info('db.commit %d items; %.5fs (kaa.db commit %.5f / %.2f%%)' % \
-                 (len(changes), t3-t1, t3-t2, (t3-t2)/(t3-t1)*100.0))
+        log.info('db.commit %d items; kaa.db commit %.5f' % \
+                 (len(changes), t2-t1)
+        changes = self.changes
+        self.changes = []
+
         # fire db changed signal
         self.signals['changed'].emit(changes)
 
@@ -524,8 +515,6 @@
 
         if 'media' in kwargs:
             del kwargs['media']
-        if isinstance(kwargs.get('media'), str):
-            raise SystemError
         self._db.update_object((type, id), **kwargs)
         self.changes.append((type, id))
         if len(self.changes) > MAX_BUFFER_CHANGES:
@@ -548,12 +537,9 @@
         for key in self._db._object_types[new_type][1].keys():
             if not key == 'id' and key in old_entry:
                 metadata[key] = old_entry[key]
-        # add object to db keep the db in sync
-        self.commit()
 
         metadata = self._db.add_object(new_type, **metadata)
         new_beacon_id = (type, metadata['id'])
-        self._db.commit()
 
         # move all children to new parent
         for child in self._db.query(parent=(type, id)):
@@ -563,7 +549,6 @@
 
         # delete old and sync the db again
         self.delete_object((type, id))
-        self.commit()
         return metadata
 
 
@@ -613,7 +598,6 @@
         Delete media with the given id.
         """
         log.info('delete media %s', id)
-        self.commit()
         for child in self._db.query(media = id):
             self._db.delete_object((str(child['type']), child['id']))
         self._db.delete_object(('media', id))

Modified: trunk/WIP/beacon2/src/server/crawl.py
==============================================================================
--- trunk/WIP/beacon2/src/server/crawl.py       (original)
+++ trunk/WIP/beacon2/src/server/crawl.py       Thu Jun 28 20:00:43 2007
@@ -99,7 +99,7 @@
         Init the Crawler.
         Parameter db is a beacon.db.Database object.
         """
-        self.db = db
+        self._db = db
         Crawler.nextid += 1
         self.num = Crawler.nextid
 
@@ -193,7 +193,7 @@
         # some debugging to find a bug in beacon
         log.info('inotify: event %s for "%s"', mask, name)
         
-        item = self.db.query(filename=name)
+        item = self._db.query(filename=name)
         if isinstance(item, kaa.notifier.InProgress):
             yield item
             item = item()
@@ -217,7 +217,7 @@
 
         if mask & INotify.MOVE and args and item._beacon_id:
             # Move information with source and destination
-            move = self.db.query(filename=args[0])
+            move = self._db.query(filename=args[0])
             if isinstance(move, kaa.notifier.InProgress):
                 yield move
                 move = move()
@@ -228,13 +228,13 @@
                 yield True
 
             # FIXME: ACTIVE WAITING:
-            while self.db.read_lock:
+            while self._db.read_lock:
                 yield kaa.notifier.YieldContinue
 
             if move._beacon_id:
                 # New item already in the db, delete it first
                 log.info('inotify delete: %s', item)
-                self.db.delete_object(move)
+                self._db.delete_object(move)
             changes = {}
             if item._beacon_parent._beacon_id != 
move._beacon_parent._beacon_id:
                 # Different directory, set new parent
@@ -248,8 +248,7 @@
                 changes['name'] = move._beacon_data['name']
             if changes:
                 log.info('inotify: move: %s', changes)
-                self.db.update_object(item._beacon_id, **changes)
-            self.db.commit()
+                self._db.update_object(item._beacon_id, **changes)
 
             # Now both directories need to be checked again
             self._scan_add(item._beacon_parent, recursive=False)
@@ -315,10 +314,10 @@
         # The file does not exist, we need to delete it in the database
 
         # FIXME: ACTIVE WAITING:
-        while self.db.read_lock:
+        while self._db.read_lock:
             yield kaa.notifier.YieldContinue
         log.info('inotify: delete %s', item)
-        self.db.delete_object(item)
+        self._db.delete_object(item)
 
         # remove directory and all subdirs from the inotify. The directory
         # is gone, so all subdirs are invalid, too.
@@ -409,10 +408,14 @@
         # crawler finished
         self._scan_function = None
         self._startup = False
-        log.info('crawler %s finished; took %0.1f seconds.', self.num, 
time.time() - self._crawl_start_time)
+        log.info('crawler %s finished; took %0.1f seconds.', \
+                 self.num, time.time() - self._crawl_start_time)
         self._crawl_start_time = None
         Crawler.active -= 1
-        self.db.commit()
+
+        # commit changes so that the client may get notified
+        self._db.commit()
+
         if not self._inotify:
             # Inotify is not in use. This means we have to start crawling
             # the filesystem again in 10 seconds using the restart function.
@@ -456,7 +459,7 @@
             yield []
             
         # parse directory
-        async = parse(self.db, directory, check_image=self._startup)
+        async = parse(self._db, directory, check_image=self._startup)
         if isinstance(async, kaa.notifier.InProgress):
             yield async
 
@@ -473,11 +476,11 @@
             # list and with inotify using the realpath (later)
             self.monitoring.add(directory.filename, use_inotify=False)
             dirname = os.path.realpath(directory.filename)
-            directory = self.db.query(filename=dirname)
+            directory = self._db.query(filename=dirname)
             if isinstance(directory, kaa.notifier.InProgress):
                 yield directory
                 directory = directory()
-            async = parse(self.db, directory, check_image=self._startup)
+            async = parse(self._db, directory, check_image=self._startup)
             if isinstance(async, kaa.notifier.InProgress):
                 yield async
 
@@ -488,7 +491,7 @@
         subdirs = []
         counter = 0
 
-        result = self.db.query(parent=directory)
+        result = self._db.query(parent=directory)
         if isinstance(result, kaa.notifier.InProgress):
             yield result
             result = result()
@@ -498,7 +501,7 @@
                 subdirs.append(child)
                 continue
             # check file
-            async = parse(self.db, child, check_image=self._startup) * 20
+            async = parse(self._db, child, check_image=self._startup) * 20
             if isinstance(async, kaa.notifier.InProgress):
                 yield async
                 async = async()
@@ -531,7 +534,7 @@
         check_attr = data.keys()[:]
         check_attr.remove('length')
 
-        result = self.db.query(parent=directory)
+        result = self._db.query(parent=directory)
         if isinstance(result, kaa.notifier.InProgress):
             yield result
             result = result()
@@ -574,11 +577,11 @@
             data['image_from_items'] = True
 
         # FIXME: ACTIVE WAITING:
-        while self.db.read_lock:
+        while self._db.read_lock:
             yield kaa.notifier.YieldContinue
 
         # update directory in database
-        self.db.update_object(directory._beacon_id, **data)
+        self._db.update_object(directory._beacon_id, **data)
         directory._beacon_data.update(data)
 
         # check parent

Modified: trunk/WIP/beacon2/src/server/hwmon/client.py
==============================================================================
--- trunk/WIP/beacon2/src/server/hwmon/client.py        (original)
+++ trunk/WIP/beacon2/src/server/hwmon/client.py        Thu Jun 28 20:00:43 2007
@@ -159,14 +159,12 @@
                                      parent=('media', mid),
                                      
title=unicode(get_title(metadata['label'])),
                                      media = mid)['id']
-            self.db.commit(force=True)
             for track in metadata.tracks:
                 self.db.add_object('track_%s' % type, name='%02d' % 
track.trackno,
                                    parent=('video', vid), media=mid,
                                    mtime=0, chapters=track.chapters, 
length=track.length,
                                    audio=[ x.convert() for x in track.audio ],
                                    subtitles=[ x.convert() for x in 
track.subtitles ])
-            self.db.commit()
         elif dev.get('volume.disc.has_audio') and metadata:
             # Audio CD
             log.info('detect %s as audio cd' % id)
@@ -178,7 +176,6 @@
                                      artist = metadata.get('artist'),
                                      parent=('media', mid),
                                      media = mid)['id']
-            self.db.commit(force=True)
             for track in metadata.tracks:
                 self.db.add_object('track_cdda', name=str(track.trackno),
                                    title=track.get('title'),
@@ -187,8 +184,6 @@
                                    parent=('audio', aid),
                                    media=mid,
                                    mtime=0)
-            self.db.commit()
-
         else:
             log.info('detect %s as normal filesystem' % id)
             mid = self.db.add_object("media", name=id, content='file')['id']
@@ -199,5 +194,4 @@
                                      name="",
                                      parent=('media', mid),
                                      media=mid, mtime=mtime)
-            self.db.commit(force=True)
         self._device_add(dev)

Modified: trunk/WIP/beacon2/src/server/monitor.py
==============================================================================
--- trunk/WIP/beacon2/src/server/monitor.py     (original)
+++ trunk/WIP/beacon2/src/server/monitor.py     Thu Jun 28 20:00:43 2007
@@ -253,6 +253,7 @@
             if not self._running:
                 break
 
+        # commit changes so that the client may get notified
         self._db.commit()
 
         # The client will update its query on this signal, so it should

Modified: trunk/WIP/beacon2/src/server/parser.py
==============================================================================
--- trunk/WIP/beacon2/src/server/parser.py      (original)
+++ trunk/WIP/beacon2/src/server/parser.py      Thu Jun 28 20:00:43 2007
@@ -86,7 +86,7 @@
     extention_plugins[ext].append(function)
 
 
-def parse(db, item, store=False, check_image=False):
+def parse(db, item, check_image=False):
     """
     Main beacon parse function. Return the load this function produced:
     0 == nothing done
@@ -119,11 +119,11 @@
         else:
             return 0
 
-    return _parse(db, item, mtime, store)
+    return _parse(db, item, mtime)
 
 
 @kaa.notifier.yield_execution()
-def _parse(db, item, mtime, store):
+def _parse(db, item, mtime):
 
     # FIXME: ACTIVE WAITING:
     while db.read_lock:
@@ -131,14 +131,10 @@
 
     parent = item._beacon_parent
     if not parent._beacon_id:
-        # There is a parent without id, update the parent now. We know that the
-        # parent should be in the db, so commit and it should work
-        db.commit()
-        if not parent._beacon_id:
-            # Still not in the database? Well, this should never happen but 
does
-            # when we use some strange softlinks around the filesystem. So in
-            # that case we need to scan the parent, too.
-            parse(db, parent, True)
+        # There is a parent without id, update the parent now.
+        r = parse(db, parent)
+        if isinstance(r, kaa.notifier.InProgress):
+            yield r
         if not parent._beacon_id:
             # This should never happen
             raise AttributeError('parent for %s has no dbid' % item)
@@ -265,10 +261,6 @@
         log.warning('change %s to %s for %s', item._beacon_id, type, item)
         db.delete_object(item._beacon_id)
         item._beacon_id = None
-        db.commit()
-
-    # Note: the items are not updated yet, the changes are still in
-    # the queue and will be added to the db on commit.
 
     if item._beacon_id:
         # Update
@@ -288,7 +280,6 @@
     if hasattr(metadata, 'tracks'):
         # The item has tracks, e.g. a dvd image on hd. Sync with the database
         # now and add the tracks.
-        db.commit()
         if not metadata.get('type'):
             log.error('%s metadata has no type', item)
             yield produced_load
@@ -309,10 +300,6 @@
                           parent=item._beacon_id,
                           media=item._beacon_media._beacon_id[1],
                           mtime=0, metadata=track)
-        db.commit()
-
-    if store:
-        db.commit()
 
     log.info('scan %s (%0.3f)' % (item, time.time() - t1))
     yield produced_load

Modified: trunk/WIP/beacon2/src/server/server.py
==============================================================================
--- trunk/WIP/beacon2/src/server/server.py      (original)
+++ trunk/WIP/beacon2/src/server/server.py      Thu Jun 28 20:00:43 2007
@@ -261,7 +261,6 @@
         Monitor a directory in the background. One directories with a monitor
         running will update running query monitors.
         """
-        self._db.commit()
         if not os.path.isdir(directory):
             log.warning("monitor_dir: %s is not a directory." % directory)
             yield False
@@ -278,10 +277,9 @@
                 break
             items.append(i)
         while items:
-            async = parser.parse(self._db, items.pop(), store=True)
+            async = parser.parse(self._db, items.pop())
             if isinstance(async, kaa.notifier.InProgress):
                 yield async
-        self._db.commit()
         log.info('monitor %s on %s', directory, data._beacon_media)
         data._beacon_media.crawler.append(data)
 
@@ -341,6 +339,7 @@
             yield kaa.notifier.YieldContinue
         for dbid, attributes in items:
             self._db.update_object(dbid, **attributes)
+        # commit to update monitors
         self._db.commit()
 
 
@@ -350,7 +349,6 @@
         """
         Request item data.
         """
-        self._db.commit()
         data = self._db.query(filename=filename)
         if isinstance(data, kaa.notifier.InProgress):
             yield data
@@ -361,10 +359,9 @@
                 break
             items.append(i)
         while items:
-            async = parser.parse(self._db, items.pop(), store=True)
+            async = parser.parse(self._db, items.pop())
             if isinstance(async, kaa.notifier.InProgress):
                 yield async
-        self._db.commit()
         yield data._beacon_data
 
 

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to