Author: dmeyer
Date: Sun Mar 12 18:51:26 2006
New Revision: 1281

Added:
   trunk/WIP/vfs/src/directory.py
   trunk/WIP/vfs/src/file.py
Modified:
   trunk/WIP/vfs/src/db.py
   trunk/WIP/vfs/src/item.py
   trunk/WIP/vfs/src/monitor.py

Log:
split item.py into one file for each item type

Modified: trunk/WIP/vfs/src/db.py
==============================================================================
--- trunk/WIP/vfs/src/db.py     (original)
+++ trunk/WIP/vfs/src/db.py     Sun Mar 12 18:51:26 2006
@@ -49,8 +49,8 @@
 MAX_BUFFER_CHANGES = 20
 
 # Item generation mapping
-from item import Directory as create_dir
-from item import File as create_file
+from directory import Directory as create_dir
+from file import File as create_file
 
 class Mountpoint(object):
     """

Added: trunk/WIP/vfs/src/directory.py
==============================================================================
--- (empty file)
+++ trunk/WIP/vfs/src/directory.py      Sun Mar 12 18:51:26 2006
@@ -0,0 +1,136 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# directory.py - Directory item of the VFS
+# -----------------------------------------------------------------------------
+# $Id: item.py 1273 2006-03-11 19:34:08Z dmeyer $
+#
+# TODO: handle all the FIXME and TODO comments inside this file and
+#       add docs for functions, variables and how to use this file
+#
+# -----------------------------------------------------------------------------
+# kaa-vfs - A virtual filesystem with metadata
+# Copyright (C) 2005 Dirk Meyer
+#
+# First Edition: Dirk Meyer <[EMAIL PROTECTED]>
+# Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
+#
+# Please see the file doc/CREDITS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# -----------------------------------------------------------------------------
+
+# python imports
+import os
+import stat
+
+# kaa.vfs imports
+from item import Item
+
+UNKNOWN = -1
+
+class Directory(Item):
+    """
+    A directory based item.
+    Object Attributes:
+    url, filename, getattr, setattr, keys, listdir
+
+    Do not access attributes starting with _vfs outside kaa.vfs
+    """
+    def __init__(self, data, parent):
+        # Notes: filename end with '/'
+        if isinstance(data, str):
+            # fake item, there is no database entry
+            id = None
+            self.filename = parent.filename + data + '/' 
+            data = { 'name': data, 'mtime': UNKNOWN }
+            if parent and parent._vfs_id:
+                data['parent_type'], data['parent_id'] = parent._vfs_id
+            media = parent._vfs_media
+        elif isinstance(parent, Directory):
+            # db data
+            id = (data['type'], data['id'])
+            media = parent._vfs_media
+            self.filename = parent.filename + data['name'] + '/'
+        else:
+            # root directory
+            id = (data['type'], data['id'])
+            media = parent
+            parent = None
+            self.filename = media.directory
+
+        Item.__init__(self, id, 'file://' + self.filename, data, parent, media)
+        self._vfs_overlay = False
+        self._vfs_isdir = True
+
+
+    def listdir(self):
+        if not self._vfs_id:
+            # item is not in db, request information now
+            
self._vfs_database_update(self._vfs_db()._vfs_request(self.filename[:-1]))
+        return self._vfs_db().query(parent=self)
+        
+
+    def _vfs_listdir(self):
+        try:
+            listdir = os.listdir(self.filename)
+        except OSError:
+            return []
+
+        media = self._vfs_media
+        overlay = media.overlay + '/' + self.filename[len(media.directory):]
+        try:
+            result = [ ( x, True ) for x in os.listdir(overlay) \
+                       if not x.startswith('.') and not x in listdir ]
+        except OSError:
+            result = []
+        result += [ ( x, False ) for x in listdir if not x.startswith('.') ]
+        result.sort(lambda x,y: cmp(x[0], y[0]))
+        return result
+
+
+    def _vfs_os_listdir(self):
+        if hasattr(self, '_vfs_os_listdir_cache'):
+            return self._vfs_os_listdir_cache
+        
+        try:
+            result = [ (x, self.filename + x) for x in 
os.listdir(self.filename)
+                       if not x.startswith('.') ]
+        except OSError:
+            return []
+
+        media = self._vfs_media
+        overlay = media.overlay + '/' + self.filename[len(media.directory):]
+        try:
+            result += [ ( x, overlay + x ) for x in os.listdir(overlay) \
+                        if not x.startswith('.') and not x in listdir ]
+        except OSError:
+            pass
+        self._vfs_os_listdir_cache = result
+        return result
+        
+    def _vfs_mtime(self):
+        # TODO: add overlay dir to mtime
+        return os.stat(self.filename)[stat.ST_MTIME]
+    
+        
+    def __repr__(self):
+        """
+        Convert object to string (usefull for debugging)
+        """
+        str = '<vfs.Directory %s' % self.filename
+        if self._vfs_data['mtime'] == UNKNOWN:
+            str += ' (new)'
+        return str + '>'

Added: trunk/WIP/vfs/src/file.py
==============================================================================
--- (empty file)
+++ trunk/WIP/vfs/src/file.py   Sun Mar 12 18:51:26 2006
@@ -0,0 +1,97 @@
+# -*- coding: iso-8859-1 -*-
+# -----------------------------------------------------------------------------
+# file.py - File item of the VFS
+# -----------------------------------------------------------------------------
+# $Id: item.py 1273 2006-03-11 19:34:08Z dmeyer $
+#
+# TODO: handle all the FIXME and TODO comments inside this file and
+#       add docs for functions, variables and how to use this file
+#
+# -----------------------------------------------------------------------------
+# kaa-vfs - A virtual filesystem with metadata
+# Copyright (C) 2005 Dirk Meyer
+#
+# First Edition: Dirk Meyer <[EMAIL PROTECTED]>
+# Maintainer:    Dirk Meyer <[EMAIL PROTECTED]>
+#
+# Please see the file doc/CREDITS for a complete list of authors.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
+# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# -----------------------------------------------------------------------------
+
+# python imports
+import os
+import stat
+
+# kaa.vfs imports
+from item import Item
+
+UNKNOWN = -1
+
+class File(Item):
+    """
+    A file based item.
+    Object Attributes:
+    url, filename, getattr, setattr, keys
+
+    Do not access attributes starting with _vfs outside kaa.vfs
+    """
+    def __init__(self, data, parent, overlay=False):
+        if isinstance(data, str):
+            # fake item, there is no database entry
+            id = None
+            self.filename = parent.filename + data
+            data = { 'name': data, 'mtime': UNKNOWN }
+            if parent and parent._vfs_id:
+                data['parent_type'], data['parent_id'] = parent._vfs_id
+            media = parent._vfs_media
+        elif isinstance(parent, Directory):
+            # db data
+            id = (data['type'], data['id'])
+            media = parent._vfs_media
+            self.filename = parent.filename + data['name']
+
+        Item.__init__(self, id, 'file://' + self.filename, data, parent, media)
+        self._vfs_overlay = overlay
+
+
+    def _vfs_mtime(self):
+        # 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.
+        search = self._vfs_data['name']
+        if search.rfind('.') > 0:
+            search = search[:search.rfind('.')]
+        mtime = 0
+        for basename, filename in self._vfs_parent._vfs_os_listdir():
+            if basename.startswith(search):
+                mtime += os.stat(filename)[stat.ST_MTIME]
+        return mtime
+
+
+    def __repr__(self):
+        """
+        Convert object to string (usefull for debugging)
+        """
+        str = '<vfs.File %s' % self.filename
+        if self._vfs_data['mtime'] == UNKNOWN:
+            str += ' (new)'
+        return str + '>'
+
+
+# make it possible to override these
+

Modified: trunk/WIP/vfs/src/item.py
==============================================================================
--- trunk/WIP/vfs/src/item.py   (original)
+++ trunk/WIP/vfs/src/item.py   Sun Mar 12 18:51:26 2006
@@ -32,10 +32,6 @@
 #
 # -----------------------------------------------------------------------------
 
-# python imports
-import os
-import stat
-
 # kaa imports
 from kaa.strutils import str_to_unicode
 
@@ -151,153 +147,3 @@
         ret = self.item
         self.item = self.item._vfs_parent
         return ret
-
-class Directory(Item):
-    """
-    A directory based item.
-    Object Attributes:
-    url, filename, getattr, setattr, keys, listdir
-
-    Do not access attributes starting with _vfs outside kaa.vfs
-    """
-    def __init__(self, data, parent):
-        # Notes: filename end with '/'
-        if isinstance(data, str):
-            # fake item, there is no database entry
-            id = None
-            self.filename = parent.filename + data + '/' 
-            data = { 'name': data, 'mtime': UNKNOWN }
-            if parent and parent._vfs_id:
-                data['parent_type'], data['parent_id'] = parent._vfs_id
-            media = parent._vfs_media
-        elif isinstance(parent, Directory):
-            # db data
-            id = (data['type'], data['id'])
-            media = parent._vfs_media
-            self.filename = parent.filename + data['name'] + '/'
-        else:
-            # root directory
-            id = (data['type'], data['id'])
-            media = parent
-            parent = None
-            self.filename = media.directory
-
-        Item.__init__(self, id, 'file://' + self.filename, data, parent, media)
-        self._vfs_overlay = False
-        self._vfs_isdir = True
-
-
-    def listdir(self):
-        if not self._vfs_id:
-            # item is not in db, request information now
-            
self._vfs_database_update(self._vfs_db()._vfs_request(self.filename[:-1]))
-        return self._vfs_db().query(parent=self)
-        
-
-    def _vfs_listdir(self):
-        try:
-            listdir = os.listdir(self.filename)
-        except OSError:
-            return []
-
-        media = self._vfs_media
-        overlay = media.overlay + '/' + self.filename[len(media.directory):]
-        try:
-            result = [ ( x, True ) for x in os.listdir(overlay) \
-                       if not x.startswith('.') and not x in listdir ]
-        except OSError:
-            result = []
-        result += [ ( x, False ) for x in listdir if not x.startswith('.') ]
-        result.sort(lambda x,y: cmp(x[0], y[0]))
-        return result
-
-
-    def _vfs_os_listdir(self):
-        if hasattr(self, '_vfs_os_listdir_cache'):
-            return self._vfs_os_listdir_cache
-        
-        try:
-            result = [ (x, self.filename + x) for x in 
os.listdir(self.filename)
-                       if not x.startswith('.') ]
-        except OSError:
-            return []
-
-        media = self._vfs_media
-        overlay = media.overlay + '/' + self.filename[len(media.directory):]
-        try:
-            result += [ ( x, overlay + x ) for x in os.listdir(overlay) \
-                        if not x.startswith('.') and not x in listdir ]
-        except OSError:
-            pass
-        self._vfs_os_listdir_cache = result
-        return result
-        
-    def _vfs_mtime(self):
-        # TODO: add overlay dir to mtime
-        return os.stat(self.filename)[stat.ST_MTIME]
-    
-        
-    def __repr__(self):
-        """
-        Convert object to string (usefull for debugging)
-        """
-        str = '<vfs.Directory %s' % self.filename
-        if self._vfs_data['mtime'] == UNKNOWN:
-            str += ' (new)'
-        return str + '>'
-    
-
-class File(Item):
-    """
-    A file based item.
-    Object Attributes:
-    url, filename, getattr, setattr, keys
-
-    Do not access attributes starting with _vfs outside kaa.vfs
-    """
-    def __init__(self, data, parent, overlay=False):
-        if isinstance(data, str):
-            # fake item, there is no database entry
-            id = None
-            self.filename = parent.filename + data
-            data = { 'name': data, 'mtime': UNKNOWN }
-            if parent and parent._vfs_id:
-                data['parent_type'], data['parent_id'] = parent._vfs_id
-            media = parent._vfs_media
-        elif isinstance(parent, Directory):
-            # db data
-            id = (data['type'], data['id'])
-            media = parent._vfs_media
-            self.filename = parent.filename + data['name']
-
-        Item.__init__(self, id, 'file://' + self.filename, data, parent, media)
-        self._vfs_overlay = overlay
-
-
-    def _vfs_mtime(self):
-        # 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.
-        search = self._vfs_data['name']
-        if search.rfind('.') > 0:
-            search = search[:search.rfind('.')]
-        mtime = 0
-        for basename, filename in self._vfs_parent._vfs_os_listdir():
-            if basename.startswith(search):
-                mtime += os.stat(filename)[stat.ST_MTIME]
-        return mtime
-
-
-    def __repr__(self):
-        """
-        Convert object to string (usefull for debugging)
-        """
-        str = '<vfs.File %s' % self.filename
-        if self._vfs_data['mtime'] == UNKNOWN:
-            str += ' (new)'
-        return str + '>'
-
-
-# make it possible to override these
-

Modified: trunk/WIP/vfs/src/monitor.py
==============================================================================
--- trunk/WIP/vfs/src/monitor.py        (original)
+++ trunk/WIP/vfs/src/monitor.py        Sun Mar 12 18:51:26 2006
@@ -42,7 +42,6 @@
 
 # kaa.vfs imports
 import parser
-import item
 import cdrom
 
 # get logging object


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to