Commit 38aa2cd9 authored by Gerion Entrup's avatar Gerion Entrup
Browse files

sqlfuse: add Generic object

add the ability to create arbitrary objects that can use the whole fuse
parent efd36e34
......@@ -39,8 +39,9 @@ import sqlfuse.operations
from sqlfuse.path import FPath, QPath
from sqlfuse.where import Where
from sqlfuse.functions import Functions
from sqlfuse.model import Generic
__all__ = ['FPath', 'QPath', 'Where', 'Functions', 'init']
__all__ = ['FPath', 'QPath', 'Where', 'Functions', 'init', 'Generic']
def init(session, fs):
......@@ -58,9 +58,9 @@ class Data:
# if self defined
if qpath is not None:
if qpath.fuse_io:
ndir = node.add_fuseio(
qpath.get(node, self._session, filename))
if qpath.is_generic:
ndir = node.add_special(
qpath.generic(self._session, node, filename, self))
ndir = node.add_special(
Special(qpath.query, qpath.functions, qpath.where,
......@@ -253,6 +253,61 @@ attribute {}, object items: {}".format('.'.join([str(pwhere.function.__self__),
self._query = self._query.where(pwhere.function(attr))
class Generic(Node):
"""Represent a generic node that can hold everything and evolve to real
def __init__(self, session, parent, name, data):
"""Construct a function node.
session -- A SQLAlchemy session.
parent -- Superclass argument, see Node.
name -- Superclass argument, see Node.
data -- Superclass argument, see Node.
super().__init__(parent, name, data)
self._session = session
self.logger = logging.getLogger('sqlfuse.generic')
def __repr__(self):
return ''.join(["Generic(session=", repr(self._session),
", parent=", self._parent.get_name(),
", name=", self._name,
", data=", repr(self._data),
def query_name(self, filename):
"""Asks for an identifier of the given filename.
The function returns a valid identifier if a result exists or None
raise NotImplementedError
def query_all(self):
"""Get an iterable object for all identifiers of the Generic."""
raise NotImplementedError
def is_special(self):
"""Indicates whether this object is special. Returns always true."""
return True
def get_obj_fname(self, ident):
"""Return the generated filename out of an identifier."""
raise NotImplementedError
def apply_where(self, placeholder, obj):
"""Specify the Generic, where placeholder is replaced with object."""
raise NotImplementedError
def get_fuseio(self,ident):
"""Return a valid FuseIO object based on the identifier."""
raise NotImplementedError
class FuseDir(FuseIO, Node):
"""Represents a directory in the filesystem tree."""
......@@ -299,7 +354,9 @@ class FuseDir(FuseIO, Node):
return None, None
# construct the new FuseIO object
if special.is_leaf():
if isinstance(special, Generic):
f = special.get_fuseio(row)
elif special.is_leaf():
(gid, path) = special.get_fileattr(row)
f = FuseFile(None, -1, self, gid, path, self._data)
class QPath:
"""Represents a container class for special objects"""
fuse_io = False
is_generic = False
def generic_fileattr(row):
"""Give the gid of path attribute of the requested row.
......@@ -45,7 +45,8 @@ class QPath:
class FPath:
fuse_io = True
is_generic = True
def get(parent, session, name):
def __init__(self, path, generic):
self.path = path
self.generic = generic
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment