Skip to content

Commit

Permalink
add docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre LAURETTE committed Apr 12, 2023
1 parent 85590f3 commit bfbdc02
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 4 deletions.
3 changes: 3 additions & 0 deletions hooks/custom_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions hooks/scene_infos_tk-maya.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions hooks/send_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

class ReportSender(HookClass):

"""Send the report. A new ticket will be created on ShotGrid."""

CONTENT = (
"Content\n"
"---\n"
Expand Down Expand Up @@ -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,
Expand All @@ -69,13 +73,17 @@ 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"),
path=thumbnail,
field_name="attachments",
)

self.logger.info("The report has been sent on ShotGrid.")

return True
9 changes: 9 additions & 0 deletions python/tk_multi_support/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions python/tk_multi_support/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)


Expand Down Expand Up @@ -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()

Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion python/tk_multi_support/factories/context_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions python/tk_multi_support/models/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand Down
1 change: 1 addition & 0 deletions python/tk_multi_support/models/scene_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bfbdc02

Please sign in to comment.