From bfbdc020e743251b3a0c30dd50fbcb67c22a2b67 Mon Sep 17 00:00:00 2001 From: Alexandre LAURETTE Date: Wed, 12 Apr 2023 09:52:46 +0200 Subject: [PATCH] add docstring --- hooks/custom_infos.py | 3 +++ hooks/scene_infos_tk-maya.py | 5 +++++ hooks/send_report.py | 8 ++++++++ python/tk_multi_support/collector.py | 9 +++++++++ python/tk_multi_support/dialog.py | 17 ++++++++++++++--- .../factories/context_factory.py | 9 ++++++++- python/tk_multi_support/models/report.py | 7 +++++++ python/tk_multi_support/models/scene_infos.py | 1 + 8 files changed, 55 insertions(+), 4 deletions(-) diff --git a/hooks/custom_infos.py b/hooks/custom_infos.py index 9c60993..dbc576f 100644 --- a/hooks/custom_infos.py +++ b/hooks/custom_infos.py @@ -15,5 +15,8 @@ class CustomInfos(HookClass): + """Add custom informations to the report. This hook is called during the + generation of the report. + """ def collect(self, report): return report diff --git a/hooks/scene_infos_tk-maya.py b/hooks/scene_infos_tk-maya.py index 851c06c..ea9a1bf 100644 --- a/hooks/scene_infos_tk-maya.py +++ b/hooks/scene_infos_tk-maya.py @@ -17,6 +17,11 @@ class SceneInfos(HookClass): + + """Scene informations. It collects all informations like the current scene, + the DCC name and the DCC version. + """ + def collect(self, scene_infos): scene_infos.current_scene = self._get_scene_path() scene_infos.dcc_name = self._get_dcc_name() diff --git a/hooks/send_report.py b/hooks/send_report.py index 20f220f..009a4e5 100644 --- a/hooks/send_report.py +++ b/hooks/send_report.py @@ -16,6 +16,8 @@ class ReportSender(HookClass): + """Send the report. A new ticket will be created on ShotGrid.""" + CONTENT = ( "Content\n" "---\n" @@ -44,6 +46,8 @@ def send(self, report): :rtype: bool """ + self.logger.info("Sending the report on ShotGrid...") + description = self.CONTENT.format( content=report.content, project=report.context.project, @@ -69,8 +73,10 @@ def send(self, report): } sg_ticket = self.parent.shotgun.create("Ticket", data) + self.logger.info("A ticket has been created.") for thumbnail in report.thumbnails: + self.logger.info("Upload a thumbnail as attachment on the ticket.") self.parent.shotgun.upload( entity_type="Ticket", entity_id=sg_ticket.get("id"), @@ -78,4 +84,6 @@ def send(self, report): field_name="attachments", ) + self.logger.info("The report has been sent on ShotGrid.") + return True diff --git a/python/tk_multi_support/collector.py b/python/tk_multi_support/collector.py index b87a0b0..f04d98b 100644 --- a/python/tk_multi_support/collector.py +++ b/python/tk_multi_support/collector.py @@ -15,7 +15,16 @@ class DataCollector(object): + """DataCollector collect all informations to build the report. To do that, + it calls somes hooks. + """ + def collect(self): + """Collect all informations and build a report + + :return: The generated Report + :rtype: tk_multi_support.models.Report + """ app = sgtk.platform.current_bundle() # Collect informations about the scene and the DCC diff --git a/python/tk_multi_support/dialog.py b/python/tk_multi_support/dialog.py index ebc49b3..52d8fb2 100644 --- a/python/tk_multi_support/dialog.py +++ b/python/tk_multi_support/dialog.py @@ -34,7 +34,7 @@ def show_dialog(app_instance): # we pass the dialog class to this method and leave the actual construction # to be carried out by toolkit. app_instance.engine.show_dialog( - "Report a problem...", app_instance, AppDialog + "Contact Studio Support", app_instance, AppDialog ) @@ -73,7 +73,8 @@ def __init__(self): @QtCore.Slot() def on_send_report_requested(self): - + """Called when the Report need to be send.""" + logger.info("The report will be sent...") self._report.subject = self.lie_subject.text() self._report.content = self.txe_content.toPlainText() @@ -82,16 +83,26 @@ def on_send_report_requested(self): ) self.close() + logger.info("Closing the app.") @QtCore.Slot(object) def on_thumbnail_created(self, pixmap): + """Called when a thumbnail has been created. + + :param pixmap: The thumbnail + :type pixmap: QPixmap + """ + logger.info("A new thumbnail has been taken") # TODO Move this code outside from here - temp_path = os.path.join(tempfile.gettempdir(), "test.jpg") + temp_path = os.path.join(tempfile.gettempdir(), "tk-multi-support.jpg") pixmap.save(temp_path) self._report.thumbnails = [temp_path] # TODO allows mutiple thumbs ? @QtCore.Slot() def on_text_edited(self, *args, **kwargs): + """Called when the subject or the content field is edited. It enable + or disable the send button. + """ if not self.lie_subject.text(): self.pub_send.setEnabled(False) return diff --git a/python/tk_multi_support/factories/context_factory.py b/python/tk_multi_support/factories/context_factory.py index bf37df2..4251267 100644 --- a/python/tk_multi_support/factories/context_factory.py +++ b/python/tk_multi_support/factories/context_factory.py @@ -14,9 +14,11 @@ class ContextFactory(object): + """Simple factory to build a context object from the sgtk context.""" + @classmethod def build(cls, tk_ctx): - """Build the context object + """Build the context object from the sgtk context :param tk_ctx: The context from sgtk :type tk_ctx: sgtk.Context @@ -40,6 +42,11 @@ def build(cls, tk_ctx): @staticmethod def urljoin(*parts): + """Build a url from given parts. It works like os.path.join. + + :return: The url + :rtype: str + """ return "/".join(str(part).strip("/") for part in parts) @classmethod diff --git a/python/tk_multi_support/models/report.py b/python/tk_multi_support/models/report.py index b281373..d0cdb75 100644 --- a/python/tk_multi_support/models/report.py +++ b/python/tk_multi_support/models/report.py @@ -10,6 +10,13 @@ class Report(object): + """The report contains all informations about the scene, the context, + the subject, the content and thubmnails. + It is used to send the ticket on ShotGrid. + + It is not a true DTO because we can add other attributes on this object and + default attributes are not protected with properties. + """ def __init__( self, scene_infos, context, subject="", content="", thumbnails=None ): diff --git a/python/tk_multi_support/models/scene_infos.py b/python/tk_multi_support/models/scene_infos.py index 5bf2a91..6450984 100644 --- a/python/tk_multi_support/models/scene_infos.py +++ b/python/tk_multi_support/models/scene_infos.py @@ -10,6 +10,7 @@ class SceneInfos(object): + """This object contains all informations of the scene.""" def __init__(self, dcc_name=None, dcc_version=None, scene_path=None): self.dcc_name = dcc_name self.dcc_version = dcc_version