fix(format): formatted the python project
This commit is contained in:
parent
a8185e5a8b
commit
648f22d3c7
2 changed files with 41 additions and 24 deletions
|
@ -1,8 +1,9 @@
|
||||||
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
|
||||||
|
|
||||||
for i in props:
|
for i in props:
|
||||||
if len(i) > j:
|
if len(i) > j:
|
||||||
j = len(i)
|
j = len(i)
|
||||||
|
@ -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,9 +20,10 @@ 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()
|
||||||
|
|
||||||
props: list[str] = [
|
props: list[str] = [
|
||||||
f"{d.username}@{d.hostname}",
|
f"{d.username}@{d.hostname}",
|
||||||
f"kernel: {d.kernel}",
|
f"kernel: {d.kernel}",
|
||||||
|
@ -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}")
|
||||||
|
|
|
@ -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()
|
||||||
|
@ -23,13 +24,13 @@ class Data:
|
||||||
self.uptime: str = self.get_uptime()
|
self.uptime: str = self.get_uptime()
|
||||||
self.locale: str = lc.setlocale(lc.LC_CTYPE)
|
self.locale: str = lc.setlocale(lc.LC_CTYPE)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
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":
|
||||||
|
@ -44,7 +45,7 @@ class Data:
|
||||||
win_release: str = win_res[0]
|
win_release: str = win_res[0]
|
||||||
win_ver: str = win_res[1]
|
win_ver: str = win_res[1]
|
||||||
return f"{win_release} {win_edition} {win_ver}"
|
return f"{win_release} {win_edition} {win_ver}"
|
||||||
|
|
||||||
raise ValueError("Unknown operating system. %r" % sys)
|
raise ValueError("Unknown operating system. %r" % sys)
|
||||||
|
|
||||||
def get_shell(self) -> str:
|
def get_shell(self) -> str:
|
||||||
|
@ -53,11 +54,11 @@ class Data:
|
||||||
shell: str = shell_info[0]
|
shell: str = shell_info[0]
|
||||||
except sh.ShellDetectionFailure:
|
except sh.ShellDetectionFailure:
|
||||||
shell: str = provide_default_shell()
|
shell: str = provide_default_shell()
|
||||||
|
|
||||||
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")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue