diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-11-15 16:07:49 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2020-11-15 16:07:49 +0100 |
commit | 055c62a92f257b494af30863771ba4fad3320f2e (patch) | |
tree | ff9a391fd81192db1c7a7bd8a763c41cf0de2061 | |
parent | 6f5806dbacf53a26714f39df96fd708bef7c0619 (diff) | |
download | psutil-055c62a92f257b494af30863771ba4fad3320f2e.tar.gz |
refactor print_wheels.py
-rw-r--r-- | psutil/tests/__init__.py | 8 | ||||
-rwxr-xr-x | scripts/internal/print_wheels.py | 78 |
2 files changed, 56 insertions, 30 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index 399aa84c..e0df67fa 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -1131,18 +1131,18 @@ def print_sysinfo(): info['PID'] = os.getpid() # metrics - pinfo = psutil.Process().as_dict() - pinfo.pop('memory_maps', None) info['cpus'] = psutil.cpu_count() info['loadavg'] = "%.1f%%, %.1f%%, %.1f%%" % ( tuple([x / psutil.cpu_count() * 100 for x in psutil.getloadavg()])) mem = psutil.virtual_memory() - info['memory'] = "%s%%, %s/%s" % ( + info['memory'] = "%s%%, used=%s, total=%s" % ( int(mem.percent), bytes2human(mem.used), bytes2human(mem.total)) swap = psutil.swap_memory() - info['swap'] = "%s%%, %s/%s" % ( + info['swap'] = "%s%%, used=%s, total=%s" % ( int(swap.percent), bytes2human(swap.used), bytes2human(swap.total)) info['pids'] = len(psutil.pids()) + pinfo = psutil.Process().as_dict() + pinfo.pop('memory_maps', None) info['proc'] = pprint.pformat(pinfo) print("=" * 70, file=sys.stderr) # NOQA diff --git a/scripts/internal/print_wheels.py b/scripts/internal/print_wheels.py index 3c966173..da835333 100755 --- a/scripts/internal/print_wheels.py +++ b/scripts/internal/print_wheels.py @@ -14,51 +14,77 @@ from psutil._common import print_color from psutil._common import bytes2human -def main(): - def is64bit(name): - return name.endswith(('x86_64.whl', 'amd64.whl')) +class Wheel: - groups = collections.defaultdict(list) - for path in glob.glob('dist/*.whl'): - name = os.path.basename(path) - plat = name.split('-')[-1] - pyimpl = name.split('-')[3] + def __init__(self, path): + self._path = path + self._name = os.path.basename(path) + + def __repr__(self): + return "<Wheel(name=%s, plat=%s, arch=%s, pyver=%s)>" % ( + self.name, self.platform(), self.arch(), self.pyver()) + + __str__ = __repr__ + + @property + def name(self): + return self._name + + def platform(self): + plat = self.name.split('-')[-1] + pyimpl = self.name.split('-')[3] ispypy = 'pypy' in pyimpl if 'linux' in plat: if ispypy: - groups['pypy_on_linux'].append(name) + return 'pypy_on_linux' else: - groups['linux'].append(name) + return 'linux' elif 'win' in plat: if ispypy: - groups['pypy_on_windows'].append(name) + return 'pypy_on_windows' else: - groups['windows'].append(name) + return 'windows' elif 'macosx' in plat: if ispypy: - groups['pypy_on_macos'].append(name) + return 'pypy_on_macos' else: - groups['macos'].append(name) + return 'macos' else: - assert 0, name + raise ValueError("unknown platform %r" % self.name) + + def arch(self): + if self.name.endswith(('x86_64.whl', 'amd64.whl')): + return '64' + return '32' + + def pyver(self): + pyver = 'pypy' if self.name.split('-')[3].startswith('pypy') else 'py' + pyver += self.name.split('-')[2][2:] + return pyver + + def size(self): + return os.path.getsize(self._path) + + +def main(): + groups = collections.defaultdict(list) + for path in glob.glob('dist/*.whl'): + wheel = Wheel(path) + groups[wheel.platform()].append(wheel) tot_files = 0 tot_size = 0 templ = "%-54s %7s %7s %7s" - for platf, names in groups.items(): - ppn = "%s (total = %s)" % (platf.replace('_', ' '), len(names)) + for platf, wheels in groups.items(): + ppn = "%s (total = %s)" % (platf, len(wheels)) s = templ % (ppn, "size", "arch", "pyver") print_color('\n' + s, color=None, bold=True) - for name in sorted(names): + for wheel in sorted(wheels, key=lambda x: x.name): tot_files += 1 - path = os.path.join('dist', name) - size = os.path.getsize(path) - tot_size += size - arch = '64' if is64bit(name) else '32' - pyver = 'pypy' if name.split('-')[3].startswith('pypy') else 'py' - pyver += name.split('-')[2][2:] - s = templ % (name, bytes2human(size), arch, pyver) - if 'pypy' in pyver: + tot_size += wheel.size() + s = templ % (wheel.name, bytes2human(wheel.size()), wheel.arch(), + wheel.pyver()) + if 'pypy' in wheel.pyver(): print_color(s, color='violet') else: print_color(s, color='brown') |