Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gerion Entrup
brainzfs
Commits
38aa2cd9
Commit
38aa2cd9
authored
Nov 30, 2016
by
Gerion Entrup
Browse files
sqlfuse: add Generic object
add the ability to create arbitrary objects that can use the whole fuse functionality
parent
efd36e34
Changes
4
Hide whitespace changes
Inline
Side-by-side
sqlfuse/__init__.py
View file @
38aa2cd9
...
...
@@ -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
):
...
...
sqlfuse/data.py
View file @
38aa2cd9
...
...
@@ -58,9 +58,9 @@ class Data:
"""
# if self defined
if
qpath
is
not
None
:
if
qpath
.
fuse_io
:
ndir
=
node
.
add_
fuseio
(
qpath
.
ge
t
(
node
,
self
.
_session
,
filename
))
if
qpath
.
is_generic
:
ndir
=
node
.
add_
special
(
qpath
.
ge
neric
(
self
.
_session
,
node
,
filename
,
self
))
else
:
ndir
=
node
.
add_special
(
Special
(
qpath
.
query
,
qpath
.
functions
,
qpath
.
where
,
...
...
sqlfuse/model.py
View file @
38aa2cd9
...
...
@@ -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
nodes.
"""
def
__init__
(
self
,
session
,
parent
,
name
,
data
):
"""Construct a function node.
Arguments:
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
otherwise.
"""
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
)
else
:
...
...
sqlfuse/path.py
View file @
38aa2cd9
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
:
"""TODO"""
fuse_io
=
True
is_generic
=
True
def
get
(
parent
,
session
,
name
):
pass
def
__init__
(
self
,
path
,
generic
):
self
.
path
=
path
self
.
generic
=
generic
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment