Author: dmeyer
Date: Sat Dec  9 14:03:25 2006
New Revision: 2190

Modified:
   trunk/beacon/bin/beacon
   trunk/beacon/src/__init__.py
   trunk/beacon/src/client.py
   trunk/beacon/src/db.py
   trunk/beacon/src/server/server.py

Log:
make it possible to delete a complete media

Modified: trunk/beacon/bin/beacon
==============================================================================
--- trunk/beacon/bin/beacon     (original)
+++ trunk/beacon/bin/beacon     Sat Dec  9 14:03:25 2006
@@ -57,6 +57,8 @@
     print '--monitor          do not exit after search and monitor for changes'
     print '--mount args       mount the query at a given mountpoint (requires 
FUSE)'
     print '--umount dirname   umounts a beacon fuse mountpoint'
+    print '--list-media       lists all known media'
+    print '--del-media media  delete given media from the database'
     print
     print 'Examples for client mode when a server is running:'
     print '  beacon --search dirname=/local/video'
@@ -70,7 +72,8 @@
 
 try:
     # list of modes this script can start in
-    possible_modes = [ 'start', 'stop', 'search', 'info', 'mount', 'umount' ]
+    possible_modes = [ 'start', 'stop', 'search', 'info', 'mount', 'umount',
+                       'list-media', 'del-media']
 
     # read arguments
     opts = [ 'db=', 'fg', 'autoshutdown', 'logfile=', 'verbose=', 'help',
@@ -138,7 +141,7 @@
     os.system('fusermount -u %s' % mountpt)
     sys.exit(0)
     
-if mode in ("search", "info", "mount"):
+if mode in ("search", "info", "mount", "list-media", "del-media"):
     # client info/search mode
 
     try:
@@ -166,6 +169,23 @@
         print "Mount point %s is not a directory" % mountpt
         sys.exit(1)
 
+if mode == 'list-media':
+    for m in kaa.beacon.query(type='media', media='ignore').get():
+        print '%4d %s' % (m['id'], m['name'])
+    sys.exit(0)
+    
+if mode == 'del-media':
+    try:
+        media = int(args.pop(0))
+    except:
+        print 'media must be an int'
+        sys.exit(1)
+    if media == 0:
+        print 'media 0 can\'t be deleted'
+        sys.exit(1)
+    kaa.beacon.delete_media(media)
+    sys.exit(0)
+    
 if mode in ('search', 'mount'):
 
     def progress(cur, total, item):

Modified: trunk/beacon/src/__init__.py
==============================================================================
--- trunk/beacon/src/__init__.py        (original)
+++ trunk/beacon/src/__init__.py        Sat Dec  9 14:03:25 2006
@@ -157,3 +157,14 @@
     while not _client.status == CONNECTED:
         kaa.notifier.step()
     return _client.db.get_db_info()
+
+
+def delete_media(id):
+    """
+    Delete media with the given id.
+    """
+    if not _client:
+        connect()
+    while not _client.status == CONNECTED:
+        kaa.notifier.step()
+    return _client.delete_media(id)

Modified: trunk/beacon/src/client.py
==============================================================================
--- trunk/beacon/src/client.py  (original)
+++ trunk/beacon/src/client.py  Sat Dec  9 14:03:25 2006
@@ -141,6 +141,14 @@
             self.rpc('db.register_track_type_attrs', name, **kwargs)
 
 
+    def delete_media(self, id):
+        """
+        Delete media with the given id.
+        """
+        if self.status != DISCONNECTED:
+            self.rpc('db.media.delete', id)
+
+        
     # -------------------------------------------------------------------------
     # Server connect / disconnect / reconnect handling
     # -------------------------------------------------------------------------

Modified: trunk/beacon/src/db.py
==============================================================================
--- trunk/beacon/src/db.py      (original)
+++ trunk/beacon/src/db.py      Sat Dec  9 14:03:25 2006
@@ -164,10 +164,7 @@
         if 'attr' in query:
             return self._db_query_attr(query)
         if 'type' in query and query['type'] == 'media':
-            m = self._db.query(**query)
-            if m:
-                return m[0]
-            return None
+            return self._db.query(**query)
         return self._db_query_raw(query)
 
 
@@ -670,6 +667,18 @@
         return self._db.get_db_info()
 
 
+    def delete_media(self, id):
+        """
+        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))
+        self._db.commit()
+
+
     # -------------------------------------------------------------------------
     # Internal functions
     # -------------------------------------------------------------------------

Modified: trunk/beacon/src/server/server.py
==============================================================================
--- trunk/beacon/src/server/server.py   (original)
+++ trunk/beacon/src/server/server.py   Sat Dec  9 14:03:25 2006
@@ -225,6 +225,14 @@
         return self._db.register_object_type_attrs('track_%s' % name, **kwargs)
 
 
+    @kaa.rpc.expose('db.media.delete')
+    def delete_media(self, id):
+        """
+        Delete media with the given id.
+        """
+        self._db.delete_media(id)
+
+        
     @kaa.rpc.expose('monitor.directory')
     def monitor_dir(self, directory):
         """

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