brynq-sdk-google-drive 1.0.1__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {brynq_sdk_google_drive-1.0.1 → brynq_sdk_google_drive-2.0.0}/PKG-INFO +1 -1
- {brynq_sdk_google_drive-1.0.1 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive/google_drive.py +17 -15
- {brynq_sdk_google_drive-1.0.1 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive.egg-info/PKG-INFO +1 -1
- {brynq_sdk_google_drive-1.0.1 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive.egg-info/requires.txt +1 -1
- {brynq_sdk_google_drive-1.0.1 → brynq_sdk_google_drive-2.0.0}/setup.py +2 -2
- {brynq_sdk_google_drive-1.0.1 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive/__init__.py +0 -0
- {brynq_sdk_google_drive-1.0.1 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive.egg-info/SOURCES.txt +0 -0
- {brynq_sdk_google_drive-1.0.1 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive.egg-info/dependency_links.txt +0 -0
- {brynq_sdk_google_drive-1.0.1 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive.egg-info/not-zip-safe +0 -0
- {brynq_sdk_google_drive-1.0.1 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive.egg-info/top_level.txt +0 -0
- {brynq_sdk_google_drive-1.0.1 → brynq_sdk_google_drive-2.0.0}/setup.cfg +0 -0
{brynq_sdk_google_drive-1.0.1 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive/google_drive.py
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
-
from typing import List, Union
|
|
2
|
+
from typing import List, Union, Literal, Optional
|
|
3
3
|
import requests
|
|
4
4
|
import json
|
|
5
5
|
from io import BytesIO
|
|
@@ -9,25 +9,31 @@ from googleapiclient.http import MediaFileUpload
|
|
|
9
9
|
from brynq_sdk_brynq import BrynQ
|
|
10
10
|
|
|
11
11
|
class GoogleDrive(BrynQ):
|
|
12
|
-
def __init__(self,
|
|
12
|
+
def __init__(self, system_type: Optional[Literal['source', 'target']] = None, debug: bool = False):
|
|
13
13
|
"""
|
|
14
14
|
:param label: label of the Google Drive system in BrynQ
|
|
15
15
|
:param debug: set to True to enable debug logging
|
|
16
16
|
"""
|
|
17
17
|
super().__init__()
|
|
18
18
|
api_version = 'v3'
|
|
19
|
+
self.system_type = system_type
|
|
19
20
|
self.base_url = f'https://www.googleapis.com/drive/{api_version}/'
|
|
20
|
-
credentials = self.
|
|
21
|
+
credentials = self.interfaces.credentials.get(system="google-drive", system_type=system_type)
|
|
22
|
+
self.credentials = credentials.get('data')
|
|
21
23
|
self.debug = debug
|
|
22
24
|
if self.debug:
|
|
23
25
|
print(f"credentials: {credentials}")
|
|
24
|
-
self.access_token = credentials['
|
|
25
|
-
self.brynq_system_id = credentials['id']
|
|
26
|
+
self.access_token = credentials['access_token']
|
|
26
27
|
self.timeout = 3600
|
|
27
28
|
|
|
29
|
+
def _refresh_credentials(self):
|
|
30
|
+
credentials = self.interfaces.credentials.get(system="sharepoint", system_type=self.system_type)
|
|
31
|
+
credentials = credentials.get('data')
|
|
32
|
+
self.access_token = credentials['access_token']
|
|
33
|
+
|
|
28
34
|
def _get_google_drive_headers(self):
|
|
29
|
-
|
|
30
|
-
headers = {'Authorization': f'Bearer {access_token}'}
|
|
35
|
+
self._refresh_credentials()
|
|
36
|
+
headers = {'Authorization': f'Bearer {self.access_token}'}
|
|
31
37
|
if self.debug:
|
|
32
38
|
print(headers)
|
|
33
39
|
return headers
|
|
@@ -56,8 +62,7 @@ class GoogleDrive(BrynQ):
|
|
|
56
62
|
local_file_path: local path of the file you want to upload
|
|
57
63
|
remote_file_path: remote path of the folder and filename where you want to place the file
|
|
58
64
|
"""
|
|
59
|
-
|
|
60
|
-
service = build('drive', 'v3', credentials=credentials)
|
|
65
|
+
service = build('drive', 'v3', credentials=self.credentials)
|
|
61
66
|
|
|
62
67
|
file_metadata = {'name': os.path.basename(remote_file_path)}
|
|
63
68
|
media = MediaFileUpload(local_file_path, resumable=True)
|
|
@@ -94,8 +99,7 @@ class GoogleDrive(BrynQ):
|
|
|
94
99
|
local_folder_path: local folder where the files will be downloaded to
|
|
95
100
|
remote_folder_path: remote path of the folder you want to get on Google Drive
|
|
96
101
|
"""
|
|
97
|
-
|
|
98
|
-
service = build('drive', 'v3', credentials=credentials)
|
|
102
|
+
service = build('drive', 'v3', credentials=self.credentials)
|
|
99
103
|
|
|
100
104
|
# List files in the specified remote folder
|
|
101
105
|
query = f"'{remote_folder_path}' in parents"
|
|
@@ -130,8 +134,7 @@ class GoogleDrive(BrynQ):
|
|
|
130
134
|
remote_file_path: complete path including filename
|
|
131
135
|
:return: response from Google Drive
|
|
132
136
|
"""
|
|
133
|
-
|
|
134
|
-
service = build('drive', 'v3', credentials=credentials)
|
|
137
|
+
service = build('drive', 'v3', credentials=self.credentials)
|
|
135
138
|
|
|
136
139
|
# Find the file ID
|
|
137
140
|
query = f"name = '{remote_file_path}'"
|
|
@@ -153,8 +156,7 @@ class GoogleDrive(BrynQ):
|
|
|
153
156
|
Remove a folder from Google Drive
|
|
154
157
|
folder: folder id that you want to delete
|
|
155
158
|
"""
|
|
156
|
-
|
|
157
|
-
service = build('drive', 'v3', credentials=credentials)
|
|
159
|
+
service = build('drive', 'v3', credentials=self.credentials)
|
|
158
160
|
|
|
159
161
|
response = service.files().delete(fileId=folder_id).execute()
|
|
160
162
|
if self.debug:
|
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_namespace_packages
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name='brynq_sdk_google_drive',
|
|
5
|
-
version='
|
|
5
|
+
version='2.0.0',
|
|
6
6
|
description='Google Drive wrapper from BrynQ',
|
|
7
7
|
long_description='Groogle Drive wrapper from BrynQ',
|
|
8
8
|
author='BrynQ',
|
|
@@ -10,7 +10,7 @@ setup(
|
|
|
10
10
|
packages=find_namespace_packages(include=['brynq_sdk*']),
|
|
11
11
|
license='BrynQ License',
|
|
12
12
|
install_requires=[
|
|
13
|
-
'brynq-sdk-brynq>=
|
|
13
|
+
'brynq-sdk-brynq>=4,<5',
|
|
14
14
|
'google-api-python-client>=2,<3',
|
|
15
15
|
'requests>=2,<=3'
|
|
16
16
|
],
|
{brynq_sdk_google_drive-1.0.1 → brynq_sdk_google_drive-2.0.0}/brynq_sdk_google_drive/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|