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
6
@@ -119,6 +119,7 @@ class Entity:
self.parents = _ParentList()
self.path = None
self.file = None
self.link_target = None
self.unit = None
self.acl = None
self.permissions = None
@@ -305,6 +306,17 @@ class Entity:
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(
@@ -1231,6 +1243,9 @@ out: List[Entity]
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)
@@ -1285,6 +1300,7 @@ out: List[Entity]
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")
@@ -1566,7 +1582,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
@@ -2011,6 +2027,39 @@ class Record(Entity):
return Entity.to_xml(self, xml, add_properties=ALL)
class Link(Record):
"""This class represents LinkAheads'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."""
@@ -2699,30 +2748,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
@@ -3216,6 +3248,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 = []
@@ -4717,6 +4750,7 @@ def _parse_single_xml_element(elem):
'property': Property,
'file': File,
'directory': Directory,
'link': Link,
'parent': Parent,
'entity': Entity}
Loading