init
This commit is contained in:
commit
8663ff8969
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.venv/
|
||||
65
barmanager.py
Normal file
65
barmanager.py
Normal file
@ -0,0 +1,65 @@
|
||||
"""barmanager
|
||||
helper script for eww bar from Shobu Ser'Hao
|
||||
|
||||
Usage:
|
||||
barmanager player get [-f --follow]
|
||||
|
||||
Options:
|
||||
-h --help Show Help screen
|
||||
-f --follow Loop on the output
|
||||
"""
|
||||
from docopt import docopt
|
||||
from subprocess import run, Popen, PIPE
|
||||
import json
|
||||
import sys
|
||||
|
||||
def main():
|
||||
arguments = docopt(__doc__)
|
||||
if arguments["player"]:
|
||||
run(["echo", json.dumps(handle_player(arguments))])
|
||||
|
||||
def handle_player(arguments):
|
||||
if arguments["get"]:
|
||||
|
||||
raw_metadata = run(["playerctl", "metadata"], capture_output=True).stdout.decode()
|
||||
metadata = parse_player_metadata(raw_metadata)
|
||||
if not arguments["--follow"]:
|
||||
return metadata
|
||||
|
||||
if arguments["--follow"]:
|
||||
process = Popen(["playerctl", "metadata", "--follow"], stdout=PIPE)
|
||||
chars = b''
|
||||
row_count = 0
|
||||
for char in iter(lambda: process.stdout.read(1), b""):
|
||||
if char:
|
||||
chars += char
|
||||
if char == b"\n":
|
||||
row_count += 1
|
||||
if row_count == len(metadata):
|
||||
run(["echo", json.dumps(parse_player_metadata(chars.decode()))])
|
||||
string = ''
|
||||
row_count = 0
|
||||
|
||||
def parse_player_metadata(raw_string):
|
||||
metadata = {}
|
||||
for i in raw_string.strip().split("\n"):
|
||||
head = ''
|
||||
tail = ''
|
||||
spaces = 0
|
||||
for j in i:
|
||||
if spaces < 2:
|
||||
if j == " ":
|
||||
spaces += 1
|
||||
else:
|
||||
spaces = 0
|
||||
head += j
|
||||
else:
|
||||
tail += j
|
||||
metadata[head.strip().split(":")[-1]] = tail.strip()
|
||||
return metadata
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
25
flake.lock
generated
Normal file
25
flake.lock
generated
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1732014248,
|
||||
"narHash": "sha256-y/MEyuJ5oBWrWAic/14LaIr/u5E0wRVzyYsouYY3W6w=",
|
||||
"rev": "23e89b7da85c3640bbc2173fe04f4bd114342367",
|
||||
"revCount": 710087,
|
||||
"type": "tarball",
|
||||
"url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.710087%2Brev-23e89b7da85c3640bbc2173fe04f4bd114342367/01934abf-23ee-7550-90cc-767601bc14b7/source.tar.gz"
|
||||
},
|
||||
"original": {
|
||||
"type": "tarball",
|
||||
"url": "https://flakehub.com/f/NixOS/nixpkgs/0.1.%2A.tar.gz"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
53
flake.nix
Normal file
53
flake.nix
Normal file
@ -0,0 +1,53 @@
|
||||
{
|
||||
description = "A Nix-flake-based Python development environment";
|
||||
|
||||
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz";
|
||||
|
||||
outputs = { self, nixpkgs }:
|
||||
let
|
||||
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
||||
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
});
|
||||
in
|
||||
{
|
||||
devShells = forEachSupportedSystem ({ pkgs }: {
|
||||
default = pkgs.mkShell {
|
||||
venvDir = ".venv";
|
||||
packages = with pkgs; [ python311 poetry ] ++
|
||||
(with pkgs.python311Packages; [
|
||||
pip
|
||||
venvShellHook
|
||||
black
|
||||
docopt
|
||||
]);
|
||||
};
|
||||
});
|
||||
|
||||
packages = forEachSupportedSystem ({pkgs}: {
|
||||
default = pkgs.python311Packages.buildPythonPackage rec {
|
||||
pname = "barManager";
|
||||
version = "0.1";
|
||||
pyproject = true;
|
||||
|
||||
src = ./.;
|
||||
build-system = with pkgs; [
|
||||
python311Packages.poetry-core
|
||||
];
|
||||
dependencies = [
|
||||
|
||||
] ++ (with pkgs.python311Packages; [
|
||||
docopt
|
||||
]);
|
||||
|
||||
meta = with pkgs.lib; {
|
||||
description = "";
|
||||
mainProgram = "barmanager";
|
||||
homepage = "";
|
||||
changelog = "";
|
||||
license = licenses.mit;
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
16
poetry.lock
generated
Normal file
16
poetry.lock
generated
Normal file
@ -0,0 +1,16 @@
|
||||
# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand.
|
||||
|
||||
[[package]]
|
||||
name = "docopt"
|
||||
version = "0.6.2"
|
||||
description = "Pythonic argument parser, that will make you smile"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "docopt-0.6.2.tar.gz", hash = "sha256:49b3a825280bd66b3aa83585ef59c4a8c82f2c8a522dbe754a8bc8d08c85c491"},
|
||||
]
|
||||
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.11"
|
||||
content-hash = "020d3e03335e70ca8b1cfd769838e50546a63b9ed4e4034ba584fd3a3ec497fd"
|
||||
18
pyproject.toml
Normal file
18
pyproject.toml
Normal file
@ -0,0 +1,18 @@
|
||||
[tool.poetry]
|
||||
name = "barmanager"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = ["Shobu Ser'Hao <shobu_serhao@proton.me>"]
|
||||
readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.11"
|
||||
docopt = "^0.6.2"
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
barmanager = "barmanager:main"
|
||||
Loading…
x
Reference in New Issue
Block a user