From: Michael Tremer Date: Thu, 26 May 2022 12:06:16 +0000 (+0000) Subject: Drop system.py X-Git-Tag: 0.9.28~744 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=356f94c20c8260dc5301fbdf0f7845713a9b783f;p=pakfire.git Drop system.py This has been replaced by cpuinfo and psutil. Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index eb6c88256..4b50fb988 100644 --- a/Makefile.am +++ b/Makefile.am @@ -133,7 +133,6 @@ pakfire_PYTHON = \ src/pakfire/hub.py \ src/pakfire/i18n.py \ src/pakfire/logger.py \ - src/pakfire/system.py \ src/pakfire/util.py pakfiredir = $(pythondir)/pakfire diff --git a/src/pakfire/system.py b/src/pakfire/system.py deleted file mode 100644 index a5362abbf..000000000 --- a/src/pakfire/system.py +++ /dev/null @@ -1,180 +0,0 @@ -#!/usr/bin/python3 -############################################################################### -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2011 Pakfire development team # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -############################################################################### - -import multiprocessing -import os -import socket - -from . import _pakfire -from .i18n import _ - -class System(object): - """ - Class that grants access to several information about - the system this software is running on. - """ - @property - def hostname(self): - hn = socket.gethostname() - - # If a host has got no domain part, we add one. - if not "." in hn: - hn = "%s.localdomain" % hn - - return hn - - @property - def cpu_count(self): - """ - Count the number of CPU cores. - """ - return multiprocessing.cpu_count() - - def parse_cpuinfo(self): - ret = {} - - with open("/proc/cpuinfo") as f: - for line in f.readlines(): - try: - # Split the lines by colons. - a, b = line.split(":") - - # Strip whitespace. - a = a.strip() - b = b.strip() - - ret[a] = b - except: - pass - - return ret - - @property - def cpu_model(self): - cpuinfo = self.parse_cpuinfo() - - ret = cpuinfo.get("model name", None) - - # Some ARM platforms do not provide "model name", so we - # try an other way. - if ret is None: - try: - ret = "%(Hardware)s - %(Processor)s" % cpuinfo - except KeyError: - pass - - # Remove too many spaces. - if ret: - ret = " ".join(ret.split()) - - return ret or _("Could not be determined") - - @property - def cpu_bogomips(self): - return _pakfire.performance_index() - - def get_loadavg(self): - return os.getloadavg() - - @property - def loadavg1(self): - return self.get_loadavg()[0] - - @property - def loadavg5(self): - return self.get_loadavg()[1] - - @property - def loadavg15(self): - return self.get_loadavg()[2] - - def has_overload(self): - """ - Checks, if the load average is not too high. - - On this is to be decided if a new job is taken. - """ - # If there are more than 2 processes in the process queue per CPU - # core we will assume that the system has heavy load and to not request - # a new job. - return self.loadavg5 >= self.cpu_count * 2 - - def parse_meminfo(self): - ret = {} - - with open("/proc/meminfo") as f: - for line in f.readlines(): - try: - a, b, c = line.split() - - a = a.strip() - a = a.replace(":", "") - b = int(b) - - ret[a] = b * 1024 - except: - pass - - return ret - - @property - def memory_total(self): - meminfo = self.parse_meminfo() - - return meminfo.get("MemTotal", None) - - # For compatibility - memory = memory_total - - @property - def memory_free(self): - meminfo = self.parse_meminfo() - - free = meminfo.get("MemFree", None) - if free: - buffers = meminfo.get("Buffers") - cached = meminfo.get("Cached") - - return free + buffers + cached - - @property - def swap_total(self): - meminfo = self.parse_meminfo() - - return meminfo.get("SwapTotal", None) - - @property - def swap_free(self): - meminfo = self.parse_meminfo() - - return meminfo.get("SwapFree", None) - - -# Create an instance of this class to only keep it once in memory. -system = System() - -if __name__ == "__main__": - print("Hostname", system.hostname) - print("Arch", system.arch) - - print("CPU Model", system.cpu_model) - print("CPU count", system.cpu_count) - print("Memory", system.memory)