Skip to content
Snippets Groups Projects

Draft: ENH: file system: import

Open Timm Fitschen requested to merge f-filesystem-import into f-filesystem-link
@@ -2031,7 +2031,7 @@ class Link(Record):
"""This class represents LinkAheads's link entities."""
def __init__(self, name=None, id=None, description=None, path=None,
target=None):
target=None, import_file=False):
Record.__init__(self, id=id, name=name, description=description)
self.role = "Link"
self.datatype = None
@@ -2040,6 +2040,8 @@ class Link(Record):
# location in the fileserver
self.path = path
self.import_file = import_file
def to_xml(self, xml=None, add_properties=ALL, local_serialization=False):
"""Convert this Link to an xml element.
@@ -2063,7 +2065,8 @@ class Link(Record):
class Directory(Record):
"""This class represents CaosDB's directory entities."""
def __init__(self, name=None, id=None, description=None, path=None):
def __init__(self, name=None, id=None, description=None, path=None,
import_file=False, recursive_import=False):
Record.__init__(self, id=id, name=name, description=description)
self.role = "Directory"
self.datatype = None
@@ -2071,6 +2074,9 @@ class Directory(Record):
# location in the fileserver
self.path = path
self.import_file = import_file
self.recursive_import = recursive_import
def to_xml(self, xml=None, add_properties=ALL, local_serialization=False):
"""Convert this Directory to an xml element.
@@ -2118,11 +2124,13 @@ class File(Record):
deprecated.
thumbnail : str
deprecated.
import_file : bool
Import the file (don't upload it, its already there). Default: `False`
"""
def __init__(self, name=None, id=None, description=None,
path=None, file=None, pickup=None,
thumbnail=None):
thumbnail=None, import_file=False):
Record.__init__(self, id=id, name=name, description=description)
self.role = "File"
@@ -2133,6 +2141,9 @@ class File(Record):
# local file path or pointer to local file
self.file = file
self.import_file = import_file
if thumbnail is not None:
warn(DeprecationWarning(
"The thumbnail feature has been removed from the CaosDB "
@@ -3698,6 +3709,8 @@ class Container(list):
if hasattr(entity, '_upload') and entity._upload is not None:
entity_xml.set("upload", entity._upload)
elif hasattr(entity, 'import_file') and entity.import_file is True:
entity_xml.set("import", "true")
insert_xml.append(entity_xml)
@@ -3776,7 +3789,7 @@ class Container(list):
def insert(self, strict=False, raise_exception_on_error=True,
unique=True, sync=True, flags=None):
"""Insert these entities into CaosDB.
"""Insert these entities into LinkAhead.
A successful insertion will generate a persistent ID for the new entities. These entities can be
identified, retrieved, updated, and deleted via their ID until they have been deleted.
@@ -3829,6 +3842,11 @@ class Container(list):
# continue
# except KeyError:
# pass
# we expect that every inserted entity produces
# exactly one entity in the server's response
sync_unique = True
for entity in self:
if entity.is_valid():
continue
@@ -3844,6 +3862,11 @@ class Container(list):
if hasattr(entity, '_upload') and entity._upload is not None:
entity_xml.set("upload", entity._upload)
elif hasattr(entity, 'recursive_import') and entity.recursive_import is True:
entity_xml.set("recursive_import", "true")
sync_unique=False
elif hasattr(entity, 'import_file') and entity.import_file is True:
entity_xml.set("import", "true")
insert_xml.append(entity_xml)
if len(self) > 0 and len(insert_xml) < 1:
@@ -3876,7 +3899,7 @@ class Container(list):
if sync:
self._sync(cresp, unique=unique,
self._sync(cresp, unique=sync_unique,
raise_exception_on_error=raise_exception_on_error)
if raise_exception_on_error:
Loading