Skip to content

Commit

Permalink
Little fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jhodges10 committed May 23, 2024
1 parent e352505 commit 01867dc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
25 changes: 13 additions & 12 deletions frameioclient/lib/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
self.session = None
self.filename = Utils.normalize_filename(asset["name"])
self.request_logs = list()
self.stats = True
self.stats = False

self._evaluate_asset()
self._get_path()
Expand Down Expand Up @@ -411,17 +411,18 @@ def multi_thread_download(self):
pprint(self.downloader)
download_speed = round((self.downloader.filesize / download_time), 2)

if self.downloader.checksum_verification == True:
# Check for checksum, if not present throw error
if self.downloader._get_checksum() == None:
raise AssetChecksumNotPresent

# Calculate the file hash
if (
Utils.calculate_hash(self.destination)
!= self.downloader.original_checksum
):
raise AssetChecksumMismatch
# TODO: Ensure this works correctly on assets that are missing checksums/at all
# if self.downloader.checksum_verification == True:
# # Check for checksum, if not present throw error
# if self.downloader._get_checksum() == None:
# raise AssetChecksumNotPresent

# # Calculate the file hash
# if (
# Utils.calculate_hash(self.destination)
# != self.downloader.original_checksum
# ):
# raise AssetChecksumMismatch

# Log completion event
SDKLogger("downloads").info(
Expand Down
4 changes: 4 additions & 0 deletions frameioclient/lib/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ def _api_call(

if r.status_code == 422 and "presentation" in endpoint:
raise PresentationException

if r.status_code == 500 and 'audit' in endpoint:
print(f"Hit a 500 on page: {r.headers.get('page-number')}, url: {r.url}")
return []

return r.raise_for_status()

Expand Down
7 changes: 6 additions & 1 deletion frameioclient/services/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def create(
"type": type,
"filesize": filesize,
"filetype": filetype,
"properties": {"reference_id": "7eaa2f13-1202-42b3-a360-9d21e9a9efa7"},
}

endpoint = "/assets/{}/children".format(parent_asset_id)
Expand Down Expand Up @@ -356,6 +357,10 @@ def upload(
except Exception as e:
print(e)

else:
with open(file_info["filepath"], "rb") as fp:
self._upload(asset, fp)

return asset

def download(
Expand Down Expand Up @@ -393,7 +398,7 @@ def upload_folder(self, source_path: str, destination_id: Union[str, UUID]):
Example::
client.assets.upload("./file.mov", "1231-12414-afasfaf-aklsajflaksjfla")
client.assets.upload("./file.mov", "1231-12414-afasfaf-aklsajflaksjfla")
"""

# Check if destination is a project or folder
Expand Down
22 changes: 14 additions & 8 deletions frameioclient/services/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_assets_recursively(self, asset_id, slim=True):
assets = self.client.assets.get_children(asset_id, slim=slim)
print("Number of assets at top level", len(assets))

for asset in assets:
for index, asset in enumerate(assets):
# try:
print(
f"Type: {asset['_type']}, Name: {asset['name']}, Children: {len(asset['children'])}"
Expand All @@ -57,7 +57,7 @@ def get_assets_recursively(self, asset_id, slim=True):
if asset["_type"] == "version_stack":
print("Grabbing top item from version stack")
versions = self.client.assets.get_children(asset["id"], slim=True)
asset = versions[0] # re-assign on purpose
assets[index]['children'] = versions # re-assign on purpose
continue

# We only get the first three items when we use "include=children"
Expand Down Expand Up @@ -97,10 +97,8 @@ def download_project(self, project_id, destination):
project = self.client.projects.get(project_id)
initial_tree = self.get_assets_recursively(project["root_asset_id"])
self.recursive_downloader(destination, initial_tree)
# pprint(initial_tree)
# print(f"Downloading {Utils.format_bytes(total_bytes, type='size')}")

def recursive_downloader(self, directory, asset, count=0):
def recursive_downloader(self, directory, asset, manifest=[]):
print(f"Directory {directory}")

try:
Expand All @@ -121,7 +119,7 @@ def recursive_downloader(self, directory, asset, count=0):
try:
if asset["_type"] == "folder":
if len(asset["children"]) >= 0:
count += 1
# count += 1
# Create the new folder that these items will go in before it's too late
if not os.path.exists(
os.path.join(target_directory, asset["name"])
Expand All @@ -139,17 +137,25 @@ def recursive_downloader(self, directory, asset, count=0):
self.recursive_downloader(
f"{directory}/{str(asset['name']).replace('/', '-')}",
asset["children"],
manifest
)

if asset["_type"] == "file":
count += 1
return self.client.assets.download(
# count += 1
fn = self.client.assets.download(
asset, target_directory, multi_part=True
)
manifest.append({
"asset_id": asset['id'],
"file_path": fn,
"directory": target_directory
})


except Exception as e:
print(e)

pprint(manifest)
return True


Expand Down

0 comments on commit 01867dc

Please sign in to comment.