diff --git a/Pipfile.lock b/Pipfile.lock index 0641be37..536d9a8d 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -314,10 +314,10 @@ }, "tqdm": { "hashes": [ - "sha256:438d6a735167099d75e5fd9a55175c6727c4dbba345ae406b2886c2728fe3e80", - "sha256:ebc205051d79b49989140f5f6c73ec23fce5f590cbc4d9cd6e4c47f168fa0f10" + "sha256:1be3e4e3198f2d0e47b928e9d9a8ec1b63525db29095cec1467f4c5a4ea8ebf9", + "sha256:7e39a30e3d34a7a6539378e39d7490326253b7ee354878a92255656dc4284457" ], - "version": "==4.34.0" + "version": "==4.35.0" }, "twine": { "hashes": [ diff --git a/graphenex/core/utils/sysinfo.py b/graphenex/core/utils/sysinfo.py index 6ce08e66..1dcde70e 100644 --- a/graphenex/core/utils/sysinfo.py +++ b/graphenex/core/utils/sysinfo.py @@ -5,20 +5,44 @@ import psutil import re + class SysInformation: - + UNITS_MAPPING = [ + (1 << 50, ' PB'), + (1 << 40, ' TB'), + (1 << 30, ' GB'), + (1 << 20, ' MB'), + (1 << 10, ' KB'), + (1, (' byte', ' bytes')), + ] + + @staticmethod + def pretty_size(bytes, units=UNITS_MAPPING): + for factor, suffix in units: + if bytes >= factor: + break + amount = int(bytes / factor) + + if isinstance(suffix, tuple): + singular, multiple = suffix + if amount == 1: + suffix = singular + else: + suffix = multiple + return str(amount) + suffix + @staticmethod def get_network_info(): masks = list() MaskResult = namedtuple('MaskResult', ['name', 'recv', 'sent', 'slug']) for mask, data in OrderedDict(psutil.net_io_counters(pernic=True)).items(): if data.packets_recv > 0 or data.packets_sent > 0: - res = MaskResult(mask, data.packets_recv, data.packets_sent, - SysInformation.slugify(mask)) + res = MaskResult(mask, SysInformation.pretty_size(data.packets_recv), SysInformation.pretty_size(data.packets_sent), + SysInformation.slugify(mask)) masks.append(res) return masks - + @staticmethod def get_disk_info(): disks = list() @@ -30,9 +54,9 @@ def get_disk_info(): disks.append(res) except PermissionError: pass - + return disks - + @staticmethod def get_general_info(): uname = platform.uname() @@ -52,11 +76,12 @@ def get_all_info(): return info_dict @staticmethod - def slugify(text, delim='-'): + def slugify(text, delim='-'): """ Generate an ASCII-only slug. """ - _punctuation_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+') + _punctuation_re = re.compile( + r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+') result = [] for word in _punctuation_re.split(text.lower()): word = normalize('NFKD', word) \ @@ -66,4 +91,4 @@ def slugify(text, delim='-'): if word: result.append(word) - return delim.join(result) \ No newline at end of file + return delim.join(result) diff --git a/graphenex/core/web/__init__.py b/graphenex/core/web/__init__.py index 910d9f45..3e52afad 100644 --- a/graphenex/core/web/__init__.py +++ b/graphenex/core/web/__init__.py @@ -6,6 +6,8 @@ import webbrowser import secrets + + logger = GraphenexLogger(__name__) app = Flask(__name__) app.config['SECRET_KEY'] = '77a98d7971ec94c8aae6dd2d' diff --git a/graphenex/core/web/views.py b/graphenex/core/web/views.py index 894e833d..34320e9a 100644 --- a/graphenex/core/web/views.py +++ b/graphenex/core/web/views.py @@ -33,8 +33,7 @@ def decorated_function(*args, **kwargs): return f(*args, **kwargs) else: emit('auth', {'text': 'Not authenticated'}) - disconnect() - + return decorated_function