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

APS Upload Pipeline Polish #1048

Merged
merged 3 commits into from
Jul 25, 2024
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
24 changes: 14 additions & 10 deletions exporter/SynthesisFusionAddin/src/APS/APS.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import logging
import os
import pathlib
import pickle
Expand All @@ -12,6 +11,9 @@
import requests

from ..general_imports import INTERNAL_ID, gm, my_addin_path
from ..Logging import getLogger

logger = getLogger()

CLIENT_ID = "GCxaewcLjsYlK8ud7Ka9AKf9dPwMR3e4GlybyfhAK2zvl3tU"
auth_path = os.path.abspath(os.path.join(my_addin_path, "..", ".aps_auth"))
Expand Down Expand Up @@ -65,20 +67,22 @@ def getAuth() -> APSAuth | None:
global APS_AUTH
if APS_AUTH is not None:
return APS_AUTH
try:
curr_time = time.time()

currTime = time.time()
if os.path.exists(auth_path):
Copy link
Member

@azaleacolburn azaleacolburn Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it display a messagebox or smth if the path is invalid?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking not. Just means that the user is not currently logged in / has never logged in before. But this could be up for debate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg I'm dumb, I was thinking of the download path oml, totally out of the scope of this PR + smth that won't ever be undefined. 🤦‍♀️

with open(auth_path, "rb") as f:
p: APSAuth = pickle.load(f)
logging.getLogger(f"{INTERNAL_ID}").info(msg=f"{json.dumps(p.__dict__)}")
APS_AUTH = p
except Exception as arg:
gm.ui.messageBox(f"ERROR:\n{arg}", "Please Sign In")
else:
return None
curr_time = int(time.time() * 1000)
if curr_time >= APS_AUTH.expires_at:

currTime = int(time.time() * 1000)
if currTime >= APS_AUTH.expires_at:
refreshAuthToken()

if APS_USER_INFO is None:
_ = loadUserInfo()

return APS_AUTH


Expand Down Expand Up @@ -140,7 +144,7 @@ def refreshAuthToken():
f.close()
except urllib.request.HTTPError as e:
removeAuth()
logging.getLogger(f"{INTERNAL_ID}").error(f"Refresh Error:\n{e.code} - {e.reason}")
logger.error(f"Refresh Error:\n{e.code} - {e.reason}")
gm.ui.messageBox("Please sign in again.")


Expand Down Expand Up @@ -172,7 +176,7 @@ def loadUserInfo() -> APSUserInfo | None:
return APS_USER_INFO
except urllib.request.HTTPError as e:
removeAuth()
logging.getLogger(f"{INTERNAL_ID}").error(f"User Info Error:\n{e.code} - {e.reason}")
logger.error(f"User Info Error:\n{e.code} - {e.reason}")
gm.ui.messageBox("Please sign in again.")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from proto.proto_out import assembly_pb2, types_pb2

from ...APS.APS import upload_mirabuf # This line causes everything to break
from ...APS.APS import getAuth, upload_mirabuf
from ...general_imports import *
from ...Logging import getLogger, logFailure, timed
from ...Types import ExportLocation, ExportMode
Expand All @@ -34,6 +34,10 @@ def export(self) -> None:
app = adsk.core.Application.get()
design: adsk.fusion.Design = app.activeDocument.design

if not getAuth():
app.userInterface.messageBox("APS Login Required for Uploading.", "APS Login")
return

assembly_out = assembly_pb2.Assembly()
fill_info(
assembly_out,
Expand Down Expand Up @@ -178,9 +182,9 @@ def export(self) -> None:
folder_id = project.rootFolder.id
file_name = f"{self.exporterOptions.fileLocation}.mira"
if upload_mirabuf(project_id, folder_id, file_name, assembly_out.SerializeToString()) is None:
gm.ui.messageBox("FAILED TO UPLOAD FILE TO APS", "ERROR") # add throw later
# Download Mirabuf File
raise RuntimeError("Could not upload to APS")
else:
assert self.exporterOptions.exportLocation == ExportLocation.DOWNLOAD
Comment on lines 186 to +187
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot that enums could be undefined 🤦‍♀️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm more so just checking to make sure we don't add different export locations in the future. Sort of a "this was the entire behaviour of ExportLocation when I wrote this code so it may need to be updated" type of thing. But yea I suppose it will also catch if it is None as well.

# check if entire path exists and create if not since gzip doesn't do that.
path = pathlib.Path(self.exporterOptions.fileLocation).parent
path.mkdir(parents=True, exist_ok=True)
Expand Down
1 change: 0 additions & 1 deletion exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ def notify(self, args):
"aps_settings", f"APS Settings ({user_info.given_name if user_info else 'Not Signed In'})"
)
apsSettings.tooltip = "Configuration settings for Autodesk Platform Services."
aps_input = apsSettings.children

# clear all selections before instantiating handlers.
gm.ui.activeSelections.clear()
Expand Down
Loading