From 5aa1ab068e6b5ce4d24ac1fdb282be572f1508c6 Mon Sep 17 00:00:00 2001 From: BrandonPacewic Date: Thu, 25 Jul 2024 09:56:22 -0700 Subject: [PATCH 1/3] Avoid throwing a message box error for not being signed in --- exporter/SynthesisFusionAddin/src/APS/APS.py | 15 +++++++++------ .../SynthesisFusionAddin/src/UI/ConfigCommand.py | 1 - 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/exporter/SynthesisFusionAddin/src/APS/APS.py b/exporter/SynthesisFusionAddin/src/APS/APS.py index 22543438e1..452f07521b 100644 --- a/exporter/SynthesisFusionAddin/src/APS/APS.py +++ b/exporter/SynthesisFusionAddin/src/APS/APS.py @@ -65,20 +65,23 @@ 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 diff --git a/exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py b/exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py index e446b18909..038ca3e19e 100644 --- a/exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py +++ b/exporter/SynthesisFusionAddin/src/UI/ConfigCommand.py @@ -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() From b2352e56f5dd5276019cf4f9a5a220a7f5f1839d Mon Sep 17 00:00:00 2001 From: BrandonPacewic Date: Thu, 25 Jul 2024 11:45:50 -0700 Subject: [PATCH 2/3] Now prompt for login before export start --- .../src/Parser/SynthesisParser/Parser.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Parser.py b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Parser.py index df7670ddf5..692b21cab2 100644 --- a/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Parser.py +++ b/exporter/SynthesisFusionAddin/src/Parser/SynthesisParser/Parser.py @@ -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 @@ -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, @@ -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) From 705b748d6a551fa92d3d4087fa4d856e9507caa9 Mon Sep 17 00:00:00 2001 From: BrandonPacewic Date: Thu, 25 Jul 2024 13:54:09 -0700 Subject: [PATCH 3/3] Updated logging module usage and removed auth token log --- exporter/SynthesisFusionAddin/src/APS/APS.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/exporter/SynthesisFusionAddin/src/APS/APS.py b/exporter/SynthesisFusionAddin/src/APS/APS.py index 452f07521b..a65728ec23 100644 --- a/exporter/SynthesisFusionAddin/src/APS/APS.py +++ b/exporter/SynthesisFusionAddin/src/APS/APS.py @@ -1,5 +1,4 @@ import json -import logging import os import pathlib import pickle @@ -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")) @@ -70,7 +72,6 @@ def getAuth() -> APSAuth | None: 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 else: return None @@ -143,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.") @@ -175,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.")