Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1039 from pypeclub/feature/publish_cli_command
Browse files Browse the repository at this point in the history
Publish command in Pype cli
  • Loading branch information
mkolar authored Mar 3, 2021
2 parents ab03c28 + 56f855d commit d64083d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
5 changes: 2 additions & 3 deletions pype/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,16 @@ def extractenvironments(output_json_path, project, asset, task, app):

@main.command()
@click.argument("paths", nargs=-1)
@click.option("-g", "--gui", is_flag=True, help="Run pyblish GUI")
@click.option("-d", "--debug", is_flag=True, help="Print debug messages")
def publish(gui, debug, paths):
def publish(debug, paths):
"""Start CLI publishing.
Publish collects json from paths provided as an argument.
More than one path is allowed.
"""
if debug:
os.environ['PYPE_DEBUG'] = '3'
PypeCommands().publish(gui, list(paths))
PypeCommands.publish(list(paths))


@main.command()
Expand Down
47 changes: 44 additions & 3 deletions pype/pype_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,50 @@ def launch_standalone_publisher():
standalonepublish.main()

@staticmethod
def publish(paths):
"""Start headless publishing.
Publish use json from passed paths argument.
Args:
paths (list): Paths to jsons.
Raises:
RuntimeError: When there is no pathto process.
"""
if not any(paths):
raise RuntimeError("No publish paths specified")

from pype import install, uninstall
from pype.api import Logger

# Register target and host
import pyblish.api
import pyblish.util

log = Logger.get_logger()

install()

pyblish.api.register_target("filesequence")
pyblish.api.register_host("shell")

os.environ["PYPE_PUBLISH_DATA"] = os.pathsep.join(paths)

log.info("Running publish ...")

# Error exit as soon as any error occurs.
error_format = "Failed {plugin.__name__}: {error} -- {error.traceback}"

for result in pyblish.util.publish_iter():
if result["error"]:
log.error(error_format.format(**result))
uninstall()
sys.exit(1)

log.info("Publish finished.")
uninstall()

def extractenvironments(output_json_path, project, asset, task, app):
env = os.environ.copy()
if all((project, asset, task, app)):
Expand All @@ -57,9 +101,6 @@ def extractenvironments(output_json_path, project, asset, task, app):
with open(output_json_path, "w") as file_stream:
json.dump(env, file_stream, indent=4)

def publish(self, gui, paths):
pass

def texture_copy(self, project, asset, path):
pass

Expand Down

0 comments on commit d64083d

Please sign in to comment.