def process(self, session, **kwargs): """Implement the behavior for when the action is triggered Args: session (dict): environment dictionary Returns: Popen instance of newly spawned process """ # Update environment with session env = os.environ.copy() env.update(session) # Get executable by name app = lib.get_application(self.name) env.update(app["environment"]) executable = lib.which(app["executable"]) # Run as server arguments = ["-server", "-portNumber=20207"] return lib.launch(executable=executable, args=arguments, environment=env)
def process(self, session, **kwargs): """Implement the behavior for when the action is triggered Args: session (dict): environment dictionary Returns: Popen instance of newly spawned process """ with pype.modified_environ(**session): # Get executable by name app = lib.get_application(self.name) executable = lib.which(app["executable"]) # Run as server arguments = [] tools_env = acre.get_tools([self.name]) env = acre.compute(tools_env) env = acre.merge(env, current_env=dict(os.environ)) if not env.get('AVALON_WORKDIR', None): pype.load_data_from_templates() os.environ["AVALON_WORKDIR"] = pype.get_workdir_template( pype.Anatomy) pype.reset_data_from_templates() env.update(dict(os.environ)) lib.launch(executable=executable, args=arguments, environment=env) return
def preflight_check(script, project): missing_apps = set() missing_resources = set() for job in script: app = job["session"]["app"] if not lib.which(app): missing_apps.add(app) for resource in job["resources"]: resourcepath = os.path.join(cd, "resources", project, resource) if not os.path.exists(resourcepath): missing_resources.add(resourcepath) if missing_apps: sys.stderr.write("ERROR: Some applications were not found.\n") sys.stderr.write("\n".join("- %s" % app for app in missing_apps)) sys.stderr.write("\n") raise MissingApps() if missing_resources: sys.stderr.write("ERROR: Some resources were not found.\n") sys.stderr.write("\n".join("- %s" % resource for resource in missing_resources)) sys.stderr.write("\n") raise MissingResources() # Look for existing project io.install() io.activate_project(project) if not io.find_one({"type": "project", "name": project}): raise MissingProject()
def process(self, session, **kwargs): """Implement the behavior for when the action is triggered Args: session (dict): environment dictionary Returns: Popen instance of newly spawned process """ with pype.modified_environ(**session): # Get executable by name app = lib.get_application(self.name) executable = lib.which(app["executable"]) # Run as server arguments = [] tools_env = acre.get_tools([self.name]) env = acre.compute(tools_env) env = acre.merge(env, current_env=dict(os.environ)) if not env.get('AVALON_WORKDIR', None): project_name = env.get("AVALON_PROJECT") anatomy = Anatomy(project_name) os.environ['AVALON_PROJECT'] = project_name io.Session['AVALON_PROJECT'] = project_name task_name = os.environ.get("AVALON_TASK", io.Session["AVALON_TASK"]) asset_name = os.environ.get("AVALON_ASSET", io.Session["AVALON_ASSET"]) application = lib.get_application( os.environ["AVALON_APP_NAME"]) project_doc = io.find_one({"type": "project"}) data = { "task": task_name, "asset": asset_name, "project": { "name": project_doc["name"], "code": project_doc["data"].get("code", '') }, "hierarchy": pype.get_hierarchy(), "app": application["application_dir"] } anatomy_filled = anatomy.format(data) workdir = anatomy_filled["work"]["folder"] os.environ["AVALON_WORKDIR"] = workdir env.update(dict(os.environ)) lib.launch(executable=executable, args=arguments, environment=env) return
def launch(self, environment): executable = lib.which(self.config["executable"]) if executable is None: raise ValueError("'%s' not found on your PATH\n%s" % (self.config["executable"], os.getenv("PATH"))) args = self.config.get("args", []) return lib.launch(executable=executable, args=args, environment=environment)
def process(self, session, **kwargs): """Implement the behavior for when the action is triggered Args: session (dict): environment dictionary Returns: Popen instance of newly spawned process """ APP = "shell" app_definition = lib.get_application(APP) self.config = app_definition session = session.copy() session["AVALON_APP"] = APP session["AVALON_APP_NAME"] = self.name env = self.environ(session) # Get executable by name executable = lib.which(self.config["executable"]) # # (NOTE): The result CWD path may not be accurate since the # Launcher did not clean up the entry while changing # frames. # For example: # if you were in 'ProjA > Char > Boy > modeling' # and jump to 'ProjB > Prop' then launch action, # you will find the CWD path is: # 'ProjB > Prop > Boy > modeling' # not just: # 'ProjB > Prop' # cwd = env.get("AVALON_SHELL_CWD", session.get("AVALON_PROJECTS", "")) if cwd and not os.path.isdir(cwd): self.log.error("The path of `cwd` is not a directory: " "{!r}".format(cwd)) cwd = None return lib.launch(executable=executable, args=[], environment=env, cwd=cwd)
def run(src, fname, session): tempdir = tempfile.mkdtemp() with tempfile.NamedTemporaryFile(mode="w+", dir=tempdir, suffix=".py", delete=False) as f: module_name = f.name f.write(src.format(fname=fname)) executable = lib.which(session["AVALON_APP"]) kwargs = dict( args=[executable, "-u", module_name], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, env=session.environment, ) try: popen = subprocess.Popen(**kwargs) # Blocks until finished output = list() for line in iter(popen.stdout.readline, ""): output.append(line) finally: popen.wait() # Wait for return code shutil.rmtree(tempdir) if AVALON_DEBUG or popen.returncode != 0: for number, line in enumerate(src.splitlines()): sys.stdout.write("%i: %s\n" % (number + 1, line)) sys.stdout.write("".join(output)) if popen.returncode != 0: raise RuntimeError("%s raised an error" % module_name)