Skip to content
Snippets Groups Projects

Draft: ENH: file system: link

Open Timm Fitschen requested to merge f-filesystem-link into f-filesystem-directory
Files
3
+ 60
36
@@ -115,6 +115,7 @@ class Entity(object):
self.parents = _Parents()
self.path = None
self.file = None
self.link_target = None
self.unit = None
self.acl = None
self.permissions = None
@@ -301,6 +302,17 @@ class Entity(object):
def path(self, new_path):
self.__path = new_path
@property
def link_target(self):
if self.__link_target is not None or self._wrapped_entity is None:
return self.__link_target
return self._wrapped_entity.link_target
@link_target.setter
def link_target(self, new_link_target):
self.__link_target = new_link_target
@property
def thumbnail(self):
warn(DeprecationWarning(
@@ -1063,6 +1075,9 @@ class Entity(object):
if self.file is not None and local_serialization:
xml.set("file", self.file)
if self.link_target is not None:
xml.set("linktarget", str(self.link_target))
if self.checksum is not None:
xml.set("checksum", self.checksum)
@@ -1117,6 +1132,7 @@ class Entity(object):
entity.description = elem.get("description")
entity.path = elem.get("path")
entity._checksum = elem.get("checksum")
entity.link_target = elem.get("linktarget")
entity._size = elem.get("size")
entity.datatype = elem.get("datatype") # @ReservedAssignment
entity.unit = elem.get("unit")
@@ -1380,7 +1396,7 @@ def _parse_value(datatype, value):
# This is for a special case, where the xml parser could not differentiate
# between single values and lists with one element. As
if hasattr(value, "__len__") and len(value) == 1:
if hasattr(value, "__len__") and len(value) == 1 and not isinstance(value, str):
return _parse_value(datatype, value[0])
# deal with references
@@ -1434,23 +1450,12 @@ class QueryTemplate():
self.description = description
self.query = query
self._cuid = None
self.value = None
self.datatype = None
self.messages = _Messages()
self.properties = None
self.parents = None
self.path = None
self.file = None
self._checksum = None
self._size = None
self._upload = None
self.unit = None
self.acl = None
self.permissions = None
self.is_valid = lambda: False
self.is_deleted = lambda: False
self.version = None
self.state = None
def retrieve(self, raise_exception_on_error=True, unique=True, sync=True,
flags=None):
@@ -1817,6 +1822,39 @@ class Record(Entity):
return Entity.to_xml(self, xml, add_properties=ALL)
class Link(Entity):
"""This class represents CaosDB's link entities."""
def __init__(self, name=None, id=None, description=None, path=None,
target=None):
Record.__init__(self, id=id, name=name, description=description)
self.role = "Link"
self.datatype = None
self.link_target = target
# location in the fileserver
self.path = path
def to_xml(self, xml=None, add_properties=ALL, local_serialization=False):
"""Convert this Link to an xml element.
@return: xml element
"""
if xml is None:
xml = etree.Element("Link")
return Entity.to_xml(self, xml=xml, add_properties=add_properties,
local_serialization=local_serialization)
def add_property(self, property=None, id=None, name=None, description=None, datatype=None,
value=None, unit=None, importance=FIX, inheritance=FIX):
return super().add_property(
property=property, id=id, name=name, description=description, datatype=datatype,
value=value, unit=unit, importance=importance, inheritance=inheritance)
class Directory(Record):
"""This class represents CaosDB's directory entities."""
@@ -1876,6 +1914,7 @@ class File(Record):
thumbnail : str
Deprecated.
"""
def __init__(self, name=None, id=None, description=None,
path=None, file=None, pickup=None,
thumbnail=None):
@@ -2506,30 +2545,13 @@ def _basic_sync(e_local, e_remote):
"this client did't know about it yet.".format(
e_remote.role, e_local.role))
e_local.id = e_remote.id
e_local.name = e_remote.name
e_local.description = e_remote.description
e_local.path = e_remote.path
e_local._checksum = e_remote._checksum
e_local._size = e_remote._size
e_local.datatype = e_remote.datatype
e_local.unit = e_remote.unit
e_local.value = e_remote.value
e_local.properties = e_remote.properties
e_local.parents = e_remote.parents
e_local.messages = e_remote.messages
e_local.acl = e_remote.acl
e_local.permissions = e_remote.permissions
e_local.is_valid = e_remote.is_valid
e_local.is_deleted = e_remote.is_deleted
e_local.version = e_remote.version
e_local.state = e_remote.state
if hasattr(e_remote, "query"):
e_local.query = e_remote.query
if hasattr(e_remote, "affiliation"):
e_local.affiliation = e_remote.affiliation
for attr in ["path", "link_target", "_checksum", "_size", "datatype",
"unit", "value", "properties", "parents", "messages", "acl",
"permissions", "is_valid", "is_deleted", "version", "state",
"query", "affiliation", "id", "name", "description"]:
if hasattr(e_remote, attr):
setattr(e_local, attr, getattr(e_remote, attr))
return e_local
@@ -3013,6 +3035,7 @@ class Container(list):
for local_entity in self:
if (sync_dict[local_entity] is None
and hasattr(local_entity, "path")
and local_entity.path is not None):
sync_remote_entities = []
@@ -4415,6 +4438,7 @@ def _parse_single_xml_element(elem):
'property': Property,
'file': File,
'directory': Directory,
'link': Link,
'parent': Parent,
'entity': Entity}
Loading