Exemple #1
0
 def import_filename(self, filename, key, sub_path=''):
     components = [self.root, key]
     if sub_path:
         components.append(sub_path)
     abs_path = os.path.join(*components)
     makedir(os.path.dirname(abs_path))
     return os.rename(filename, abs_path)
Exemple #2
0
 def import_filename(self, filename, key, sub_path=''):
     components = [self.root, key]
     if sub_path:
         components.append(sub_path)
     abs_path = os.path.join(*components)
     makedir(os.path.dirname(abs_path))
     return os.rename(filename, abs_path)
Exemple #3
0
 def store_descriptor(self, uid, filename, fd):
     """
     Store a file content given by a file descriptor
     :param uid: UUID of the Element
     :param fd: file descriptor
     :return: a key unique to this storage
     :raise:
     """
     components = [self.root] + self.split_uid(uid) + [uid, filename]
     abs_path = os.path.join(*components)
     makedir(os.path.dirname(abs_path))
     with open(abs_path, 'wb') as fd_write:
         data = fd.read(10240)
         while data:
             fd_write.write(data)
             data = fd.read(10240)
     return os.path.join(*(components[1:]))
Exemple #4
0
 def store_descriptor(self, uid, filename, fd):
     """
     Store a file content given by a file descriptor
     :param uid: UUID of the Element
     :param fd: file descriptor
     :return: a key unique to this storage
     :raise:
     """
     components = [self.root] + self.split_uid(uid) + [uid, filename]
     abs_path = os.path.join(*components)
     makedir(os.path.dirname(abs_path))
     with open(abs_path, 'wb') as fd_write:
         data = fd.read(10240)
         while data:
             fd_write.write(data)
             data = fd.read(10240)
     return os.path.join(*(components[1:]))
Exemple #5
0
 def get_file(self, key, sub_path='', mode='rb'):
     """
     Return a file descriptor in read mode of the given path
     :param key: UUID of the Element
     :param sub_path: relative path to read
     :return: A file-like object
     :raise:
     """
     components = [self.root, key]
     if sub_path:
         components.append(sub_path)
     abs_path = os.path.join(*components)
     makedir(os.path.dirname(abs_path))
     try:
         fd = open(abs_path, mode)
     except IOError:
         fd = None
     return fd
Exemple #6
0
 def get_file(self, key, sub_path='', mode='rb'):
     """
     Return a file descriptor in read mode of the given path
     :param key: UUID of the Element
     :param sub_path: relative path to read
     :return: A file-like object
     :raise:
     """
     components = [self.root, key]
     if sub_path:
         components.append(sub_path)
     abs_path = os.path.join(*components)
     makedir(os.path.dirname(abs_path))
     try:
         fd = open(abs_path, mode)
     except IOError:
         fd = None
     return fd