示例#1
0
    def get_newest_mtime(path):
        """Scan items in 'path' and return newest modification time among entries found."""

        newest = 0
        for _, fpath, _ in FSHelpers.lsdir(path, must_exist=False):
            mtime = os.path.getmtime(fpath)
            if mtime > newest:
                newest = mtime

        if not newest:
            raise Error(f"no files found in '{path}'")
        return newest
示例#2
0
    def _get_cstate_indexes(self, cpu):
        """Yield tuples of of C-state indexes and sysfs paths for cpu number 'cpu'."""

        basedir = self._sysfs_base / f"cpu{cpu}" / "cpuidle"
        name = None
        for name, path, typ in FSHelpers.lsdir(basedir, proc=self._proc):
            errmsg = f"unexpected entry '{name}' in '{basedir}'{self._proc.hostmsg}"
            if typ != "/" or not name.startswith("state"):
                raise Error(errmsg)
            index = name[len("state"):]
            if not Trivial.is_int(index):
                raise Error(errmsg)
            yield int(index), Path(path)

        if name is None:
            raise Error(f"C-states are not supported{self._proc.hostmsg}")
示例#3
0
def _get_ifinfos(proc):
    """
    For every network interfaces backed by a real device on the system defined by 'proc', yield the
    following tuples:
    * interface name
    * device HW address
    """

    for ifname, path, typ in FSHelpers.lsdir(_SYSFSBASE, proc=proc):
        if typ != "@":
            # We expect a symlink.
            continue

        devpath = None
        with contextlib.suppress(Error):
            devpath = FSHelpers.abspath(path / "device", proc=proc)
        if not devpath:
            continue

        yield ifname, devpath.name