mirror of
https://github.com/SpyHoodle/PrideFetch.git
synced 2024-11-22 10:55:43 +00:00
Merge pull request #11 from SpyHoodle/packaging
This commit is contained in:
commit
76fd80c064
@ -1,7 +1,7 @@
|
||||
# pridefetch 🏳️⚧️
|
||||
|
||||
![pridefetch screenshot](https://file.coffee/u/J0dk4lIjU5Wmdu.png)<br>
|
||||
Python fetch script for showing your favourite pride flags & system info!<br>
|
||||
Python fetch script for showing your favourite pride flags & system stats!<br>
|
||||
Originally forked from [megabytesofrem/pridefetch](https://github.com/megabytesofrem/pridefetch).<br>
|
||||
|
||||
## Examples
|
||||
@ -53,9 +53,14 @@ You can run pridefetch straight away
|
||||
nix run github:SpyHoodle/pridefetch
|
||||
```
|
||||
|
||||
Or, install it and run
|
||||
Or, install it and then run
|
||||
|
||||
```bash
|
||||
nix profile install github:SpyHoodle/pridefetch
|
||||
pridefetch
|
||||
```
|
||||
|
||||
## Made with ❤️ and 🏳️⚧️
|
||||
- Pridefetch is at an early stage, so may not work on all systems.
|
||||
- Please report any issues or bugs on the Issues tab.
|
||||
- Checkout our [contributing guidelines](https://github.com/SpyHoodle/pridefetch/blob/master/CONTRIBUTING.md) if you'd like to contribute.
|
11
flake.nix
11
flake.nix
@ -13,17 +13,20 @@
|
||||
in {
|
||||
pridefetch = pkgs.stdenv.mkDerivation {
|
||||
name = "pridefetch";
|
||||
buildInputs = [
|
||||
(pkgs.python39.withPackages (pythonPackages: with pythonPackages; [
|
||||
buildInputs = with pkgs; [
|
||||
(python39.withPackages (pythonPackages: with pythonPackages; [
|
||||
distro
|
||||
]))
|
||||
zip
|
||||
];
|
||||
unpackPhase = "true";
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp ${./pridefetch} $out/bin/pridefetch
|
||||
cp ${./packages.py} $out/bin/packages.py
|
||||
cd ${./src}
|
||||
zip -r $out/pridefetch.zip *
|
||||
echo '#!/usr/bin/env python' | cat - $out/pridefetch.zip > $out/bin/pridefetch
|
||||
chmod +x $out/bin/pridefetch
|
||||
rm $out/pridefetch.zip
|
||||
'';
|
||||
meta = with pkgs.lib; {
|
||||
description = "Print out system statistics with pride flags";
|
||||
|
19
packages.py
19
packages.py
@ -1,19 +0,0 @@
|
||||
from subprocess import check_output
|
||||
|
||||
commands = [
|
||||
"pacman -Qq",
|
||||
"apt list --installed",
|
||||
"yum list installed",
|
||||
"dnf list installed",
|
||||
"qlist -I",
|
||||
"rpm -qa",
|
||||
"nix-store -qR /run/current-system/sw"
|
||||
]
|
||||
|
||||
def get_num_packages() -> (int, bool):
|
||||
for command in commands:
|
||||
try:
|
||||
return len(check_output(command.split(" ")).decode("utf-8").split("\n")) - 1
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
return False
|
@ -1,20 +1,23 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# General imports
|
||||
from argparse import ArgumentParser
|
||||
from datetime import timedelta
|
||||
from getpass import getuser
|
||||
# from platform import machine as architecture
|
||||
from platform import platform as system
|
||||
from platform import release as kernel
|
||||
from random import choice as random_choice
|
||||
from socket import gethostname
|
||||
from time import clock_gettime, CLOCK_BOOTTIME
|
||||
|
||||
# Title - user@hostname
|
||||
from getpass import getuser
|
||||
from socket import gethostname
|
||||
|
||||
# System info modules
|
||||
from platform import platform as system
|
||||
from platform import release as kernel
|
||||
# from platform import machine as architecture
|
||||
from distro import name as distribution
|
||||
from modules.packages import get_num_packages as packages
|
||||
|
||||
from packages import get_num_packages as packages
|
||||
|
||||
# Define a dictionary of all the flags and their colors
|
||||
# A dictionary of all the flags and their colors
|
||||
# Each color is the color for an individual row in the flag
|
||||
flags = {
|
||||
"classic": [196, 208, 226, 28, 20, 90],
|
||||
@ -38,18 +41,18 @@ reset = "\033[0m\033[39m"
|
||||
|
||||
|
||||
def color256(col: int, bg_fg: str) -> str:
|
||||
# Hacky alias around manually typing out escape codes every time
|
||||
# Alias to avoid manually typing out escape codes every time
|
||||
return f"\033[{48 if bg_fg == 'bg' else 38};5;{col}m"
|
||||
|
||||
|
||||
def draw_fetch(flag_name: str, width: int = None):
|
||||
# Load the flag from the dictionary of flags
|
||||
# Load the chosen flag from the dictionary of flags
|
||||
flag = flags[flag_name]
|
||||
|
||||
# Make sure that the row color is different to the color of the hostname
|
||||
row_color = color256(flag[1] if flag[0] != flag[1] else flag[2], "fg")
|
||||
|
||||
# The fetch data to be displayed
|
||||
# The fetch data (system info) to be displayed
|
||||
row_data = [
|
||||
f"{color256(flag[0], 'fg') if flag[0] != 0 else color256(242, 'fg')}"
|
||||
f"\033[1m{getuser()}@{gethostname()}{reset}",
|
||||
@ -65,7 +68,7 @@ def draw_fetch(flag_name: str, width: int = None):
|
||||
# If the data is greater than the flag length then duplicate the length of the flag
|
||||
flag = [element for element in flag for _ in (0, 1)]
|
||||
|
||||
# Set the width of the flag relative to its height (keep it in a nice ratio)
|
||||
# Set the width of the flag relative to its height (keep it in a ratio)
|
||||
width = width or round(len(flag) * 1.5 * 3)
|
||||
|
||||
# Ensures nothing is printed for empty lines
|
||||
@ -83,14 +86,14 @@ def draw_fetch(flag_name: str, width: int = None):
|
||||
|
||||
|
||||
def main():
|
||||
# Argument configuration
|
||||
# Argument configuration - options
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument("-f", "--flag", help="displays the chosen flag")
|
||||
parser.add_argument("-r", "--random", help="randomly choose a flag from a list seperated by commas")
|
||||
parser.add_argument("-w", "--width", help="choose a custom width for the flag", type=int)
|
||||
parser.add_argument("-l", "--list", help="lists all the flags that can be displayed", action="store_true")
|
||||
|
||||
# Parse the arguments
|
||||
# Parse (collect) any arguments
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.flag:
|
||||
@ -110,6 +113,7 @@ def main():
|
||||
print(f"Available flags:\n{', '.join(flags)}")
|
||||
|
||||
else:
|
||||
# By default, draw the classic flag
|
||||
draw_fetch("classic", args.width)
|
||||
|
||||
|
32
src/modules/packages.py
Normal file
32
src/modules/packages.py
Normal file
@ -0,0 +1,32 @@
|
||||
from subprocess import check_output
|
||||
|
||||
commands = [
|
||||
"pacman -Qq --color never", # Arch Linux
|
||||
"xbps-query -l", # Void Linux
|
||||
"kiss l", # KISS Linux
|
||||
"apt list --installed", # Debian, Ubuntu, Mint
|
||||
"dpkg -l", # Debian, Ubuntu, Mint
|
||||
"dnf list installed", # Fedora
|
||||
"zypper search -i", # openSUSE
|
||||
"rpm -qa", # RHEL, Fedora Core, CentOS
|
||||
"yum list installed", # RHEL, Fedora Core, CentOS
|
||||
"nix-store -qR /run/current-system/sw", # NixOS
|
||||
"equery list '*'", # Gentoo
|
||||
"qlist -I", # Gentoo
|
||||
"pkg info -a", # BSDs
|
||||
"pkg_info", # BSDs
|
||||
"apk info", # Alpine
|
||||
]
|
||||
|
||||
|
||||
def get_num_packages() -> (int, bool):
|
||||
for command in commands:
|
||||
try:
|
||||
# Get the length of the output of the command - the number of packages
|
||||
return len(check_output(command.split(" ")).decode("utf-8").split("\n")) - 1
|
||||
except FileNotFoundError:
|
||||
# If the command doesn't exist, skip it
|
||||
pass
|
||||
|
||||
# If we get here, we didn't find any of the commands
|
||||
return False
|
Loading…
Reference in New Issue
Block a user