fix(format): formatted the python project

This commit is contained in:
Artur Manuel 2024-08-05 10:54:27 +01:00
commit 648f22d3c7
Failed to generate hash of commit
2 changed files with 41 additions and 24 deletions

View file

@ -1,5 +1,6 @@
from whyfetch.data import Data from whyfetch.data import Data
def separator_from_longest_prop(props: list[str]): def separator_from_longest_prop(props: list[str]):
j: int = 0 j: int = 0
@ -10,7 +11,8 @@ def separator_from_longest_prop(props: list[str]):
else: else:
continue continue
return ""*j return "" * j
class Colours: class Colours:
red: str = "\x1b[1;31m" red: str = "\x1b[1;31m"
@ -18,6 +20,7 @@ class Colours:
white: str = "\x1b[1;39m" white: str = "\x1b[1;39m"
magenta: str = "\x1b[1;35m" magenta: str = "\x1b[1;35m"
def __main__(): def __main__():
d: Data = Data() d: Data = Data()
@ -28,17 +31,29 @@ def __main__():
f"shell: {d.shell}", f"shell: {d.shell}",
f"ram: {d.ram}", f"ram: {d.ram}",
f"up: {d.uptime}", f"up: {d.uptime}",
f"locale: {d.locale}" f"locale: {d.locale}",
] ]
separator: str = separator_from_longest_prop(props) separator: str = separator_from_longest_prop(props)
print(f'{Colours.white}━━━━━━━━━━━━━━━{separator}') print(f"{Colours.white}━━━━━━━━━━━━━━━{separator}")
print(f' {Colours.red}_.----._{Colours.white} {Colours.magenta}{d.username}{Colours.white}@{Colours.magenta}{d.hostname}') print(
print(f' {Colours.red}.\' \'.{Colours.white} {Colours.magenta}kernel:{Colours.white} {d.kernel}') f" {Colours.red}_.----._{Colours.white} {Colours.magenta}{d.username}{Colours.white}@{Colours.magenta}{d.hostname}"
print(f'{Colours.red}/{Colours.white}._ _.--._ {Colours.red}\\{Colours.white} {Colours.magenta}os:{Colours.white} {d.os}') )
print(f'|_ \'-\' _.._ `| {Colours.magenta}shell:{Colours.white} {d.shell}') print(
print(f'{Colours.blue}\\{Colours.white} `---\' `-{Colours.blue}/{Colours.white} {Colours.magenta}ram:{Colours.white} {d.ram}') f" {Colours.red}.' '.{Colours.white} {Colours.magenta}kernel:{Colours.white} {d.kernel}"
print(f' {Colours.blue}\'._ _.\'{Colours.white} {Colours.magenta}up:{Colours.white} {d.uptime}') )
print(f' {Colours.blue}\'----\'{Colours.white} {Colours.magenta}locale:{Colours.white} {d.locale}') print(
print(f'━━━━━━━━━━━━━━━{separator}') f"{Colours.red}/{Colours.white}._ _.--._ {Colours.red}\\{Colours.white} {Colours.magenta}os:{Colours.white} {d.os}"
)
print(f"|_ '-' _.._ `| {Colours.magenta}shell:{Colours.white} {d.shell}")
print(
f"{Colours.blue}\\{Colours.white} `---' `-{Colours.blue}/{Colours.white} {Colours.magenta}ram:{Colours.white} {d.ram}"
)
print(
f" {Colours.blue}'._ _.'{Colours.white} {Colours.magenta}up:{Colours.white} {d.uptime}"
)
print(
f" {Colours.blue}'----'{Colours.white} {Colours.magenta}locale:{Colours.white} {d.locale}"
)
print(f"━━━━━━━━━━━━━━━{separator}")

View file

@ -12,6 +12,7 @@ import os
ures: pl.uname_result = pl.uname() ures: pl.uname_result = pl.uname()
sys: str = pl.system() sys: str = pl.system()
class Data: class Data:
def __init__(self) -> None: def __init__(self) -> None:
self.username: str = gp.getuser() self.username: str = gp.getuser()
@ -27,9 +28,9 @@ class Data:
def get_os(self) -> str: def get_os(self) -> str:
if "Linux" == ures.system: if "Linux" == ures.system:
linux_res: dict[str, str] = pl.freedesktop_os_release() linux_res: dict[str, str] = pl.freedesktop_os_release()
return linux_res['PRETTY_NAME'] return linux_res["PRETTY_NAME"]
if [ "FreeBSD", "OpenBSD", "NetBSD" ] not in [ ures.system ]: if ["FreeBSD", "OpenBSD", "NetBSD"] not in [ures.system]:
return ures.system return ures.system
if sys == "Darwin": if sys == "Darwin":
@ -57,7 +58,7 @@ class Data:
return shell return shell
def get_ram(self) -> str: def get_ram(self) -> str:
to_gb: Callable[[int], float] = lambda s: s / (1024 ** 3) to_gb: Callable[[int], float] = lambda s: s / (1024**3)
vm: NamedTuple = ps.virtual_memory() vm: NamedTuple = ps.virtual_memory()
total: float = to_gb(vm.total) total: float = to_gb(vm.total)
used: float = to_gb(vm.used) used: float = to_gb(vm.used)
@ -68,9 +69,10 @@ class Data:
current_uptime: tm.struct_time = tm.gmtime(tm.time() - ps.boot_time()) current_uptime: tm.struct_time = tm.gmtime(tm.time() - ps.boot_time())
return tm.strftime("%H hours, %M minutes, %S seconds", current_uptime) return tm.strftime("%H hours, %M minutes, %S seconds", current_uptime)
def provide_default_shell() -> str: def provide_default_shell() -> str:
if os.name == 'nt': if os.name == "nt":
return os.environ['COMSPEC'] return os.environ["COMSPEC"]
elif os.name == 'posix': elif os.name == "posix":
return os.environ['SHELL'] return os.environ["SHELL"]
raise NotImplementedError(f'OS {os.name!r} support not available') raise NotImplementedError(f"OS {os.name!r} support not available")