Skip to content

Commit

Permalink
Made importer app compatible with threading
Browse files Browse the repository at this point in the history
  • Loading branch information
gillesvink committed Jun 21, 2022
1 parent 2a77755 commit 429abc7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[![Python 2.6 2.7 3.7](https://img.shields.io/badge/python-2.6%20%7C%202.7%20%7C%203.7-blue.svg)](https://www.python.org/)
[![Build Status](https://dev.azure.com/shotgun-ecosystem/Toolkit/_apis/build/status/Apps/tk-multi-starterapp?branchName=master)](https://dev.azure.com/shotgun-ecosystem/Toolkit/_build/latest?definitionId=57&branchName=master)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Linting](https://img.shields.io/badge/PEP8%20by-Hound%20CI-a873d1.svg)](https://houndci.com)
[![PEP8](https://img.shields.io/badge/code%20style-pep8-orange.svg)](https://www.python.org/dev/peps/pep-0008/)

# ShotGrid Library Importer App
This desktop app will provide a GUI to import a complete stock library.
It will create an asset grouped per scene, transcode with FFMPEG a preview for ShotGrid, and create a version for every asset.

![ShotGrid Library Importer user interface](resources/tk-desktop-libraryimporter.png)
18 changes: 12 additions & 6 deletions python/app/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import tempfile
import shutil
import re
import time
from datetime import datetime

# by importing QT from sgtk rather than directly, we ensure that
Expand Down Expand Up @@ -81,7 +82,7 @@ def __init__(self):

# Connecting logic
self.ui.browseDirectory.clicked.connect(self.file_browser)
self.ui.executeButton.clicked.connect(self.execute_importing)
self.ui.executeButton.clicked.connect(self.execute)

def file_browser(self):
# Creating file browser
Expand All @@ -105,13 +106,17 @@ def output_to_console(self, message):
previous_text = self.ui.console.toPlainText()
current_time = datetime.now()
current_time = current_time.strftime("%H:%M:%S")
current_time = "[" + str(current_time) + "] "
current_time = "[%s] " % str(current_time)

if not previous_text == "":
self.ui.console.insertPlainText("\n" + current_time + message)
else:
self.ui.console.insertPlainText(current_time + message)

def execute(self):
thread = threading.Thread(target=self.execute_importing())
thread.start()

def execute_importing(self):
# Getting directory path
directory_path = self.ui.directoryPath.text()
Expand Down Expand Up @@ -210,11 +215,14 @@ def import_library(self, directory_path):
+ ", adding stock to this category."
)

thread = threading.Thread(target=self.import_sub_directory, args=(directory_path, library_project_id, category_id, status, ))
thread.start()

def import_sub_directory(self, directory_path, library_project_id, category_id, status):
# Creating asset per filename and generate quicktime, afterwards upload to ShotGrid
for subdir, dir, files in os.walk(directory_path):
dir_list = os.listdir(subdir)

if any(".exr" in dirNames for dirNames in dir_list):
if any(".exr" in dir_names for dir_names in dir_list):
# exr logic
file_sequences = self.get_frame_sequences(subdir)
for sequence in file_sequences:
Expand Down Expand Up @@ -300,8 +308,6 @@ def import_library(self, directory_path):
file_path, file_name, version_id, "file"
)

# Message when everything is done
self.output_to_console("Done importing.")

def generate_asset(self, project_id, category_id, file_name, status):
# Getting ShotGrid object
Expand Down
Binary file added resources/tk-desktop-libraryimporter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 429abc7

Please sign in to comment.