def _generate_report(self): """Put together the final HTML report.""" _LOG.info("Generating the HTML report.") # Make sure the output directory exists. try: self.outdir.mkdir(parents=True, exist_ok=True) except OSError as err: raise Error(f"failed to create directory '{self.outdir}': {err}") raw_stats_paths, descr_paths = self._copy_raw_data() # Find the styles and templates paths. templdir = FSHelpers.search_for_app_data( "wult", Path("templates"), pathdescr="HTML report Jinja2 templates") csspath = FSHelpers.search_for_app_data( "wult", Path("css/style.css"), pathdescr="HTML report CSS file") # Copy the styles file to the output directory. dstpath = self.outdir.joinpath("style.css") try: shutil.copyfile(csspath, dstpath) except OSError as err: raise Error( f"failed to copy CSS file from '{csspath}' to '{dstpath}':\n{err}" ) # The summary table is only included into the main HTML page. sum_tbl = self._prepare_summary_table(raw_stats_paths, descr_paths) links_tbl = self._prepare_links_table() # Each column name gets its own HTML page. for colname, pinfos in self._pinfos.items(): stats_tbl = self._prepare_stats_table(pinfos) # Render the template. jenv = Jinja2.build_jenv(templdir, trim_blocks=True, lstrip_blocks=True) jenv.globals["stats_tbl"] = stats_tbl jenv.globals["pinfos"] = pinfos jenv.globals["colname"] = colname jenv.globals["title_descr"] = self.title_descr jenv.globals["toolname"] = self._refinfo["toolname"] if sum_tbl: jenv.globals["sum_tbl"] = sum_tbl jenv.globals["links_tbl"] = links_tbl templfile = outfile = "index.html" sum_tbl = None else: templfile = "metric.html" outfile = links_tbl[colname]["fname"] Jinja2.render_template(jenv, Path(templfile), outfile=self.outdir.joinpath(outfile))
def get_path_pairs(proc, toolname, helperpath): """ Yield paths for 'toolname' driver and helpertool source code and deployables. Arguments are same as in 'is_deploy_needed()'. """ lproc = Procs.Proc() for path, is_drv in [(_DRV_SRC_SUBPATH, True), (_HELPERS_SRC_SUBPATH, False)]: srcpath = FSHelpers.search_for_app_data(toolname, path / toolname, default=None) # Some tools may not have helpers. if not srcpath: continue for deployable in _get_deployables(srcpath, lproc): deploypath = None # Deployable can be driver module or helpertool. if is_drv: deploypath = _get_module_path(proc, deployable) else: if helperpath and helperpath.name == deployable: deploypath = helperpath else: deploypath = get_helpers_deploy_path(proc, toolname) deploypath = Path(deploypath, "bin", deployable) yield srcpath, deploypath
def __init__(self, name): """ The class constructor. The arguments are as follows. * name - name of the tool to load the definitions for (e.g., 'wult'). """ self.name = name self.info = None self.vanilla_info = None path = FSHelpers.search_for_app_data("wult", Path(f"defs/{name}.yml"), pathdescr=f"{name} datapoints definitions file") self.info = self.vanilla_info = YAML.load(path)
def _deploy_prepare(args, toolname, minkver): """ Validate command-line arguments of the "deploy" command and prepare for builing the helpers and drivers. The arguments are as follows. o args - the command line arguments. o toolname - name of the tool being deployed (e.g., 'ndl'). o minkver - the minimum required version number. """ args.tmpdir = None args.kver = None if not args.ihost: args.ihost = "localhost" if not args.bhost: args.bhost = args.ihost if args.ihost != args.bhost and not args.bhost == "localhost": raise Error("build host (--build-host) must be the local host or the same as deploy host " "(--host)") if args.ihost == "localhost" and args.bhost == "localhost": for attr in ("username", "privkey", "timeout"): if getattr(args, attr) is not None: _LOG.warning("ignoring the '--%s' option as it not useful for a local host", attr) if not args.timeout: args.timeout = 8 else: args.timeout = Trivial.str_to_num(args.timeout) if not args.username: args.username = "******" if args.privkey and not args.privkey.is_dir(): raise Error(f"path '{args.privkey}' does not exist or it is not a directory") if hasattr(args, "drvsrc"): if not args.drvsrc: args.drvsrc = FSHelpers.search_for_app_data("wult", _DRV_SRC_SUBPATH/f"{toolname}", pathdescr=f"{toolname} drivers sources") if not args.drvsrc.is_dir(): raise Error(f"path '{args.drvsrc}' does not exist or it is not a directory") if hasattr(args, "helpersrc"): if not args.helpersrc: args.helpersrc = FSHelpers.search_for_app_data("wult", _HELPERS_SRC_SUBPATH/f"{toolname}", pathdescr=f"{toolname} helper sources") if not args.helpersrc.is_dir(): raise Error(f"path '{args.helpersrc}' does not exist or it is not a directory") with contextlib.closing(get_proc(args, args.bhost)) as proc: if not FSHelpers.which("make", default=None, proc=proc): raise Error(f"please, install the 'make' tool{proc.hostmsg}") if not args.ksrc: args.kver = KernelVersion.get_kver(proc=proc) if not args.ksrc: args.ksrc = Path(f"/lib/modules/{args.kver}/build") else: args.ksrc = FSHelpers.abspath(args.ksrc, proc=proc) if not FSHelpers.isdir(args.ksrc, proc=proc): raise Error(f"kernel sources directory '{args.ksrc}' does not exist{proc.hostmsg}") if not args.kver: args.kver = KernelVersion.get_kver_ktree(args.ksrc, proc=proc) _LOG.info("Kernel sources path: %s", args.ksrc) _LOG.info("Kernel version: %s", args.kver) if KernelVersion.kver_lt(args.kver, minkver): raise Error(f"version of the kernel{proc.hostmsg} is {args.kver}, and it is not new " f"enough.\nPlease, use kernel version {minkver} or newer.") args.tmpdir = FSHelpers.mktemp(prefix=f"{toolname}-", proc=proc) if hasattr(args, "drvsrc"): _LOG.debug("copying the drivers to %s:\n '%s' -> '%s'", proc.hostname, args.drvsrc, args.tmpdir) proc.rsync(f"{args.drvsrc}/", args.tmpdir / "drivers", remotesrc=False, remotedst=True) args.drvsrc = args.tmpdir / "drivers" _LOG.info("Drivers will be compiled on host '%s'", proc.hostname) if hasattr(args, "helpersrc"): _LOG.debug("copying the helpers to %s:\n '%s' -> '%s'", proc.hostname, args.helpersrc, args.tmpdir) proc.rsync(f"{args.helpersrc}/", args.tmpdir / "helpers", remotesrc=False, remotedst=True) args.helpersrc = args.tmpdir / "helpers" _LOG.info("Helpers will be compiled on host '%s'", proc.hostname) with contextlib.closing(get_proc(args, args.ihost)) as proc: if not args.kmodpath: args.kmodpath = Path(f"/lib/modules/{args.kver}") if not FSHelpers.isdir(args.kmodpath, proc=proc): raise Error(f"kernel modules directory '{args.kmodpath}' does not exist{proc.hostmsg}") _LOG.info("Drivers will be deployed to '%s'%s", args.kmodpath, proc.hostmsg) _LOG.info("Kernel modules path%s: %s", proc.hostmsg, args.kmodpath) if hasattr(args, "helpersrc"): if not args.helpers_path: args.helpers_path = get_helpers_deploy_path(proc, toolname) _LOG.info("Helpers will be deployed to '%s'%s", args.helpers_path, proc.hostmsg)