def _get_subdrive(self, drive_uid, name, autocreate=True): """Return the DriveInfo for the Drive that the user has called 'name' in the drive with UID 'drive_uid'. If 'autocreate' is True then this drive is automatically created if it does not exist. """ if self.is_null(): raise PermissionError( "You cannot get a DriveInfo from a null UserDrives") from Acquire.ObjectStore import string_to_filepath_parts \ as _string_to_filepath_parts parts = _string_to_filepath_parts(name) if len(parts) != 1: raise ValueError("The passed drive name '%s' is not valid!" % name) from Acquire.Service import get_service_account_bucket \ as _get_service_account_bucket from Acquire.ObjectStore import ObjectStore as _ObjectStore from Acquire.ObjectStore import string_to_encoded as _string_to_encoded encoded_name = _string_to_encoded(name) bucket = _get_service_account_bucket() drive_key = "%s/%s/%s/%s" % (_subdrives_root, self._user_guid, drive_uid, encoded_name) try: drive_uid = _ObjectStore.get_string_object(bucket, drive_key) except: drive_uid = None if drive_uid is not None: from Acquire.Storage import DriveInfo as _DriveInfo drive = _DriveInfo(drive_uid=drive_uid, identifiers=self._identifiers, is_authorised=self._is_authorised) else: drive = None if drive is None: if self._is_authorised and autocreate: # create a new UID for the drive and write this to the # object store from Acquire.ObjectStore import create_uuid as _create_uuid drive_uid = _create_uuid() drive_uid = _ObjectStore.set_ins_string_object( bucket, drive_key, drive_uid) from Acquire.Storage import DriveInfo as _DriveInfo drive = _DriveInfo(drive_uid=drive_uid, identifiers=self._identifiers, is_authorised=self._is_authorised, autocreate=True) return drive
def get_drive(self, name, aclrules=None, autocreate=True): """Return the DriveMeta for the Drive that the user has called 'name'. If 'autocreate' is True then this drive is automatically created if it does not exist. Note that the '/' in the name will be interpreted as drive separators. """ if self.is_null(): raise PermissionError( "You cannot get a DriveInfo from a null UserDrives") # break the name into directory parts from Acquire.ObjectStore import string_to_filepath_parts \ as _string_to_filepath_parts parts = _string_to_filepath_parts(name) # first get the root drive... root_name = parts[0] from Acquire.Service import get_service_account_bucket \ as _get_service_account_bucket from Acquire.ObjectStore import ObjectStore as _ObjectStore from Acquire.ObjectStore import string_to_encoded as _string_to_encoded encoded_name = _string_to_encoded(root_name) drive_name = root_name bucket = _get_service_account_bucket() drive_key = "%s/%s/%s" % (_drives_root, self._user_guid, encoded_name) try: drive_uid = _ObjectStore.get_string_object(bucket, drive_key) except: drive_uid = None if drive_uid is not None: from Acquire.Storage import DriveInfo as _DriveInfo drive = _DriveInfo(drive_uid=drive_uid, is_authorised=self._is_authorised, identifiers=self._identifiers) else: drive = None if drive is None: if self._is_authorised and autocreate: # create a new UID for the drive and write this to the # object store from Acquire.ObjectStore import create_uid as _create_uid drive_uid = _create_uid() drive_uid = _ObjectStore.set_ins_string_object( bucket, drive_key, drive_uid) from Acquire.Storage import DriveInfo as _DriveInfo drive = _DriveInfo(drive_uid=drive_uid, identifiers=self._identifiers, is_authorised=self._is_authorised, aclrules=aclrules, autocreate=True) if drive is None: from Acquire.Storage import MissingDriveError raise MissingDriveError("There is no Drive called '%s' available" % name) container = [] # now we have the drive, get the sub-drive in this drive... if len(parts) > 1: for subdrive in parts[1:]: container.append(drive.uid()) drive_name = subdrive drive = self._get_subdrive(drive_uid=drive.uid(), name=drive_name, autocreate=autocreate) if drive is None: from Acquire.Storage import MissingDriveError raise MissingDriveError( "There is no Drive called '%s' available" % name) from Acquire.Storage import DriveMeta as _DriveMeta drivemeta = _DriveMeta(name=drive_name, uid=drive.uid(), container=container, aclrules=drive.aclrules()) drivemeta.resolve_acl(identifiers=self._identifiers) return drivemeta