Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Python tests

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Installing requirements
run: pip install -e '.[dev]'

- name: Running tests
run: pytest
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ Library and cli to manage and interact with your Google Drive, sheets and docs
1. [License](#license)

# Introduction
[![Build Status](https://travis-ci.org/eduardogr/google-drive-python.svg?branch=main)](https://travis-ci.org/github/eduardogr/google-drive-python)
[![codecov](https://codecov.io/gh/eduardogr/google-drive-python/branch/main/graph/badge.svg?token=E183Y3LLXX)](https://codecov.io/gh/eduardogr/google-drive-python)
[![Python](https://img.shields.io/badge/Python-v3.6%2B-blue)]()
![Build Status](https://github.com/eduardogr/google-drive-python/actions/workflows/python-tests.yml/badge.svg?event=push)
[![Python](https://img.shields.io/badge/Python-v3.9%2B-blue)]()
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
[![GitHub license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/eduardogr/google-drive-python/blob/main/LICENSE)

Expand Down
20 changes: 0 additions & 20 deletions docs/Makefile

This file was deleted.

35 changes: 0 additions & 35 deletions docs/make.bat

This file was deleted.

54 changes: 0 additions & 54 deletions docs/source/conf.py

This file was deleted.

20 changes: 0 additions & 20 deletions docs/source/index.rst

This file was deleted.

69 changes: 32 additions & 37 deletions googledrive/api.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import pickle
import os.path
import json

from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

from googledrive.models import GoogleApiClientHttpError
from googledrive.models import GoogleApiClientHttpErrorBuilder
from googledrive.mappers import GoogleFileDictToGoogleFile
from googledrive.exceptions import MissingGoogleDriveFolderException
from googledrive.exceptions import MissingGoogleDriveFileException
from googledrive.exceptions import GoogleApiClientHttpErrorException

from googledrive import models
from googledrive import mappers
from googledrive import exceptions

class GoogleAuth:
def authenticate(self, credentials, scopes):
Expand Down Expand Up @@ -131,10 +126,10 @@ def create_folder(self, name):
.execute()
)
except HttpError as e:
http_error = GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise GoogleApiClientHttpErrorException(http_error)
http_error = models.GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise exceptions.GoogleApiClientHttpErrorException(http_error)

return GoogleFileDictToGoogleFile().google_file_dict_to_google_file(folder)
return mappers.GoogleFileDictToGoogleFile().google_file_dict_to_google_file(folder)

def create_file(self, name, mimetype):
splitted_path = list(self.__split_path(name))
Expand All @@ -145,7 +140,7 @@ def create_file(self, name, mimetype):
parent_name = splitted_path[-2]
parent_folder = self.get_folder(parent_name)
if parent_folder == None:
raise MissingGoogleDriveFolderException(
raise exceptions.MissingGoogleDriveFolderException(
"Missing folder: {}".format(parent_name)
)
parents = [parent_folder.id]
Expand All @@ -161,10 +156,10 @@ def create_file(self, name, mimetype):
.execute()
)
except HttpError as e:
http_error = GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise GoogleApiClientHttpErrorException(http_error)
http_error = models.GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise exceptions.GoogleApiClientHttpErrorException(http_error)

return GoogleFileDictToGoogleFile().google_file_dict_to_google_file(file)
return mappers.GoogleFileDictToGoogleFile().google_file_dict_to_google_file(file)

def update_file_parent(self, file_id, current_parent, new_parent):
drive_service = super().get_service(
Expand All @@ -176,8 +171,8 @@ def update_file_parent(self, file_id, current_parent, new_parent):
)
file_update.execute()
except HttpError as e:
http_error = GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise GoogleApiClientHttpErrorException(http_error)
http_error = models.GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise exceptions.GoogleApiClientHttpErrorException(http_error)

def get_file_from_id(self, file_id: str):
drive_service = super().get_service(
Expand All @@ -190,12 +185,12 @@ def get_file_from_id(self, file_id: str):
.execute()
)

return GoogleFileDictToGoogleFile().google_file_dict_to_google_file(
return mappers.GoogleFileDictToGoogleFile().google_file_dict_to_google_file(
google_file_dict
)
except HttpError as e:
http_error = GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise GoogleApiClientHttpErrorException(http_error)
http_error = models.GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise exceptions.GoogleApiClientHttpErrorException(http_error)

def list_files(self, page_token: str, query: str):
drive_service = super().get_service(
Expand All @@ -215,11 +210,11 @@ def list_files(self, page_token: str, query: str):
.execute()
)
except HttpError as e:
http_error = GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise GoogleApiClientHttpErrorException(http_error)
http_error = models.GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise exceptions.GoogleApiClientHttpErrorException(http_error)

google_files = [
GoogleFileDictToGoogleFile().google_file_dict_to_google_file(
mappers.GoogleFileDictToGoogleFile().google_file_dict_to_google_file(
google_file_dict
)
for google_file_dict in response.get("files", [])
Expand All @@ -243,8 +238,8 @@ def copy_file(self, file_id, new_filename):
)
return results.get("id")
except HttpError as e:
http_error = GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise GoogleApiClientHttpErrorException(http_error)
http_error = models.GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise exceptions.GoogleApiClientHttpErrorException(http_error)

def create_permission(self, document_id: str, role: str, email_address):
drive_service = super().get_service(
Expand All @@ -256,8 +251,8 @@ def create_permission(self, document_id: str, role: str, email_address):
body={"type": "user", "emailAddress": email_address, "role": role},
).execute()
except HttpError as e:
http_error = GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise GoogleApiClientHttpErrorException(http_error)
http_error = models.GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise exceptions.GoogleApiClientHttpErrorException(http_error)

#
# High level API access
Expand All @@ -282,7 +277,7 @@ def googledrive_ls(self, path: str):
else:
folder = self.get_folder(splitted_path[0])
if folder is None:
raise MissingGoogleDriveFolderException(
raise exceptions.MissingGoogleDriveFolderException(
"Missing folder: {}".format(splitted_path[0])
)

Expand All @@ -291,7 +286,7 @@ def googledrive_ls(self, path: str):
folder = self.__get_file(query, path_element)

if folder is None:
raise MissingGoogleDriveFolderException(
raise exceptions.MissingGoogleDriveFolderException(
"Missing folder: {}".format(path_element)
)

Expand All @@ -315,7 +310,7 @@ def googledrive_get_file(self, path: str):

folder = self.get_folder(splitted_path[0])
if folder is None:
raise MissingGoogleDriveFolderException(
raise exceptions.MissingGoogleDriveFolderException(
"Missing folder: {}".format(path[0])
)

Expand All @@ -327,7 +322,7 @@ def googledrive_get_file(self, path: str):
folder = self.__get_file(query, path_element)

if folder is None:
raise MissingGoogleDriveFolderException(
raise exceptions.MissingGoogleDriveFolderException(
"Missing folder: {}".format(path_element)
)

Expand Down Expand Up @@ -365,8 +360,8 @@ def __get_files(self, query: str):
page_token = next_page_token
return None
except HttpError as e:
http_error = GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise GoogleApiClientHttpErrorException(http_error)
http_error = models.GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise exceptions.GoogleApiClientHttpErrorException(http_error)


class SheetsService(GoogleService):
Expand Down Expand Up @@ -396,7 +391,7 @@ def create_spreadsheet(self, filename):
#
def get_file_values(self, spreadsheet_id, rows_range):
if spreadsheet_id is None:
raise MissingGoogleDriveFileException(
raise exceptions.MissingGoogleDriveFileException(
"Missing file: {}".format(spreadsheet_id)
)

Expand All @@ -422,8 +417,8 @@ def get_file_values(self, spreadsheet_id, rows_range):
self.cached_file_values.update({spreadsheet_id: {rows_range: values}})
return values
except HttpError as e:
http_error = GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise GoogleApiClientHttpErrorException(http_error)
http_error = models.GoogleApiClientHttpErrorBuilder().from_http_error(e)
raise exceptions.GoogleApiClientHttpErrorException(http_error)

def update_file_values(
self, spreadsheet_id, rows_range, value_input_option, values
Expand Down Expand Up @@ -506,7 +501,7 @@ def get_file_rows_from_folder(
google_file = super().googledrive_get_file(file_path)

if google_file is None:
raise MissingGoogleDriveFileException("Missing file: {}".format(filename))
raise exceptions.MissingGoogleDriveFileException("Missing file: {}".format(filename))

values = super().get_file_values(google_file.id, rows_range)

Expand Down
Loading