Skip to content

Commit

Permalink
APS Upload Pipeline Polish (#1048)
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterBarclay authored Jul 25, 2024
2 parents bf4cdb4 + 705b748 commit df36e28
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
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):
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
# 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

0 comments on commit df36e28

Please sign in to comment.