Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate controller.launch functionality into library functionality #20

Open
BigRoy opened this issue Sep 8, 2017 · 2 comments
Open

Comments

@BigRoy
Copy link
Contributor

BigRoy commented Sep 8, 2017

Issue

Currently the only way in Avalon to set up a project's environment is to actually launch into the application through the Launcher. I believe this should be simplified and separated so that it becomes trivial to initialize an application's environment for an asset in code, e.g. when trying to batch prepare a lot of assets.

This would also increase the readability of launching an application itself, since it would just rely on the library functions for initializing the environment, like lib.create_environment(asset, task, app).

This is not reliable pseudocode, but would present the idea.

# pseudocode
import os
import errno
import traceback
import shutil
from avalon import io

# A mockup maya application (should be loaded from .toml)
app = {
    "default_dirs": [
        "scenes",
        "data",
        "renderData/shaders",
        "images",
        "sourceimages"
    ],
    "copy": {
        "{AVALON_CORE}/res/workspace.mel": "workspace.mel"
    }
}

asset = io.find_one({"type": "asset"})
create_environment(app, asset, task="model")

def create_environment(app, asset, task):
    """Create a work environment for application in asset's task.

    Arguments:
        app (dict): Application specification.
        asset (bson.ObjectID): The asset database id.
        task (str): The name of the task to operate in.

    """
    # todo: actually get the workdir using project's config and the asset itself
    # this would format the template for "work" files.
    workdir = _get_workdir(asset, task, app)

    try:
        os.makedirs(workdir)
        log.info("Creating working directory '%s'", workdir)

    except OSError as e:

        # An already existing working directory is fine.
        if e.errno == errno.EEXIST:
            log.info("Existing working directory found.")

        else:
            log.error("Could not create working directory.")
            log.error(traceback.format_exc())

    else:
        log.info("Creating default directories..")
        for dirname in app.get("default_dirs", []):
            log.debug(" - %s",  dirname)
            os.makedirs(os.path.join(workdir, dirname))

    # Perform application copy
    for src, dst in app.get("copy", {}).items():
        # Format source by environment
        # TODO: Formatting shouldn't be done here!
        src = src.format(**os.environ)
        dst = os.path.join(workdir, dst)

        try:
            log.info("Copying %s -> %s", src, dst)
            shutil.copy(src, dst)
        except OSError as e:
            log.error("Could not copy application file: %s", e)
            log.error(" - %s -> %s", src, dst)

I might even want to propose to have this logic be part of the avalon's core API, which would also make it an issue for avalon core.

@mottosso
Copy link
Contributor

mottosso commented Sep 8, 2017

Thanks @BigRoy.

I also had some thoughts on this, where the (new and unused) Session object would carry a launch() method, launching a given application within the Session.

@BigRoy
Copy link
Contributor Author

BigRoy commented Sep 8, 2017

I also had some thoughts on this, where the (new and unused) Session object would carry a launch() method, launching a given application within the Session.

Sounds interesting! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants