Ejemplo n.º 1
0
 def _get_new_item(self):
     item = Item()
     if self.new_parent_relpath != self.parent_relpath:
         ref = ItemReference()
         # Refer to https://dev.onedrive.com/items/move.htm for Move API request.
         ref.path = '/drives/' + self.repo.drive.id + '/root:'
         if self.new_parent_relpath != '':
             ref.path += self.new_parent_relpath
         item.parent_reference = ref
     if self.new_name != self.item_name:
         item.name = self.new_name
     return item
Ejemplo n.º 2
0
 def update_timestamp_and_record(self, new_item, item_local_stat):
     remote_mtime, remote_mtime_w = get_item_modified_datetime(new_item)
     if not remote_mtime_w:
         # last_modified_datetime attribute is not modifiable in OneDrive server. Update local mtime.
         fix_owner_and_timestamp(self.local_abspath, self.repo.context.user_uid,
                                 datetime_to_timestamp(remote_mtime))
     else:
         file_system_info = FileSystemInfo()
         file_system_info.last_modified_date_time = datetime.utcfromtimestamp(item_local_stat.st_mtime)
         updated_item = Item()
         updated_item.file_system_info = file_system_info
         item_request = self.repo.authenticator.client.item(drive=self.repo.drive.id, id=new_item.id)
         new_item = item_request_call(self.repo, item_request.update, updated_item)
     self.repo.update_item(new_item, self.parent_relpath, item_local_stat.st_size)
Ejemplo n.º 3
0
 def update_timestamp_and_record(self, new_item, item_local_stat):
     remote_mtime, remote_mtime_w = get_item_modified_datetime(new_item)
     if not remote_mtime_w:
         # last_modified_datetime attribute is not modifiable in OneDrive server. Update local mtime.
         fix_owner_and_timestamp(self.local_abspath, self.repo.context.user_uid,
                                 datetime_to_timestamp(remote_mtime))
     else:
         file_system_info = FileSystemInfo()
         file_system_info.last_modified_date_time = datetime.utcfromtimestamp(item_local_stat.st_mtime)
         updated_item = Item()
         updated_item.file_system_info = file_system_info
         item_request = self.repo.authenticator.client.item(drive=self.repo.drive.id, id=new_item.id)
         new_item = item_request_call(self.repo, item_request.update, updated_item)
     self.repo.update_item(new_item, self.parent_relpath, item_local_stat.st_size)
Ejemplo n.º 4
0
	def makedir(self, path, permissions=None, recreate=False):
		parentDir = dirname(path)
		itemRequest = self.client.item(path=parentDir)
		try:
			item = itemRequest.get()
		except OneDriveError as e:
			raise ResourceNotFound(path=parentDir, exc=e)

		if item.folder is None:
			raise DirectoryExpected(path=parentDir)
		newItem = Item()
		newItem.name = basename(path)
		newItem.folder = Folder()
		itemRequest.children.add(entity=newItem)
		# don't need to close this filesystem so we return the non-closing version
		return SubFS(self, path)
Ejemplo n.º 5
0
	def setinfo(self, path, info): # pylint: disable=too-many-branches
		itemRequest = self.client.item(path=path)
		try:
			existingItem = itemRequest.get()
		except OneDriveError as e:
			raise ResourceNotFound(path=path, exc=e)

		itemUpdate = Item()
		itemUpdate.id = existingItem.id
		itemUpdate.file_system_info = FileSystemInfo()

		for namespace in info:
			for name, value in info[namespace].items():
				if namespace == "basic":
					if name == "name":
						assert False, "Unexpected to try and change the name this way"
					elif name == "is_dir":
						# can't change this - must be an error in the framework
						assert False, "Can't change an item to and from directory"
					else:
						assert False, "Aren't we guaranteed that this is all there is in the basic namespace?"
				elif namespace == "details":
					if name == "accessed":
						pass # not supported by OneDrive
					elif name == "created":
						# incoming datetimes should be utc timestamps, OneDrive expects naive UTC datetimes
						itemUpdate.file_system_info.created_date_time = epoch_to_datetime(value).replace(tzinfo=None)
					elif name == "metadata_changed":
						pass # not supported by OneDrive
					elif name == "modified":
						# incoming datetimes should be utc timestamps, OneDrive expects naive UTC datetimes
						itemUpdate.file_system_info.last_modified_date_time = epoch_to_datetime(value).replace(tzinfo=None)
					elif name == "size":
						assert False, "Can't change item size"
					elif name == "type":
						assert False, "Can't change an item to and from directory"
					else:
						assert False, "Aren't we guaranteed that this is all there is in the details namespace?"
				else:
					# ignore namespaces that we don't recognize
					pass
		itemRequest.update(itemUpdate)
Ejemplo n.º 6
0
    def create_directory(self, dname, parent_id='root'):
        """ create directory, assign parent_id if supplied """
        if not parent_id:
            raise ValueError('need to specify parent_id')
        if dname == '':
            result = t_get(self.client.item(id='root')).to_dict()
            result['parentid'] = 'root'
            return result
        newfolder = Folder()
        newitem = Item()
        newitem.name = dname
        newitem.folder = newfolder

        try:
            tmp = self.client.item(id=parent_id).children.add(newitem)
        except error.OneDriveError as exc:
            raise
        result = tmp.to_dict()
        result['parentid'] = parent_id
        return result
Ejemplo n.º 7
0
	def move(self, src_path, dst_path, overwrite=False):
		if not overwrite and self.exists(dst_path):
			raise DestinationExists(dst_path)
		srcRequest = self.client.item(path=src_path)

		itemUpdate = Item()

		newFilename = basename(dst_path)
		if not self.isdir(dst_path) and newFilename != basename(src_path):
			itemUpdate.name = newFilename

		parentDir = dirname(dst_path)
		if parentDir != dirname(src_path):
			try:
				parentDirItem = self.client.item(path=parentDir).get()
			except OneDriveError as e:
				raise ResourceNotFound(path=parentDir, exc=e)

			ref = ItemReference()
			ref.id = parentDirItem.id
			itemUpdate.parent_reference = ref

		srcRequest.update(itemUpdate)
Ejemplo n.º 8
0
 def _get_folder_pseudo_item(item_name):
     item = Item()
     item.name = item_name
     item.folder = Folder()
     return item
Ejemplo n.º 9
0
 def setUp(self):
     self.count = 0
     self.item = Item()
Ejemplo n.º 10
0
 def _get_folder_pseudo_item(item_name):
     item = Item()
     item.name = item_name
     item.folder = Folder()
     return item