-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System info #98
System info #98
Changes from 2 commits
866bde1
93f2a1a
6e06687
72f6898
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import sys | ||
import os | ||
|
||
from typing import Optional | ||
from cpuinfo import get_cpu_info | ||
from typing import Optional, Tuple | ||
from pathlib import Path | ||
import pkg_resources | ||
import platform | ||
import psutil | ||
import pyglet | ||
import importlib | ||
|
@@ -70,23 +72,45 @@ def bcipy_version() -> str: | |
return f'{version} - {sha_hash}' if sha_hash else version | ||
|
||
|
||
def get_system_info() -> dict: | ||
"""Get System Information. | ||
""" | ||
def get_screen_resolution() -> Tuple[int, int]: | ||
"""Gets the screen resolution. | ||
|
||
Note: Use this method if only the screen resolution is needed; it is much more efficient | ||
than extracting that information from the dict returned by the get_system_info method. | ||
|
||
Returns | ||
------- | ||
(width, height) | ||
""" | ||
screen = pyglet.canvas.get_display().get_default_screen() | ||
return (screen.width, screen.height) | ||
|
||
# Three lines for getting screen resolution | ||
platform = pyglet.window.get_platform() | ||
display = platform.get_default_display() | ||
screen = display.get_default_screen() | ||
|
||
mem = psutil.virtual_memory() | ||
def get_system_info() -> dict: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome - this is exactly what Barry et al. asked for! |
||
"""Get System Information. | ||
See: https://stackoverflow.com/questions/3103178/how-to-get-the-system-info-with-python | ||
|
||
Returns | ||
------- | ||
dict of system-related properties, including ['os', 'py_version', 'resolution', | ||
'memory', 'bcipy_version', 'platform', 'platform-release', 'platform-version', | ||
'architecture', 'processor', 'cpu_count', 'hz', 'ram'] | ||
""" | ||
screen_width, screen_height = get_screen_resolution() | ||
return { | ||
'os': sys.platform, | ||
'py_version': sys.version, | ||
'resolution': [screen.width, screen.height], | ||
'memory': mem.available / 1024 / 1024, | ||
'bcipy_version': bcipy_version() | ||
'resolution': [screen_width, screen_height], | ||
'memory': psutil.virtual_memory().available / 1024 / 1024, | ||
'bcipy_version': bcipy_version(), | ||
'platform': platform.system(), | ||
'platform-release': platform.release(), | ||
'platform-version': platform.version(), | ||
'architecture': platform.machine(), | ||
'processor': platform.processor(), | ||
'cpu_count': os.cpu_count(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like we can get the CPU name in most cases. It would be worth adding! https://github.com/workhorsy/py-cpuinfo#raw-fields |
||
'hz': get_cpu_info()['hz_actual_friendly'], | ||
'ram': str(round(psutil.virtual_memory().total / (1024.0**3))) + " GB" | ||
} | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need to change slightly to work with the updated dependencies