iterative / iterative/PyDrive2

Support file revisions

Offen
#161 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
feature request
Vorherrschende Sprache
Python
Sterne
670
Forks
75
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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](https://developers.google.com/drive/api/v3/reference/revisions) by its `id`_.

I have a code snipped that worked for me (based on [`GetContentFile`](https://github.com/iterative/PyDrive2/blob/master/pydrive2/files.py#L293) 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.

```python
@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

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
api
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.