|
| 1 | +import os |
| 2 | +import importlib |
| 3 | +from pyblish import api as pyblish |
| 4 | +from avalon import api |
| 5 | +import logging |
| 6 | + |
| 7 | + |
| 8 | +log = logging.getLogger(__name__) |
| 9 | + |
| 10 | +AVALON_CONFIG = os.environ["AVALON_CONFIG"] |
| 11 | + |
| 12 | + |
| 13 | +def ls(): |
| 14 | + pass |
| 15 | + |
| 16 | + |
| 17 | +def reload_pipeline(): |
| 18 | + """Attempt to reload pipeline at run-time. |
| 19 | +
|
| 20 | + CAUTION: This is primarily for development and debugging purposes. |
| 21 | +
|
| 22 | + """ |
| 23 | + |
| 24 | + import importlib |
| 25 | + |
| 26 | + api.uninstall() |
| 27 | + |
| 28 | + for module in ("avalon.io", |
| 29 | + "avalon.lib", |
| 30 | + "avalon.pipeline", |
| 31 | + "avalon.api", |
| 32 | + "avalon.tools", |
| 33 | + |
| 34 | + "avalon.tools.loader.app", |
| 35 | + "avalon.tools.creator.app", |
| 36 | + "avalon.tools.manager.app", |
| 37 | + |
| 38 | + "avalon.aport", |
| 39 | + "avalon.aport.pipeline", |
| 40 | + "{}".format(AVALON_CONFIG) |
| 41 | + ): |
| 42 | + log.info("Reloading module: {}...".format(module)) |
| 43 | + module = importlib.import_module(module) |
| 44 | + reload(module) |
| 45 | + |
| 46 | + import avalon.aport |
| 47 | + api.install(avalon.aport) |
| 48 | + |
| 49 | + |
| 50 | +def install(config): |
| 51 | + """Install Aport-specific functionality of avalon-core. |
| 52 | +
|
| 53 | + This is where you install menus and register families, data |
| 54 | + and loaders into Aport. |
| 55 | +
|
| 56 | + It is called automatically when installing via `api.install(avalon.aport)`. |
| 57 | +
|
| 58 | + See the Maya equivalent for inspiration on how to implement this. |
| 59 | +
|
| 60 | + """ |
| 61 | + |
| 62 | + pyblish.register_host("aport") |
| 63 | + # Trigger install on the config's "aport" package |
| 64 | + config = find_host_config(config) |
| 65 | + |
| 66 | + if hasattr(config, "install"): |
| 67 | + config.install() |
| 68 | + |
| 69 | + log.info("config.aport installed") |
| 70 | + |
| 71 | + |
| 72 | +def find_host_config(config): |
| 73 | + try: |
| 74 | + config = importlib.import_module(config.__name__ + ".aport") |
| 75 | + except ImportError as exc: |
| 76 | + if str(exc) != "No module name {}".format( |
| 77 | + config.__name__ + ".aport"): |
| 78 | + raise |
| 79 | + config = None |
| 80 | + |
| 81 | + return config |
| 82 | + |
| 83 | + |
| 84 | +def uninstall(config): |
| 85 | + """Uninstall all tha was installed |
| 86 | +
|
| 87 | + This is where you undo everything that was done in `install()`. |
| 88 | + That means, removing menus, deregistering families and data |
| 89 | + and everything. It should be as though `install()` was never run, |
| 90 | + because odds are calling this function means the user is interested |
| 91 | + in re-installing shortly afterwards. If, for example, he has been |
| 92 | + modifying the menu or registered families. |
| 93 | +
|
| 94 | + """ |
| 95 | + config = find_host_config(config) |
| 96 | + if hasattr(config, "uninstall"): |
| 97 | + config.uninstall() |
| 98 | + |
| 99 | + pyblish.deregister_host("aport") |
0 commit comments