Download the contents of a specific Drive revision by ID

Open
#161 1 comment 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
api

Research direction

Start in pydrive2/files.py at GetContentFile and read the linked Google Drive revisions API reference, then trace how file IDs and download requests are wrapped. Done means the package can download a specified file revision by its id while preserving the existing download behavior.

Written by the indexing model from the issue text.

Description

feature request priority-p2

Hello PyDrive2 team,

First, thank you for developing and maintaining this package, I find it very helpful.

Second, I wanted to propose a new feature, which I personally find very useful (e.g. I am planning to use it for creating a simplified configuration management tool):

possibility to download a particular file revision by its id.

I have a code snipped that worked for me (based on GetContentFile function), but It has many shortcuts and potential flaws, therefore, I don't think it is good idea to create a PR with this code. Unfortunately, I don't have much experience working with the GDrive API to fix it myself.

@LoadAuth
def _GetContentRevision(
    file,
    rev_id,
    filename,
    chunksize=DEFAULT_CHUNK_SIZE,
):
    revisions = file.auth.service.revisions()
    file_id = file.metadata.get("id") or file.get("id")
    if not file_id:
        raise ValueError('No ID')

    def _download(fd, request):
        downloader = MediaIoBaseDownload(
            fd, file._WrapRequest(request), chunksize=chunksize
        )
        done = False
        while done is False:
            status, done = downloader.next_chunk()

    with open(filename, mode="w+b") as fd:
        rev = revisions.get(fileId=file_id, revisionId=rev_id)
        revision_metadata = rev.execute()
        rev.uri = revision_metadata["downloadUrl"]
        _download(fd, rev)

Hope you will find this feature useful as well.

-- Nikita

Dominant language
Python
Stars
671
Forks
76
Avg merge
17h 55m
Merged PRs (30d)
46

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from iterative/PyDrive2

All issues in iterative/PyDrive2

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.