Author: dmeyer
Date: Fri Apr 21 20:23:28 2006
New Revision: 1439

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

Log:
make it possible for an item to change the type

Modified: trunk/beacon/src/db.py
==============================================================================
--- trunk/beacon/src/db.py      (original)
+++ trunk/beacon/src/db.py      Fri Apr 21 20:23:28 2006
@@ -530,6 +530,35 @@
             self.commit()
 
 
+    def update_object_type(self, (type, id), new_type):
+        old_entry = self._db.query(type=type, id=id)
+        if not old_entry:
+            # already changed by something
+            return None
+        old_entry = old_entry[0]
+
+        # copy metadata to new object
+        metadata = {}
+        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)):
+            log.warning('untested code: mode parent for %s' % child)
+            self._db.update_object((child['type'], child['id']), 
parent=new_beacon_id)
+
+        # delete old and sync the db again
+        self.delete_object((type, id))
+        self.commit()
+        return metadata
+
+    
     def delete_object(self, (type, id), beacon_immediately=False):
         self.changes.append(('delete', (type, id), {}))
         if len(self.changes) > MAX_BUFFER_CHANGES or beacon_immediately:

Modified: trunk/beacon/src/parser.py
==============================================================================
--- trunk/beacon/src/parser.py  (original)
+++ trunk/beacon/src/parser.py  Fri Apr 21 20:23:28 2006
@@ -86,9 +86,7 @@
     log.info('scan %s' % item)
     attributes = { 'mtime': mtime }
     metadata = kaa.metadata.parse(item.filename)
-    if item._beacon_data.has_key('type'):
-        type = item._beacon_data['type']
-    elif metadata and metadata['media'] and \
+    if metadata and metadata['media'] and \
              db.object_types().has_key(metadata['media']):
         type = metadata['media']
     elif item._beacon_isdir:
@@ -96,6 +94,16 @@
     else:
         type = 'file'
 
+    if item._beacon_id and type != item._beacon_id[0]:
+        # The item changed its type. Adjust the db
+        data = db.update_object_type(item._beacon_id, type)
+        if not data:
+            log.warning('item to change not in the db anymore, try to find it')
+            data = db.get_object(item._beacon_data['name'], parent._beacon_id)
+        log.info('change item %s to %s' % (item._beacon_id, type))
+        item._beacon_database_update(data)
+
+
     if type == 'dir':
         for cover in ('cover.jpg', 'cover.png'):
             if os.path.isfile(item.filename + cover):


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