def _setup_env(self): env = dict(os.environ) self.logger.debug("Set 'CLADE_INTERCEPT' environment variable value") env["CLADE_INTERCEPT"] = str(self.output) if self.intercept_open: self.logger.debug( "Set 'CLADE_INTERCEPT_OPEN' environment variable value") env["CLADE_INTERCEPT_OPEN"] = self.output_open if self.intercept_envs: self.logger.debug( "Set 'CLADE_ENV_VARS' environment variable value") env["CLADE_ENV_VARS"] = self.output_envs # Prepare environment variables for PID graph if self.append: last_used_id = get_last_id(self.output) else: last_used_id = "0" f = tempfile.NamedTemporaryFile(mode="w", delete=False) f.write(last_used_id) f.flush() self.clade_if_file = f.name env["CLADE_ID_FILE"] = self.clade_if_file env["CLADE_PARENT_ID"] = "0" return env
def parse(self, cmds_file): self.log("Parsing {} commands".format( get_last_id(cmds_file, raise_exception=True))) for cmd in iter_cmds(cmds_file): self.pid_by_id[cmd["id"]] = cmd["pid"] self.dump_data(self.pid_by_id, self.pid_by_id_file) if self.pid_by_id and self.conf.get("PidGraph.as_picture"): self.__print_pid_graph(cmds_file) self.pid_by_id.clear()
def _setup_env(self): env = dict(os.environ) self.logger.debug("Set 'CLADE_INTERCEPT' environment variable value") env["CLADE_INTERCEPT"] = self.output # Prepare environment variables for PID graph if self.append: last_used_id = get_last_id(self.output) else: last_used_id = "0" f = tempfile.NamedTemporaryFile(delete=False) f.write(last_used_id.encode()) env["CLADE_ID_FILE"] = f.name env["CLADE_PARENT_ID"] = "0" return env
def test_pid_graph(tmpdir, cmds_file): c = Clade(tmpdir, cmds_file) e = c.parse("PidGraph") last_id = get_last_id(cmds_file) pid_graph = e.load_pid_graph() pid_by_id = e.load_pid_by_id() cmd_ids = list(str(x) for x in range(1, int(last_id) + 1)) assert len(pid_graph) == len(cmd_ids) for cmd_id in cmd_ids: assert cmd_id in pid_graph assert len(pid_graph[cmd_id]) >= 1 for pid in pid_graph[cmd_id]: assert int(pid) < int(cmd_id) assert len(pid_by_id) == len(cmd_ids) for cmd_id in cmd_ids: assert cmd_id in pid_by_id assert int(pid_by_id[cmd_id]) < int(cmd_id)
def test_get_last_id(cmds_file): assert int(get_last_id(cmds_file)) >= number_of_cmds