Skip to content

Commit

Permalink
Merge pull request #12 from tokejepsen/master
Browse files Browse the repository at this point in the history
pip install and multiple guis
  • Loading branch information
mottosso authored Oct 11, 2016
2 parents c032583 + bf29678 commit 0f279c0
Show file tree
Hide file tree
Showing 6 changed files with 848 additions and 31 deletions.
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,29 @@ It has a number of arguments.

```bash
$ python -m pyblish_standalone -h
usage: __main__.py [-h] [-d key value] [--path PATH]
usage: __main__.py [-h] [-d key value] [--path PATH] [--register-host HOSTNAME] [--register-gui GUINAME] [-debug]

optional arguments:
-h, --help show this help message and exit
-d key value, --data key value
Append data to context, can be called multiple times
-h, --help Show this help message and exit
-d KEY VALUE, --data KEY VALUE
Append data to context, can be called multiple times.
--path PATH Append path to PYBLISHPLUGINPATH, can be called
multiple times
multiple times.
-rh HOSTNAME, --register-host HOSTNAME
Register host name before starting the Pyblish.
-rg GUINAME, --register-gui GUINAME
Validates and uses the gui name in the order specified.
--debug Registers mock plugins for debugging.
```

You can also pass in a file, which will become the current file in the context

```bash
$ python -m pyblish_standalone "/path/to/file"
```
```python
>>> context.data["currentFile"]
"/path/to/file"
```

- See [the main Pyblish repository](https://github.com/pyblish/pyblish) for more information.
57 changes: 40 additions & 17 deletions pyblish_standalone/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
import sys
import time
import socket
import argparse

import executable
Expand All @@ -16,12 +14,18 @@ def cli():
parser.add_argument("-d", "--data", nargs=2, action="append",
metavar=("key", "value"),
help=("Append data to context, "
"can be called multiple times"))
"can be called multiple times."))
parser.add_argument("--path", action="append",
help=("Append path to PYBLISHPLUGINPATH, "
"can be called multiple times"))
parser.add_argument("-rh", "--register-host", action="append",
help=("Append hosts to register."))
help=("Register host name before "
"starting the Pyblish."))
parser.add_argument("-rg", "--register-gui", action="append",
help=("Validates and uses the gui name "
"in the order specified."))
parser.add_argument("--debug", action="store_true",
help=("Registers mock plugins for debugging."))

kwargs = parser.parse_args(sys.argv[1:])

Expand All @@ -36,23 +40,42 @@ def cli():

os.environ["PYBLISHPLUGINPATH"] = os.pathsep.join(pyblish_path)

# debug mode
if kwargs.debug:
from . import mock
import pyblish.api

for Plugin in mock.plugins:
pyblish.api.register_plugin(Plugin)

print "Enter debug mode..."

# collect hosts passed
hosts = kwargs.__dict__["register_host"]
if not hosts:
hosts = []
executable.start(hosts=hosts)

# register guis
gui = None
guis = []
try:
for g in kwargs.register_gui:
gui = __import__(g)
guis.append(g)
except:
import traceback
print traceback.format_exc()
pass

if gui:
print "Found gui: %s" % gui
else:
print "No valid guis registered in: %s" % guis
return

executable.start(gui, hosts=hosts)


if __name__ == "__main__":
cli()
print("Press Ctrl-C to quit..")

try:
while True:
time.sleep(1)
except (KeyboardInterrupt, SystemExit):
# Close GUI on terminal session end
try:
executable.stop()
except socket.error:
# QML client closed before host? No problem.
pass
executable.stop()
25 changes: 17 additions & 8 deletions pyblish_standalone/executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@
import socket

import pyblish.api
import pyblish_integration.lib


def start(hosts=[]):
"""Start Pyblish QML"""
def start(gui, hosts=[]):
""" This starts the supplied gui.
Loops through 5 attempts to show the gui, due to qml server nature.
It also registers any hosts along with it self "standalone".
Args:
gui (module): Module that has a "show" method.
hosts (list): List of host names to register before starting.
"""

pyblish.api.register_host("standalone")
for host in hosts:
pyblish.api.register_host(host)

pyblish_integration.setup()

max_tries = 5
while True:
try:
time.sleep(0.5)
pyblish_integration.show()
gui.show()
except socket.error as e:
if max_tries <= 0:
raise Exception("Couldn't run Pyblish QML: %s" % e)
Expand All @@ -32,5 +37,9 @@ def start(hosts=[]):


def stop():
"""Hide Pyblish QML"""
pyblish_integration.lib.proxy.hide()
""" Called when shutting down. """
try:
import pyblish_aftereffects
pyblish_aftereffects.stop_server()
except:
pass
Loading

0 comments on commit 0f279c0

Please sign in to comment.