PyDrive2
PyDrive2 copied to clipboard
rebuild `cp_file` in `GDriveFileSystem` to use `GoogleDriveFile.Copy`
Can copy single files and folders, the recursive implementation is in AbstractFileSystem.copy.
Is compatible with AbstractFileSystem.copy so for example:
fs = GDriveFileSystem("root/tmp", auth)
fs.copy('root/tmp/a.pdf', 'root/tmp/folder/b.pdf', recursive=False)
> will copy the file file a.pdf in the folder and rename it to b.pdf
fs.copy('root/tmp/folder1', 'root/tmp/folder/new_folder1', recursive=True)
> will copy the folder folder1 into folder, renaming it new_folder1. will also copy the content
> of folder1 into new_folder1
There are no tests for copy, but there is one for the move method, that right now is implemented as copy + rm, and the test passes.
todo list:
- [ ] add tests
@shcheklein can you please review the code? Also check if this is backward compatible with the previous implementation.
Thank you.
@simone-viozzi hey, thanks. I'll try to find some time this week!
@shcheklein I noticed that there was no mkdir method and I needed one, so I implemented it.
I also noticed that fs.expand_path only works if the path is one level under self.path. Example:
self.path=root/tmp/- folder structure like:
root/tmp/fo1root/tmp/fo1/file2.pdfroot/tmp/fo1/fo2/root/tmp/fo1/fo2/file3.pdfroot/tmp/fo1/fo2/fo3/root/tmp/fo1/fo2/fo3/file4.pdf
then:
print(fs.expand_path('root/tmp/fo1', recursive=True))
> ['root/tmp/fo1', 'root/tmp/fo1/file2.pdf', 'root/tmp/fo1/fo2/file3.pdf', 'root/tmp/fo1/fo2/fo3/file4.pdf']
# ( correct )
print(fs.expand_path('root/tmp/fo1/fo2/', recursive=True))
> ['root/tmp/fo1/fo2']
# ( wrong! Correct answer is: ['root/tmp/fo1/fo2', 'root/tmp/fo1/fo2/file3.pdf', 'root/tmp/fo1/fo2/fo3/file4.pdf'] )
expand_path use find:
https://github.com/iterative/PyDrive2/blob/27bbf4c8b4ef7fc3cce97f645b0e79d6795bf73c/pydrive2/fs/spec.py#L469-L509
The same bug happens in find as well.
I lost a good amount of time to understand why copy suddenly stopped working 😅