import os.path
from sqlobject import SQLObjectNotFound

import wakefs.db
import wakefs.utils
import wakefs.conn

class File(object):
    def __init__(self, name, location=None):
        wakefs.db.initialise()
        DBObjectClass = getattr(wakefs.db,type(self).__name__)
        try:
            self._dbobject = DBObjectClass.selectBy(name=name).getOne()
        except SQLObjectNotFound:
            dirname = os.path.dirname(name) or "/"
            if dirname != "/" and wakefs.db.File.selectBy(name=dirname).count() > 0:
                raise ValueError("'%s' is a file." % dirname)
            directory = Directory(
                    name=dirname,
                    location=location
                )
            stats = wakefs.utils.get_stats(name, location)
            self._dbobject = DBObjectClass(
                    directory = directory._dbobject,
                    location = location,
                    name = name,
                    **stats
                )

    def __get_db_col(self, colname):
        if self._dbobject:
            return getattr(self._dbobject, colname)
        else:
            raise AttributeError("Object was deleted")

    def __set_db_col(self, colname, value):
        if self._dbobject:
            setattr(self._dbobject, colname, value)
        else:
            raise AttributeError("Object was deleted")

    @property
    def crc(self):
        return self.__get_db_col('crc')

    @property
    def location(self):
        return self.__get_db_col('location')

    @property
    def name(self):
        return self.__get_db_col('name')

    def __unicode__(self):
        return self.name

    def __str__(self):
        return str(unicode(self))

    def __repr__(self):
        return unicode(self)
    
class Link(File):
    def __init__(self, name, target, location=None):
        wakefs.db.initialise()
        DBObjectClass = getattr(wakefs.db,type(self).__name__)
        self._connection = wakefs.conn.connection_factory()
        try:
            self._dbobject = DBObjectClass.selectBy(name=name).getOne()
        except SQLObjectNotFound:
            dirname = os.path.dirname(name) or "/"
            if dirname != "/" and wakefs.db.File.selectBy(name=dirname).count() > 0:
                raise ValueError("'%s' is a file." % dirname)
            directory = Directory(
                    name=dirname,
                    location=location
                )
            stats = wakefs.utils.get_stats(name, location)
            self._dbobject = wakefs.db.DBObjectClass(
                    directory = directory._dbobject,
                    location = location,
                    target = target,
                    name = name,
                    **stats
                )

    @property
    def target(self):
        return self.target

class SymLink(Link):
    pass

class Directory(File):
    @property
    def content(self):
        for c in self.__get_db_col('content'):
            yield globals()[type(c).__name__](c.name,c.location)

@@ -106,16 +106,875 @@
 s.conn%0A%0A
+class Stats(object):%0A    valid_attributes = %7B%0A            'st_mode', 'st_ino', 'st_dev', 'st_nlink', 'st_uid',%0A            'st_gid', 'st_rdev', 'st_size', 'st_blksize', 'st_blocks',%0A            'st_atime', 'st_mtime', 'st_ctime'%0A        %7D%0A%0A    def __init__(self, **stat):%0A        if set(stat.keys()) == Stats.valid_attributes:%0A            self.stat = stat%0A        else:%0A            raise ValueError(%22Parameters %25s wrong%22 %25%0A                    str(tuple(Stats.valid_attributes %5E set(stat.keys()))))%0A%0A    def __getattribute__(self, name):%0A        if name in Stats.valid_attributes:%0A            return self.stat%5Bname%5D%0A        else:%0A            return object.__getattribute__(self,name)%0A%0A    def __repr__(self):%0A        repr = %22Stats(%22%0A        for a in Stats.valid_attributes:%0A            repr += a + '=' + str(self.stat%5Ba%5D) + ','%0A        return repr%5B:-1%5D + %22)%22%0A%0A
 class Fi
@@ -2452,24 +2452,698 @@
 ol('name')%0A%0A
+    @property%0A    def stat(self):%0A        return Stats(%0A                self.__get_db_col('st_mode'),%0A                self.__get_db_col('st_ino'),%0A                self.__get_db_col('st_dev'),%0A                self.__get_db_col('st_nlink'),%0A                self.__get_db_col('st_uid'),%0A                self.__get_db_col('st_gid'),%0A                self.__get_db_col('st_rdev'),%0A                self.__get_db_col('st_size'),%0A                self.__get_db_col('st_blksize'),%0A                self.__get_db_col('st_blocks'),%0A                self.__get_db_col('st_atime'),%0A                self.__get_db_col('st_mtime'),%0A                self.__get_db_col('st_ctime'),%0A            )%0A%0A
     def __un

Add stats type