Author: dmeyer
Date: Fri Feb 17 21:42:05 2006
New Revision: 1190

Modified:
   trunk/WIP/vfs/src/client.py
   trunk/WIP/vfs/src/db.py
   trunk/WIP/vfs/src/monitor.py
   trunk/WIP/vfs/src/parser.py
   trunk/WIP/vfs/src/query.py
   trunk/WIP/vfs/src/server.py

Log:
again, more updates, cache working now

Modified: trunk/WIP/vfs/src/client.py
==============================================================================
--- trunk/WIP/vfs/src/client.py (original)
+++ trunk/WIP/vfs/src/client.py Fri Feb 17 21:42:05 2006
@@ -36,6 +36,7 @@
 
 # Python imports
 import os
+import copy
 import logging
 
 # kaa imports
@@ -87,15 +88,19 @@
     def query(self, **query):
         result = Query(self, **query)
         self._queries.append(weakref(result))
-        if 'parent' in query:
-            query['parent'] = query['parent']._vfs_id
         return result
     
+
     def monitor(self, query, status):
         """
         Monitor a query
         """
-        self._server_monitor(self.id, query.id, query._query, status,
+        q = None
+        if status:
+            q = copy.copy(query._query)
+            if 'parent' in q:
+                q['parent'] = q['parent']._vfs_id
+        self._server_monitor(self.id, query.id, q,
                              __ipc_noproxy_args=True, __ipc_oneway=True)
         
 #     def query(self, **query):
@@ -137,7 +142,6 @@
         dependencies. So this function is needed to find the correct Query
         for a request.
         """
-        print 'NOTIFY', id, msg
         for query in self._queries:
             if query and query.id == id:
                 if hasattr(query, '_vfs_%s' % msg):

Modified: trunk/WIP/vfs/src/db.py
==============================================================================
--- trunk/WIP/vfs/src/db.py     (original)
+++ trunk/WIP/vfs/src/db.py     Fri Feb 17 21:42:05 2006
@@ -311,8 +311,12 @@
         A query to get all files in a directory.
         """
         dirname = parent.filename[:-1]
-        items = [ create_file(f, parent) for f in \
-                  self._db.query(parent = parent._vfs_id) ]
+        items = []
+        for i in self._db.query(parent = parent._vfs_id):
+            if i['type'] == 'dir':
+                items.append(create_dir(i, parent))
+            else:
+                items.append(create_file(i, parent))
         # sort items based on url. The listdir is also sorted, that makes
         # checking much faster
         items.sort(lambda x,y: cmp(x._vfs_name, y._vfs_name))
@@ -386,7 +390,7 @@
         Internal query function inside the thread. This function will use the
         corrent internal query function based on special keywords.
         """
-        print 'QUERY', query
+#         print 'QUERY', query
         # make sure db is ok
         self.commit()
         

Modified: trunk/WIP/vfs/src/monitor.py
==============================================================================
--- trunk/WIP/vfs/src/monitor.py        (original)
+++ trunk/WIP/vfs/src/monitor.py        Fri Feb 17 21:42:05 2006
@@ -64,7 +64,7 @@
     """
 
     def __init__(self, callback, db, server, id, query):
-        log.info('create new monitor %s', id)
+        log.debug('create new monitor %s' % id)
         self.id = id
         self.callback = Notification(callback, self.id)
         self._server = server
@@ -99,30 +99,28 @@
             return True
         current = self._db.query(**self._query)
         if len(current) != len(self.items):
-            self.callback('changed')
             self.items = current
-            self._scan()
+            self._scan(False)
             return True
         for pos, c in enumerate(current):
             if self.items[pos].url != c.url:
                 self.items = current
-                self._scan()
-                self.callback('changed')
+                self._scan(False)
                 return True
         return True
 
 
-    def _scan(self, notify=False):
-        self._scan_step(self.items[:], [], notify)
+    def _scan(self, first_call):
+        self._scan_step(self.items[:], [], first_call)
 
         
     @execute_in_timer(Timer, 0.001, type='once')
-    def _scan_step(self, items, changed, notify):
+    def _scan_step(self, items, changed, first_call):
         """
         Find changed items in 'items' and add them to changed.
         """
         if not items:
-            self._update(changed, notify)
+            self._update(changed, first_call)
             return False
         c = 0
         while items:
@@ -136,9 +134,17 @@
         return True
 
 
-    def _update(self, changed, notify):
-        self._checker = weakref(parser.Checker(weakref(self), self._db, 
changed, notify))
-
+    def _update(self, changed, first_call):
+        if changed:
+            c = parser.Checker(weakref(self), self._db, changed, first_call)
+            self._checker = weakref(c)
+            if not first_call and len(changed) > 10:
+                self.callback('changed')
+        elif first_call:
+            self.callback('checked')
+        else:
+            self.callback('changed')
+            
 
     def send_update(self, changed):
         changed = [ (x.url, x._vfs_data) for x in changed ]
@@ -202,4 +208,4 @@
 
 
     def __del__(self):
-        log.debug('del %s', repr(self))
+        log.debug('del %s' % repr(self))

Modified: trunk/WIP/vfs/src/parser.py
==============================================================================
--- trunk/WIP/vfs/src/parser.py (original)
+++ trunk/WIP/vfs/src/parser.py Fri Feb 17 21:42:05 2006
@@ -39,7 +39,7 @@
 import logging
 
 # kaa imports
-from kaa.notifier import Timer
+from kaa.notifier import Timer, execute_in_timer
 import kaa.metadata
 
 # kaa.vfs imports
@@ -49,7 +49,7 @@
 log = logging.getLogger('vfs')
 
 def parse(db, item, store=False):
-    print 'check', item
+    print 'check', item.url
     mtime = item._vfs_mtime()
     if not mtime:
         log.info('oops, no mtime %s' % item)
@@ -112,17 +112,18 @@
 
 
 class Checker(object):
-    def __init__(self, monitor, db, items, notify):
+    def __init__(self, monitor, db, items, notify_checked):
         self.monitor = monitor
         self.db = db
         self.items = items
         self.max = len(items)
         self.pos = 0
         self.updated = []
-        self.do_notify = notify
-        Timer(self.check).start(0.01)
+        self.notify_checked = notify_checked
+        self.check()
 
 
+    @execute_in_timer(Timer, 0.01)
     def check(self):
 
         if self.items:
@@ -139,13 +140,12 @@
 
         if not self.items:
             self.db.commit()
-            if self.monitor:
-                self.monitor.callback('changed')
-            if self.monitor and self.do_notify:
-                self.monitor.callback('checked')
+            self.notify('changed')
+            if self.notify_checked:
+                self.notify('checked')
 
         updated = []
-        while self.updated and self.updated[0]._vfs_id:
+        while self.updated and self.updated[0] and self.updated[0]._vfs_id:
             updated.append(self.updated.pop(0))
         if updated:
             self.monitor.send_update(updated)
@@ -158,3 +158,6 @@
     def notify(self, *args, **kwargs):
         if self.monitor:
             self.monitor.callback(*args, **kwargs)
+
+#     def __del__(self):
+#         print 'del parser'

Modified: trunk/WIP/vfs/src/query.py
==============================================================================
--- trunk/WIP/vfs/src/query.py  (original)
+++ trunk/WIP/vfs/src/query.py  Fri Feb 17 21:42:05 2006
@@ -61,10 +61,15 @@
         self.result = self._client.database.query(**query)
     
 
-    def monitor(status=True):
+    def monitor(self, status=True):
+        """
+        Turn on/off query mnitoring
+        """
         if self._monitor == status:
             return
         self._client.monitor(self, status)
+        self._monitor = status
+
         
     def _vfs_progress(self, pos, max, url):
         """
@@ -78,6 +83,7 @@
         """
         Checked message from server.
         """
+        self.signals['up-to-date'].emit()
         return
 
 
@@ -85,7 +91,7 @@
         """
         Checked message from server.
         """
-        print 'UPDATE'
+#         print 'UPDATE'
         url, data = items.pop(0)
         for r in self.result:
             if r.url == url:
@@ -99,6 +105,7 @@
 
     def _vfs_changed(self):
         self.result = self._client.database.query(**self._query)
+        self.signals['changed'].emit()
 
         
     def __repr__(self):

Modified: trunk/WIP/vfs/src/server.py
==============================================================================
--- trunk/WIP/vfs/src/server.py (original)
+++ trunk/WIP/vfs/src/server.py Fri Feb 17 21:42:05 2006
@@ -132,12 +132,11 @@
         return self._db.register_object_type_attrs('track_%s' % name, **kwargs)
 
 
-    def monitor(self, client_id, request_id, status, query):
+    def monitor(self, client_id, request_id, query):
         """
         Create a monitor object to monitor a query for a client.
         """
-        print 'MONITOR', client_id, request_id, query, status
-        if 'parent' in query:
+        if query and 'parent' in query:
             type, id = query['parent']
             query['parent'] = self._db.query(type=type, id=id)[0]
 
@@ -146,8 +145,8 @@
                 break
         else:
             raise AttributeError('Unknown client id %s', client_id)
-        if not status:
-            print 'remove monitor'
+        if not query:
+            log.debug('remove monitor')
             for m in monitors:
                 if m.id == request_id:
                     monitors.remove(m)
@@ -244,8 +243,13 @@
 
 
 def _client_closed(client):
-    print client
+    for server in _server.values():
+        for client_info in server._clients:
+            if ipc.get_ipc_from_proxy(client_info[1]) == client:
+                log.warning('disconnect client')
+                server._clients.remove(client_info)
     
 # connect to the ipc code
 _ipc = ipc.IPCServer('vfs')
 _ipc.register_object(connect, 'vfs')
+_ipc.signals["client_closed"].connect(_client_closed)


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to