Author: dmeyer
Date: Fri Nov 4 20:08:19 2005
New Revision: 889
Added:
trunk/vfs/src/monitor.py
trunk/vfs/src/parser.py
Removed:
trunk/vfs/src/mediadb.py
Modified:
trunk/vfs/src/client.py
trunk/vfs/src/db.py
trunk/vfs/src/item.py
trunk/vfs/src/server.py
trunk/vfs/test/client.py
trunk/vfs/test/server.py
Log:
first working version
Modified: trunk/vfs/src/client.py
==============================================================================
--- trunk/vfs/src/client.py (original)
+++ trunk/vfs/src/client.py Fri Nov 4 20:08:19 2005
@@ -1,50 +1,47 @@
-import time
from kaa.base import ipc, weakref
-from kaa.notifier import Signal, Callback
+from kaa.notifier import Signal
+
+from db import Database
class Query(object):
- def __init__(self, query, remote_object):
+ def __init__(self, notify, local_db, monitor, query):
self._query = query
- self.remote_object = remote_object
- t1 = time.time()
- self.items = remote_object.execute(__ipc_copy_result=True)
- t2 = time.time()
- print 'init query took %s' % (t2 - t1)
+ self._remote = None
+ self._result = local_db.query(**query)
+ self.id = 0
+ monitor(notify, __ipc_async=self._get_monitor, **query)
+ self._monitor = None
+
+ def _get_monitor(self, (monitor, id)):
+ self._monitor = monitor
+ self.id = id
+ # FIXME: for some strange reasons, monitor is a ProxiedObject None
+ print 'monitor is', monitor, 'id', id
- def update(self):
- self.remote_query.update(__ipc_oneway=True)
+ def get(self):
+ return self._result.get()
- def notify(self, event, *args, **kwargs):
- if event == 'progress':
- print 'progress: %s of %s' % (args[0], args[1])
- return
- if event == 'changed':
- print 'remote object changed'
- t1 = time.time()
- self.items = self.remote_object.execute(__ipc_copy_result=True)
- t2 = time.time()
- print 'update query took %s' % (t2 - t1)
-
+ def notify(self, msg, *args, **kwargs):
+ # TODO: redo the query here and emit signals
+ print msg, args, kwargs
+
class Client(object):
- def __init__(self):
- self._ipc = ipc.IPCClient('vfs')
- self._server = self._ipc.get_object('vfs')
- self._active_queries = []
+ def __init__(self, db):
+ self.monitor = ipc.IPCClient('vfs').get_object('vfs')(db).monitor
+ self._db = Database(db)
+ self._db.read_only = True
+ self._queries = []
- def query(self, **kwargs):
- remote_query = self._server.query(self.notify, **kwargs)
- query = Query(kwargs, remote_query)
- self._active_queries.append(weakref(query))
+ def query(self, **query):
+ query = Query(self.notify, self._db, self.monitor, query)
+ # TODO: clean up dead weakrefs later
+ self._queries.append(weakref(query))
return query
-
- def listdir(self, dirname):
- return self.query(dir=dirname)
- def notify(self, object, *args, **kwargs):
- for q in self._active_queries:
- if not q:
- continue
- if q.remote_object._query == object:
- q.notify(*args, **kwargs)
-
+ def notify(self, id, *args, **kwargs):
+ for query in self._queries:
+ if query and query.id == id:
+ query.notify(*args, **kwargs)
+ return
+ print 'not found'
Modified: trunk/vfs/src/db.py
==============================================================================
--- trunk/vfs/src/db.py (original)
+++ trunk/vfs/src/db.py Fri Nov 4 20:08:19 2005
@@ -1,6 +1,7 @@
import os
import threading
import logging
+import time
import kaa
import kaa.notifier
@@ -13,6 +14,13 @@
# get logging object
log = logging.getLogger('vfs')
+class DatabaseError:
+ def __init__(self, msg):
+ self.msg = msg
+
+ def __str__(self):
+ return self.msg
+
class Database(threading.Thread):
class Query(object):
@@ -21,7 +29,8 @@
self.function = function
self.value = None
self.valid = False
-
+ self.exception = False
+
def __call__(self, *args, **kwargs):
self.db.condition.acquire()
self.db.jobs.append((self, self.function, args, kwargs))
@@ -33,7 +42,7 @@
while not self.valid:
kaa.notifier.step()
return self.value
-
+
def __init__(self, dbdir):
threading.Thread.__init__(self)
self.setDaemon(True)
@@ -41,23 +50,151 @@
self.stopped = False
self.jobs = [ None ]
self.dbdir = dbdir
+ self.read_only = False
+
+ self.changes_lock = threading.Lock()
+ self.changes = []
+
self.start()
+
self.wait()
def __getattr__(self, attr):
+ if attr == '_object_types':
+ return self._db._object_types
+ if attr in ('commit', 'query'):
+ return Database.Query(self, getattr(self, '_' + attr))
return Database.Query(self, getattr(self._db, attr))
-
+
+ def get_dir(self, dirname):
+ if dirname in self._dir_cache:
+ return self._dir_cache[dirname]
+ pdir = self.get_dir(os.path.dirname(dirname))
+ if not pdir:
+ return None
+ parent = ("dir", pdir["id"])
+
+ # TODO: handle dirs on romdrives which don't have '/'
+ # as basic parent
+
+ name = os.path.basename(dirname)
+ current = self._db.query(type="dir", name=name, parent=parent)
+ if not current and self.read_only:
+ return
+ if not current:
+ current = self._db.add_object("dir", name=name, parent=parent)
+ self._db.commit()
+ else:
+ current = current[0]
+ current['url'] = 'file:' + dirname
+ current = Item(current, pdir, self._db)
+ self._dir_cache[dirname] = current
+ self._parent_cache[current.dbid] = current
+ return current
+
+
+ def _commit(self):
+ self.changes_lock.acquire()
+ changes = self.changes
+ self.changes = []
+ self.changes_lock.release()
+ for c in changes:
+ c[0](*c[1], **c[2])
+ self._db.commit()
+
+
+ def _query(self, *args, **kwargs):
+ if not 'dirname' in kwargs:
+ return self._db.query(*args, **kwargs)
+ dirname = os.path.normpath(kwargs['dirname'])
+ del kwargs['dirname']
+
+ parent = self.get_dir(dirname)
+ if parent:
+ files = self._db.query(parent = ("dir", parent["id"]))
+ else:
+ print 'parent not found'
+ files = []
+ parent = dirname + '/'
+
+ fs_listing = os.listdir(dirname)
+
+ # TODO: add OVERLAY_DIR support
+ # Ignore . files
+
+ items = []
+ for f in files[:]:
+ if f['name'] in fs_listing:
+ # file still there
+ fs_listing.remove(f['name'])
+ items.append(Item(f, parent, self))
+ else:
+ # file deleted
+ files.remove(f)
+ # FIXME: remove from database
+
+ for f in fs_listing:
+ # new files
+ items.append(Item(f, parent, self))
+
+ return items
+
+
+ def add_object(self, *args, **kwargs):
+ if 'vfs_immediately' in kwargs:
+ del kwargs['vfs_immediately']
+ return Database.Query(self, self._db.add_object)(*args, **kwargs)
+ self.changes_lock.acquire()
+ self.changes.append((self._db.add_object, args, kwargs))
+ self.changes_lock.release()
+
+
+ def update_object(self, *args, **kwargs):
+ if 'vfs_immediately' in kwargs:
+ del kwargs['vfs_immediately']
+ return Database.Query(self, self._db.update_object)(*args,
**kwargs)
+ self.changes_lock.acquire()
+ self.changes.append((self._db.update_object, args, kwargs))
+ self.changes_lock.release()
+
+
+ def register_object_type_attrs(self, *args, **kwargs):
+ kwargs['name'] = (str, ATTR_KEYWORDS_FILENAME)
+ kwargs['mtime'] = (int, ATTR_SIMPLE)
+ return Database.Query(self,
self._db.register_object_type_attrs)(*args, **kwargs)
+
+
def wait(self):
if not self.jobs:
return
Database.Query(self, None)().get()
+
def run(self):
if not os.path.isdir(self.dbdir):
os.makedirs(self.dbdir)
self._db = db.Database(self.dbdir + '/db')
+
+ self._db.register_object_type_attrs("dir",
+ name = (str, ATTR_KEYWORDS_FILENAME),
+ mtime = (int, ATTR_SIMPLE))
+
+ self._db.register_object_type_attrs("file",
+ name = (str, ATTR_KEYWORDS_FILENAME),
+ mtime = (int, ATTR_SIMPLE))
+
+ root = self._db.query(type="dir", name="/")
+ if not root:
+ root = self._db.add_object("dir", name="/")
+ else:
+ root = root[0]
+ root['url'] = 'file:/'
+ root = Item(root, None, self._db)
+ self._dir_cache = { '/': root }
+ self._parent_cache = { root.dbid: root }
+
# remove dummy job for startup
self.jobs = self.jobs[1:]
@@ -74,77 +211,18 @@
try:
r = None
if function:
+ t1 = time.time()
r = function(*args, **kwargs)
+ t2 = time.time()
callback.value = r
callback.valid = True
kaa.notifier.wakeup()
+ except DatabaseError, e:
+ callback.value = e
+ callback.valid = True
+ callback.exception = True
+ kaa.notifier.wakeup()
except:
log.exception("oops")
callback.valid = True
kaa.notifier.wakeup()
-
-
-class Server(object):
- def __init__(self, dbdir):
- self._db = Database(dbdir)
-
- self.register_object_type_attrs("dir",
- name = (str, ATTR_KEYWORDS_FILENAME),
- mtime = (int, ATTR_SIMPLE))
-
- self.register_object_type_attrs("file",
- name = (str, ATTR_KEYWORDS_FILENAME),
- mtime = (int, ATTR_SIMPLE))
-
- self.register_object_type_attrs("video",
- name = (str, ATTR_KEYWORDS_FILENAME),
- mtime = (int, ATTR_SIMPLE),
- title = (unicode, ATTR_KEYWORDS),
- width = (int, ATTR_SIMPLE),
- height = (int, ATTR_SIMPLE),
- length = (int, ATTR_SIMPLE))
-
- self.register_object_type_attrs("audio",
- name = (str, ATTR_KEYWORDS_FILENAME),
- mtime = (int, ATTR_SIMPLE),
- title = (unicode, ATTR_KEYWORDS),
- artist = (unicode, ATTR_KEYWORDS | ATTR_INDEXED),
- album = (unicode, ATTR_KEYWORDS),
- genre = (unicode, ATTR_INDEXED),
- samplerate = (int, ATTR_SIMPLE),
- length = (int, ATTR_SIMPLE),
- bitrate = (int, ATTR_SIMPLE),
- trackno = (int, ATTR_SIMPLE))
-
- self.register_object_type_attrs("image",
- name = (str, ATTR_KEYWORDS_FILENAME),
- mtime = (int, ATTR_SIMPLE),
- width = (int, ATTR_SEARCHABLE),
- height = (int, ATTR_SEARCHABLE),
- date = (unicode, ATTR_SEARCHABLE))
-
- # TODO: add more known types
-
- root = self._db.query(type="dir", name="/").get()
- if not root:
- root = self._db.add_object("dir", name="/").get()
- print root
- root = self._db.query(type='dir', name='/').get()[0]
- print root
- else:
- root = root[0]
- root['url'] = 'file:/'
- root = Item(root, None, self._db)
- self._dir_cache = { '/': root }
- self._parent_cache = { root.__id__(): root }
-
- def register_object_type_attrs(self, *args, **kwargs):
- return self._db.register_object_type_attrs(*args, **kwargs)
-
-
-print 'a'
-s = Server('xxx')
-
-print 'go'
-print 'go2'
-kaa.main()
Modified: trunk/vfs/src/item.py
==============================================================================
--- trunk/vfs/src/item.py (original)
+++ trunk/vfs/src/item.py Fri Nov 4 20:08:19 2005
@@ -3,33 +3,39 @@
class Item(object):
def __init__(self, data, parent, db):
self.data = data
- self.parent = parent
self.db = db
+ self.parent = None
# self.dirname always ends with a slash
# if the item is a dir, self.filename also ends with a slash
# self.url does not end with a slash (except root)
- # If parent is not set, this is a root node. A root node
- # is always part of the db already
+ # If parent is not set, this is a root node.
+ # A root node is always part of the db already
if not parent:
self.url = 'file:/' + self.data['name']
self.dirname = self.data['name']
self.filename = self.data['name']
self.isdir = True
self.basename = '/'
+ self.dbid = self.data['type'], self.data["id"]
return
if isinstance(self.data, dict):
self.basename = self.data['name']
+ self.dbid = self.data['type'], self.data["id"]
else:
self.basename = self.data
-
- # check if the item s based on a file
- if parent.filename:
- self.url = 'file:/' + parent.filename + self.basename
- self.dirname = parent.filename
- self.filename = parent.filename + self.basename
+ self.dbid = None
+
+ # check if the item is based on a file
+ if not isinstance(parent, str):
+ self.parent = parent
+ parent = parent.filename
+ if parent:
+ self.url = 'file:/' + parent + self.basename
+ self.dirname = parent
+ self.filename = parent + self.basename
if os.path.isdir(self.filename):
self.filename += '/'
self.isdir = True
@@ -39,10 +45,6 @@
# TODO: handle files/parents not based on file:
- def __id__(self):
- return (self.data['type'], self.data["id"])
-
-
def __str__(self):
if isinstance(self.data, str):
return 'new file %s' % self.data
@@ -61,7 +63,7 @@
return None
-# def __del__(self):
-# print 'del %s' % self
+ def __del__(self):
+ print 'del %s' % self
Added: trunk/vfs/src/monitor.py
==============================================================================
--- (empty file)
+++ trunk/vfs/src/monitor.py Fri Nov 4 20:08:19 2005
@@ -0,0 +1,45 @@
+from kaa.notifier import OneShotTimer
+
+import parser
+
+class Notification(object):
+ def __init__(self, remote, id):
+ self.remote = remote
+ self.id = id
+
+ def __call__(self, *args, **kwargs):
+ self.remote(self.id, __ipc_oneway=True, *args, **kwargs)
+
+
+class Monitor(object):
+ """
+ Monitor query for changes and call callback.
+ """
+ NEXT_ID = 1
+ def __init__(self, callback, db, query):
+ self.id = Monitor.NEXT_ID
+ Monitor.NEXT_ID += 1
+ self.callback = Notification(callback, self.id)
+
+ self._db = db
+ self._query = query
+
+ items = []
+ for item in self._db.query(**query).get():
+ mtime = parser.get_mtime(item)
+ if not mtime:
+ continue
+ if isinstance(item.data, dict) and item.data['mtime'] == mtime:
+ continue
+ items.append(item)
+ if items:
+ parser.Checker(self._db, items, self.callback)
+ else:
+ # do this later to make sure the monitor is known to
+ # the remote side
+ OneShotTimer(self.callback, 'progress', 0, 0).start(0)
+
+ def __del__(self):
+ print 'delete monitor', self._query
+
+
Added: trunk/vfs/src/parser.py
==============================================================================
--- (empty file)
+++ trunk/vfs/src/parser.py Fri Nov 4 20:08:19 2005
@@ -0,0 +1,101 @@
+import os
+import stat
+
+from kaa.notifier import Timer
+import kaa.metadata
+
+def get_mtime(item):
+ if not item.filename:
+ print 'no filename == no mtime :('
+ return 0
+
+ mtime = 0
+ if item.isdir:
+ return os.stat(item.filename)[stat.ST_MTIME]
+
+ # mtime is the the mtime for all files having the same
+ # base. E.g. the mtime of foo.jpg is the sum of the
+ # mtimeof foo.jpg and foo.jpg.xml or for foo.mp3 the
+ # mtime is the sum of foo.mp3 and foo.jpg.
+
+ base = os.path.splitext(item.filename)[0]
+
+ # TODO: add overlay support
+
+ # TODO: Make this much faster. We should cache the listdir
+ # and the stat results somewhere, maybe already split by ext
+ # But since this is done in background, this is not so
+ # important right now.
+ files = map(lambda x: item.dirname + x, os.listdir(item.dirname))
+ for f in filter(lambda x: x.startswith(base), files):
+ mtime += os.stat(f)[stat.ST_MTIME]
+ return mtime
+
+
+def parse(db, item):
+ mtime = get_mtime(item)
+ if not mtime:
+ print 'oops, no mtime', item
+ return
+ if isinstance(item.data, dict) and item.data['mtime'] == mtime:
+ print 'up-to-date', item
+ return
+ print 'scan', item
+ attributes = { 'mtime': mtime }
+ metadata = kaa.metadata.parse(item.filename)
+ if isinstance(item.data, dict):
+ type = item.data['type']
+ elif metadata and metadata['media'] and \
+ db._object_types.has_key(metadata['media']):
+ type = metadata['media']
+ elif item.isdir:
+ type = 'dir'
+ else:
+ type = 'file'
+
+ type_list = db._object_types[type]
+ for key in type_list[1].keys():
+ if metadata and metadata.has_key(key) and metadata[key] != None:
+ attributes[key] = metadata[key]
+
+ # TODO: do some more stuff here:
+ # - check metadata for thumbnail or cover (audio) and use kaa.thumb to
store it
+ # - schedule thumbnail genereation with kaa.thumb
+ # - search for covers based on the file (should be done by kaa.metadata)
+ # - maybe the item is now in th db so we can't add it again
+
+ # FIXME: the items are not updated yet, the changes are still in
+ # the queue and will be added to the db on commit.
+
+ if item.dbid:
+ # update
+ db.update_object(item.dbid, **attributes)
+ item.data.update(attributes)
+ else:
+ # create
+ db.add_object(type, name=item.basename, parent=item.parent.dbid,
**attributes)
+ return True
+
+
+class Checker(object):
+ def __init__(self, db, items, notify):
+ self.db = db
+ self.items = items
+ self.max = len(items)
+ self.pos = 0
+ self.notify = notify
+ Timer(self.check).start(0.01)
+
+ def check(self):
+ if not self.items:
+ print 'commit changes'
+ self.db.commit()
+ self.notify('changed')
+ return False
+ self.pos += 1
+ self.notify('progress', self.pos, self.max)
+ item = self.items[0]
+ self.items = self.items[1:]
+ parse(self.db, item)
+ return True
+
Modified: trunk/vfs/src/server.py
==============================================================================
--- trunk/vfs/src/server.py (original)
+++ trunk/vfs/src/server.py Fri Nov 4 20:08:19 2005
@@ -1,198 +1,22 @@
import os
-import stat
-import time
from kaa.base import ipc, weakref
from kaa.base.db import *
-from kaa.notifier import Signal, OneShotTimer, Timer
-import kaa.metadata
-from item import Item
+from db import Database
+from monitor import Monitor
-def get_mtime(item):
- if not item.filename:
- print 'no filename == no mtime :('
- return 0
-
- mtime = 0
- if item.isdir:
- return os.stat(item.filename)[stat.ST_MTIME]
-
- # mtime is the the mtime for all files having the same
- # base. E.g. the mtime of foo.jpg is the sum of the
- # mtimeof foo.jpg and foo.jpg.xml or for foo.mp3 the
- # mtime is the sum of foo.mp3 and foo.jpg.
-
- base = os.path.splitext(item.filename)[0]
-
- # TODO: add overlay support
-
- # TODO: Make this much faster. We should cache the listdir
- # and the stat results somewhere, maybe already split by ext
- # But since this is done in background, this is not so
- # important right now.
- files = map(lambda x: item.dirname + x, os.listdir(item.dirname))
- for f in filter(lambda x: x.startswith(base), files):
- mtime += os.stat(f)[stat.ST_MTIME]
- return mtime
-
-
-def parse(db, item):
- mtime = get_mtime(item)
- if not mtime:
- print 'oops, no mtime', item
- return
- attributes = { 'mtime': mtime }
- metadata = kaa.metadata.parse(item.filename)
- if isinstance(item.data, dict):
- type = item.data['type']
- elif metadata and metadata['media'] and \
- db._object_types.has_key(metadata['media']):
- type = metadata['media']
- elif item.isdir:
- type = 'dir'
- else:
- type = 'file'
-
- type_list = db._object_types[type]
- for key in type_list[1].keys():
- if metadata and metadata.has_key(key) and metadata[key] != None:
- attributes[key] = metadata[key]
-
- # TODO: do some more stuff here:
- # - check metadata for thumbnail or cover (audio) and use kaa.thumb to
store it
- # - schedule thumbnail genereation with kaa.thumb
- # - search for covers based on the file (should be done by kaa.metadata)
- # - maybe the item is now in th db so we can't add it again
- if isinstance(item.data, dict):
- # update
- id = item.data['id']
- db.update_object((type, id), **attributes)
- item.data.update(attributes)
- else:
- # create
- item.data = db.add_object(type, name=item.basename,
- parent=item.parent.__id__(),
- **attributes)
- return True
-
-class Checker(object):
- def __init__(self, db, items, progress, callback):
- self.db = db
- self.items = items
- self.max = len(items)
- self.pos = 0
- self.progress = progress
- self.callback = callback
- Timer(self.check).start(0.01)
-
- def check(self):
- if not self.items:
- self.db.commit()
- self.callback()
- return False
- self.pos += 1
- self.progress(self.pos, self.max)
- item = self.items[0]
- parse(self.db, item)
- self.items = self.items[1:]
- return True
-
-class Query(object):
- def __init__(self, server, db, query):
- self._server = server
- self._db = db
- self._items = []
- self._query = query
-
- def __del__(self):
- print 'DEL'
-
- def check_query(self):
- need_update = []
- for i in self._items:
- if not i.filename:
- # FIXME: handle non file items
- pass
- elif not isinstance(i.data, dict):
- # Never scanned by the db
- need_update.append(i)
- elif get_mtime(i) != i.data['mtime']:
- # updated on disc
- need_update.append(i)
- self.progress(0, len(need_update))
- if need_update:
- Checker(self._db, need_update, self.progress, self.changed)
-
- def progress(self, pos, all):
- self._server.notify(self, 'progress', pos, all, __ipc_oneway=True)
-
- def changed(self):
- self._server.notify(self, 'changed', __ipc_oneway=True)
-
-class DirectoryQuery(Query):
- def __init__(self, server, db, **kwargs):
- Query.__init__(self, server, db, kwargs)
- self.dir = server.get_dir(kwargs['dir'])
-
- def execute(self):
- t1 = time.time()
- self._items = []
- dirname = os.path.normpath(self.dir['url'][5:])
- files = self._db.query(parent = ("dir", self.dir["id"]))
- t2 = time.time()
- fs_listing = os.listdir(dirname)
-
- # TODO: add OVERLAY_DIR support
- # Ignore . files
-
- for f in files[:]:
- if f['name'] in fs_listing:
- # file still there
- fs_listing.remove(f['name'])
- self._items.append(Item(f, self.dir, self._db))
- else:
- # file deleted
- files.remove(f)
- # FIXME: remove from database
-
- for f in fs_listing:
- # new files
- self._items.append(Item(f, self.dir, self._db))
-
-# for i in self._items:
-# print i
- t3 = time.time()
- print 'server query took %s sec, complet op %s sec' % (t2-t1, t3-t1)
- OneShotTimer(self.check_query).start(0.01)
- return self._items
-
-
class Server(object):
def __init__(self, dbdir):
- if not os.path.isdir(dbdir):
- os.makedirs(dbdir)
- self._db = Database(dbdir + '/db')
-
- self.register_object_type_attrs("dir",
- name = (str, ATTR_KEYWORDS),
- mtime = (int, ATTR_SIMPLE))
-
- self.register_object_type_attrs("file",
- name = (str, ATTR_KEYWORDS),
- mtime = (int, ATTR_SIMPLE))
+ self._db = Database(dbdir)
self.register_object_type_attrs("video",
- name = (str, ATTR_KEYWORDS),
- mtime = (int, ATTR_SIMPLE),
title = (unicode, ATTR_KEYWORDS),
width = (int, ATTR_SIMPLE),
height = (int, ATTR_SIMPLE),
length = (int, ATTR_SIMPLE))
self.register_object_type_attrs("audio",
- name = (str, ATTR_KEYWORDS),
- mtime = (int, ATTR_SIMPLE),
title = (unicode, ATTR_KEYWORDS),
artist = (unicode, ATTR_KEYWORDS | ATTR_INDEXED),
album = (unicode, ATTR_KEYWORDS),
@@ -201,77 +25,41 @@
length = (int, ATTR_SIMPLE),
bitrate = (int, ATTR_SIMPLE),
trackno = (int, ATTR_SIMPLE))
-
+
self.register_object_type_attrs("image",
- name = (str, ATTR_KEYWORDS),
- mtime = (int, ATTR_SIMPLE),
width = (int, ATTR_SEARCHABLE),
height = (int, ATTR_SEARCHABLE),
date = (unicode, ATTR_SEARCHABLE))
# TODO: add more known types
-
- root = self._db.query(type="dir", name="/")
- if not root:
- root = self._db.add_object("dir", name="/")
- # FIXME: get current data from database
- root = self._db.query(type='dir', name='/')[0]
- else:
- root = root[0]
- root['url'] = 'file:/'
- root = Item(root, None, self._db)
- self._dir_cache = { '/': root }
- self._parent_cache = { root.__id__(): root }
-
- self._ipc = ipc.IPCServer('vfs')
- self._ipc.signals["client_closed"].connect_weak(self._client_closed)
- self._ipc.register_object(self, "vfs")
- self._active_queries = []
+
+ self._db.commit()
+ self._db.wait()
def register_object_type_attrs(self, *args, **kwargs):
return self._db.register_object_type_attrs(*args, **kwargs)
-
- def query(self, callback, **kwargs):
- if 'dir' in kwargs:
- query = DirectoryQuery(self, self._db, **kwargs)
- else:
- raise AttributeError('query not supported')
- self._active_queries.append((weakref(query), callback))
- return query
-
- def get_dir(self, dirname):
- if dirname in self._dir_cache:
- return self._dir_cache[dirname]
- pdir = self.get_dir(os.path.dirname(dirname))
- print pdir
- parent = ("dir", pdir["id"])
-
- # TODO: handle dirs on romdrives which don't have '/'
- # as basic parent
-
- name = os.path.basename(dirname)
- current = self._db.query(type="dir", name=name, parent=parent)
- if not current:
- current = self._db.add_object("dir", name=name, parent=parent)
- else:
- current = current[0]
- current['url'] = 'file:' + dirname
- current = Item(current, pdir, self._db)
- self._dir_cache[dirname] = current
- self._parent_cache[current.__id__()] = current
- return current
-
- def notify(self, object, *args, **kwargs):
- for local, remote in self._active_queries:
- if local == object:
-# print 'found'
- remote(object._query, *args, **kwargs)
- pass
-
- def _client_closed(self, client):
- pass
-# for signal in self.signals.values():
-# for callback in signal:
-# if ipc.get_ipc_from_proxy(callback) == client:
-# signal.disconnect(callback)
+ def query(self, *args, **kwargs):
+ return self._db.query(*args, **kwargs)
+
+ def monitor(self, callback, **query):
+ monitor = Monitor(callback, self._db, query)
+ return monitor, monitor.id
+
+
+_vfs_db = {}
+
+def connect(dbdir):
+ dbdir = os.path.normpath(os.path.abspath(dbdir))
+ print 'connect to', dbdir
+
+ # TODO: delete databases not used anymore
+
+ if not dbdir in _vfs_db:
+ server = Server(dbdir)
+ # FIXME: use weakref
+ _vfs_db[dbdir] = server
+ return _vfs_db[dbdir]
+
+_ipc = ipc.IPCServer('vfs')
+_ipc.register_object(connect, 'vfs')
Modified: trunk/vfs/test/client.py
==============================================================================
--- trunk/vfs/test/client.py (original)
+++ trunk/vfs/test/client.py Fri Nov 4 20:08:19 2005
@@ -2,6 +2,7 @@
from kaa.notifier import Timer
import sys
import kaa
+import kaa.notifier
import time
def foo():
@@ -12,20 +13,31 @@
def progress(pos, max):
print pos, max
-c = kaa.vfs.client.Client()
+c = kaa.vfs.client.Client('vfsdb')
t1 = time.time()
-l = c.listdir('/home/dmeyer/images/eemshaven/mager')
+#q = c.query(dirname='/home/dmeyer/images/intership/eemshaven/mager/')
+q = c.query(dirname='/home/dmeyer/video')
t2 = time.time()
-print 'client thinks query took %s for %s items' % (t2 - t1, len(l.items))
-#print l
-#for i in l.items:
-# print i
-#l.update(__ipc_async = foo)
-print 'done'
-#l.signals['progress'].connect(progress)
+q.get()
+t3 = time.time()
+for item in q.get():
+ print item
-#print l.update()
+print 'q took %s' % (t2 - t1), (t3 - t1)
-# Timer(foo).start(5)
+# t1 = time.time()
+# l = c.listdir('/home/dmeyer/images/eemshaven/mager')
+# t2 = time.time()
+# print 'client thinks query took %s for %s items' % (t2 - t1, len(l.items))
+# #print l
+# #for i in l.items:
+# # print i
+# #l.update(__ipc_async = foo)
+# print 'done'
+# #l.signals['progress'].connect(progress)
+
+# #print l.update()
+
+# # Timer(foo).start(5)
print 'loop'
kaa.main()
Modified: trunk/vfs/test/server.py
==============================================================================
--- trunk/vfs/test/server.py (original)
+++ trunk/vfs/test/server.py Fri Nov 4 20:08:19 2005
@@ -14,6 +14,5 @@
print g
return True
-guide = kaa.vfs.server.Server("foo")
Timer(do_gc).start(1)
kaa.main()
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog