Author: dmeyer
Date: Sat Oct 13 11:07:57 2007
New Revision: 2860
Log:
do not use a global medialist to allow client and server in the same process
Modified:
trunk/beacon/src/__init__.py
trunk/beacon/src/client.py
trunk/beacon/src/db.py
trunk/beacon/src/media.py
trunk/beacon/src/server/controller.py
trunk/beacon/src/server/db.py
trunk/beacon/src/server/hwmon/__init__.py
trunk/beacon/src/server/hwmon/client.py
trunk/beacon/src/server/server.py
Modified: trunk/beacon/src/__init__.py
==============================================================================
--- trunk/beacon/src/__init__.py (original)
+++ trunk/beacon/src/__init__.py Sat Oct 13 11:07:57 2007
@@ -48,7 +48,6 @@
from thumbnail import LARGE as THUMBNAIL_LARGE
from query import register_filter, wrap, Query
from item import Item
-from media import medialist as media
from kaa.db import *
# get logging object
@@ -184,6 +183,17 @@
return _client._db.get_db_info()
+def list_media():
+ """
+ List all media objects.
+ """
+ if not _client:
+ connect()
+ while not _client.is_connected():
+ kaa.notifier.step()
+ return _client._db.medialist
+
+
def delete_media(id):
"""
Delete media with the given id.
Modified: trunk/beacon/src/client.py
==============================================================================
--- trunk/beacon/src/client.py (original)
+++ trunk/beacon/src/client.py Sat Oct 13 11:07:57 2007
@@ -48,7 +48,6 @@
# kaa.beacon imports
from db import Database
from query import Query
-from media import medialist
from item import Item
# get logging object
@@ -350,12 +349,12 @@
self.id = id
self.status = CONNECTED
new_media = []
- medialist.connect(self)
+ self._db.medialist.connect(self)
for id, prop in media:
# in the client medialist.add has to lock the db
# and needs the db.lock rpc which will always result
# in returning an InProgress object.
- async = medialist.add(id, prop)
+ async = self._db.medialist.add(id, prop)
yield async
new_media.append(async.get_result())
self.signals['connect'].emit()
@@ -402,14 +401,14 @@
"""
Notification that the media with the given id changed.
"""
- if medialist.get_by_media_id(id):
+ if self._db.medialist.get_by_media_id(id):
# Update can take a while but it should not matter here.
# The InProgress object can be ignored
- medialist.get_by_media_id(id).update(prop)
+ self._db.medialist.get_by_media_id(id).update(prop)
return
# Adding a media always returns an InProgress object. Attach
# sending the signal to the InProgress return.
- async = medialist.add(id, prop)
+ async = self._db.medialist.add(id, prop)
async.connect_once(self.signals['media.add'].emit, media)
@@ -418,6 +417,6 @@
"""
Notification that the media with the given id was removed.
"""
- media = medialist.remove(id)
+ media = self._db.medialist.remove(id)
if media:
self.signals['media.remove'].emit(media)
Modified: trunk/beacon/src/db.py
==============================================================================
--- trunk/beacon/src/db.py (original)
+++ trunk/beacon/src/db.py Sat Oct 13 11:07:57 2007
@@ -45,7 +45,7 @@
# beacon imports
from item import Item
-from media import medialist
+from media import MediaList
# get logging object
log = logging.getLogger('beacon.db')
@@ -123,6 +123,7 @@
# internal db dir, it contains the real db and the
# overlay dir for the beacon
self._db_directory = dbdir
+ self.medialist = MediaList()
# handle changes in a list and add them to the database
# on commit.
@@ -163,7 +164,7 @@
qlen = len(query)
if not 'media' in query:
# query only media we have right now
- query['media'] = db.QExpr('in', medialist.get_all_beacon_ids())
+ query['media'] = db.QExpr('in',
self.medialist.get_all_beacon_ids())
else:
if query['media'] == 'ignore':
del query['media']
@@ -376,7 +377,7 @@
# now we need a parent
if i['name'] == '':
# root node found, find correct mountpoint
- m = medialist.get_by_beacon_id(i['parent'])
+ m = self.medialist.get_by_beacon_id(i['parent'])
if not m:
raise AttributeError('bad media %s' % str(i['parent']))
return create_directory(i, m)
@@ -428,7 +429,7 @@
counter = 0
timer = time.time()
- for media in medialist:
+ for media in self.medialist:
cache[media._beacon_id] = media
cache[media.root._beacon_id] = media.root
@@ -471,12 +472,12 @@
"""
dirname = os.path.dirname(filename)
basename = os.path.basename(filename)
- m = medialist.get_by_directory(filename)
+ m = self.medialist.get_by_directory(filename)
if not m:
raise AttributeError('mountpoint not found')
if (os.path.isdir(filename) and \
- m != medialist.get_by_directory(dirname)) or filename == '/':
+ m != self.medialist.get_by_directory(dirname)) or filename == '/':
# the filename is the mountpoint itself
e = self._db.query(parent=m._beacon_id, name='')
return create_directory(e[0], m)
Modified: trunk/beacon/src/media.py
==============================================================================
--- trunk/beacon/src/media.py (original)
+++ trunk/beacon/src/media.py Sat Oct 13 11:07:57 2007
@@ -29,7 +29,7 @@
#
# -----------------------------------------------------------------------------
-__all__ = [ 'medialist' ]
+__all__ = [ 'MediaList' ]
# python imports
import os
@@ -249,7 +249,3 @@
Iterate over all media objects.
"""
return self._dict.values().__iter__()
-
-
-# global media list object
-medialist = MediaList()
Modified: trunk/beacon/src/server/controller.py
==============================================================================
--- trunk/beacon/src/server/controller.py (original)
+++ trunk/beacon/src/server/controller.py Sat Oct 13 11:07:57 2007
@@ -36,7 +36,6 @@
# kaa.beacon imports
import hwmon
-from kaa.beacon.media import medialist
from parser import parse
@@ -49,7 +48,7 @@
self._db = db
self._changed = []
hwmon.connect()
- medialist.connect(self)
+ db.medialist.connect(self)
hwmon.set_database(handler, db, rootfs)
# Item callbacks
Modified: trunk/beacon/src/server/db.py
==============================================================================
--- trunk/beacon/src/server/db.py (original)
+++ trunk/beacon/src/server/db.py Sat Oct 13 11:07:57 2007
@@ -43,7 +43,6 @@
# beacon imports
from kaa.beacon.item import Item
-from kaa.beacon.media import medialist
from kaa.beacon.db import Database as RO_Database
# get logging object
Modified: trunk/beacon/src/server/hwmon/__init__.py
==============================================================================
--- trunk/beacon/src/server/hwmon/__init__.py (original)
+++ trunk/beacon/src/server/hwmon/__init__.py Sat Oct 13 11:07:57 2007
@@ -36,9 +36,6 @@
# kaa imports
import kaa.notifier
-# kaa.beacon imports
-from kaa.beacon.media import medialist
-
# kaa.beacon.server.hwmon imports
from client import Client as _Client
Modified: trunk/beacon/src/server/hwmon/client.py
==============================================================================
--- trunk/beacon/src/server/hwmon/client.py (original)
+++ trunk/beacon/src/server/hwmon/client.py Sat Oct 13 11:07:57 2007
@@ -41,7 +41,6 @@
import kaa.rpc
# kaa.beacon imports
-from kaa.beacon.media import medialist
from kaa.beacon.utils import get_title
# get logging object
@@ -85,9 +84,9 @@
# FIXME: check if the device is still valid
id = dev.get('beacon.id')
- if medialist.get_by_media_id(id):
+ if self._db.medialist.get_by_media_id(id):
# already in db
- media = medialist.get_by_media_id(id)
+ media = self._db.medialist.get_by_media_id(id)
media.update(dev)
self.handler.media_changed(media)
return
@@ -107,7 +106,7 @@
self.mount(dev)
return
- m = medialist.add(id, dev)
+ m = self._db.medialist.add(id, dev)
# create overlay directory structure
if not os.path.isdir(m.overlay):
@@ -128,8 +127,8 @@
@kaa.rpc.expose('device.remove')
def _device_remove(self, id):
log.info('remove device %s' % id)
- self.handler.media_removed(medialist.get_by_media_id(id))
- medialist.remove(id)
+ self.handler.media_removed(self._db.medialist.get_by_media_id(id))
+ self._db.medialist.remove(id)
@kaa.rpc.expose('device.changed')
Modified: trunk/beacon/src/server/server.py
==============================================================================
--- trunk/beacon/src/server/server.py (original)
+++ trunk/beacon/src/server/server.py Sat Oct 13 11:07:57 2007
@@ -40,9 +40,6 @@
from kaa.notifier import OneShotTimer, Timer, Callback
from kaa.notifier.url import add_password
-# kaa.beacon imports
-from kaa.beacon.media import medialist
-
# kaa.beacon server imports
import parser
from controller import Controller
@@ -178,7 +175,7 @@
self._next_client += 1
self._clients.append((self._next_client, client, []))
media = []
- for m in medialist:
+ for m in self._db.medialist:
media.append((m.id, m.prop))
client.rpc('connect', self._next_client, self._dbdir, media)
@@ -436,7 +433,7 @@
"""
Eject media with the given id
"""
- dev = medialist.get_by_media_id(id)
+ dev = self._db.medialist.get_by_media_id(id)
if not dev:
log.error('eject: no device %s' % id)
return False
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog