Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce logging, telemetry, progress bars, transport layers, improved doc strings #73

Merged
merged 4 commits into from
Aug 3, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions frameioclient/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
from .lib import *
from .services import *
from .client import FrameioClient
<<<<<<<

=======
from .service import *
from .lib import *
>>>>>>>
5 changes: 1 addition & 4 deletions frameioclient/client.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from .lib import (
Utils,
APIClient,
AWSClient,
Telemetry,
ClientVersion,
ClientVersion,
FrameioDownloader
)

class FrameioClient(APIClient, object):
def __init__(self, token, host):
def __init__(self, token, host='https://api.frame.io'):
super().__init__(token, host)

@property
Expand Down Expand Up @@ -41,7 +39,6 @@ def users(self):
def assets(self):
from .services import Asset
return Asset(self)
total=3,

@property
def comments(self):
Expand Down
4 changes: 2 additions & 2 deletions frameioclient/lib/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, asset, download_folder, prefix, multi_part=False, concurrency
self.in_progress = 0
self.filename = Utils.normalize_filename(asset["name"])
self.request_logs = list()
self.session = AWSClient()._get_session(auth=None)
self.session = AWSClient()._get_session()

self._evaluate_asset()

Expand Down Expand Up @@ -135,7 +135,7 @@ def single_part_download(self, url):
print("Beginning download -- {} -- {}".format(self.asset["name"], Utils.format_bytes(self.file_size, type="size")))

# Downloading
r = requests.get(url)
r = self.session.get(url)
open(self.destination, "wb").write(r.content)

download_time = time.time() - start_time
Expand Down
27 changes: 12 additions & 15 deletions frameioclient/lib/transport.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import os
import logging
import enlighten
import requests
import threading
import concurrent.futures

from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
Expand Down Expand Up @@ -34,7 +32,7 @@ def __init__(self):
def _initialize_thread(self):
self.thread_local = threading.local()

def _get_session(self, auth=True):
def _get_session(self):
if not hasattr(self.thread_local, "session"):
http = requests.Session()
adapter = HTTPAdapter(max_retries=self.retry_strategy)
Expand All @@ -46,24 +44,23 @@ def _get_session(self, auth=True):


class APIClient(HTTPClient, object):
def __init__(self, token, host='https://api.frame.io'):
def __init__(self, token, host):
super().__init__()
self.host = host
self.token = token
self._initialize_thread()
self.session = self._get_session(auth=token)
self.session = self._get_session()
self.auth_header = {
'Authorization': 'Bearer {}'.format(self.token),
}

def _format_api_call(self, endpoint):
return '{}/v2{}'.format(self.host, endpoint)

def _api_call(self, method, endpoint, payload={}, limit=None):
url = '{}/v2{}'.format(self.host, endpoint)

headers = {**self.shared_headers, **self.auth_header}

r = self.session.request(
method,
url,
url=self._format_api_call(endpoint),
headers=self.auth_header,
json=payload
)
Expand Down Expand Up @@ -97,14 +94,14 @@ def get_specific_page(self, method, endpoint, payload, page):
Gets a specific page for that endpoint, used by Pagination Class

:Args:
method (string): 'get', 'post'
endpoint (string): endpoint ('/accounts/<ACCOUNT_ID>/teams')
payload (dict): Request payload
page (int): What page to get
method (string): 'get', 'post'
endpoint (string): endpoint ('/accounts/<ACCOUNT_ID>/teams')
payload (dict): Request payload
page (int): What page to get
"""
if method == 'get':
endpoint = '{}?page={}'.format(endpoint, page)
return self._api_call(method, endpoint)
return self._api_call(method, endpoint)

if method == 'post':
payload['page'] = page
Expand Down
13 changes: 11 additions & 2 deletions frameioclient/service/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def upload(self, destination_id, filepath, asset=None):

return asset

def download(self, asset, download_folder, prefix=None, multi_part=False, concurrency=5):
def download(self, asset, download_folder, prefix=None, multi_part=False, concurrency=5, stats=False):
"""
Download an asset. The method will exit once the file is downloaded.

Expand All @@ -241,5 +241,14 @@ def download(self, asset, download_folder, prefix=None, multi_part=False, concur

client.assets.download(asset, "~./Downloads")
"""
downloader = FrameioDownloader(asset, download_folder, prefix, multi_part, concurrency)
downloader = FrameioDownloader(
asset,
download_folder,
prefix,
multi_part,
concurrency,
user_id=self.client.me['id'],
stats=stats
)

return downloader.download_handler()
7 changes: 0 additions & 7 deletions frameioclient/services/__init__.py

This file was deleted.

233 changes: 0 additions & 233 deletions frameioclient/services/assets.py

This file was deleted.