def run_action(action, env): config = env.config # Set build environment from config env.shell.pushenv() for var, value in getattr(env, 'env', {}).items(): env.shell.setenv(var, value) if isinstance(action, str): action_cls = Scripts.find_action(action) if not action_cls: print('Action {} not found'.format(action)) sys.exit(13) action = action_cls() if action.is_main(): Scripts.run_action(action, env) else: Scripts.run_action( Script([ InstallCompiler(), InstallPackages(), DownloadDependencies(), action, ], name='main'), env) env.shell.popenv()
def run(self, env): sh = env.shell def _expand_vars(cmd): cmd_type = type(cmd) if cmd_type == str: cmd = replace_variables(cmd, env.config['variables']) elif cmd_type == list: cmd = [ replace_variables(sub, env.config['variables']) for sub in cmd ] return cmd # Interpolate any variables self.commands = [_expand_vars(cmd) for cmd in self.commands] # Run each of the commands children = [] for cmd in self.commands: cmd_type = type(cmd) # See if the string is actually an action if cmd_type == str: action_cls = Scripts.find_action(cmd) if action_cls: cmd = action_cls() cmd_type = type(cmd) if cmd_type == str: result = sh.exec(*cmd.split(' ')) if result.returncode != 0: print('Command failed, exiting') sys.exit(12) elif cmd_type == list: result = sh.exec(*cmd) if result.returncode != 0: print('Command failed, exiting') sys.exit(12) elif isinstance(cmd, Action): Scripts.run_action(cmd, env) elif callable(cmd): children += to_list(cmd(env)) else: print('Unknown script sub command: {}: {}', cmd_type, cmd) sys.exit(4) return children