6 from fresh import FreshBase, convertTime
8 _logger = logging.getLogger('arvados.arvados_fuse')
10 class File(FreshBase):
11 """Base for file objects."""
13 def __init__(self, parent_inode, _mtime=0):
14 super(File, self).__init__()
16 self.parent_inode = parent_inode
22 def readfrom(self, off, size, num_retries=0):
25 def writeto(self, off, size, num_retries=0):
26 raise Exception("Not writable")
31 def clear(self, force=False):
41 class FuseArvadosFile(File):
42 """Wraps a ArvadosFile."""
44 def __init__(self, parent_inode, arvfile, _mtime):
45 super(FuseArvadosFile, self).__init__(parent_inode, _mtime)
46 self.arvfile = arvfile
49 with llfuse.lock_released:
50 return self.arvfile.size()
52 def readfrom(self, off, size, num_retries=0):
53 with llfuse.lock_released:
54 return self.arvfile.readfrom(off, size, num_retries, exact=True)
56 def writeto(self, off, buf, num_retries=0):
57 with llfuse.lock_released:
58 return self.arvfile.writeto(off, buf, num_retries)
64 return self.arvfile.writable()
67 with llfuse.lock_released:
69 self.arvfile.parent.root_collection().save()
72 class StringFile(File):
73 """Wrap a simple string as a file"""
74 def __init__(self, parent_inode, contents, _mtime):
75 super(StringFile, self).__init__(parent_inode, _mtime)
76 self.contents = contents
79 return len(self.contents)
81 def readfrom(self, off, size, num_retries=0):
82 return self.contents[off:(off+size)]
85 class ObjectFile(StringFile):
86 """Wrap a dict as a serialized json object."""
88 def __init__(self, parent_inode, obj):
89 super(ObjectFile, self).__init__(parent_inode, "", 0)
90 self.object_uuid = obj['uuid']
94 return self.object_uuid
96 def update(self, obj=None):
97 self._mtime = convertTime(obj['modified_at']) if 'modified_at' in obj else 0
98 self.contents = json.dumps(obj, indent=4, sort_keys=True) + "\n"