swaytools: init at 0.1.0

This commit is contained in:
Átila Saraiva 2022-02-14 23:18:02 -03:00
parent a31699dce9
commit e93bb42cd7
3 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,22 @@
{ lib, python3Packages, slurp }:
python3Packages.buildPythonApplication rec {
pname = "swaytools";
version = "0.1.0";
src = python3Packages.fetchPypi {
inherit pname version;
sha256 = "1eb89259cbe027a0fa6bfc06ecf94e89b15e6f7b4965104e5b661c916ce7408c";
};
propagatedBuildInputs = [ slurp ];
passthru.updateScript = ./update.py;
meta = with lib; {
homepage = "https://github.com/tmccombs/swaytools";
description = "Collection of simple tools for sway (and i3)";
license = licenses.gpl3Only;
maintainers = with maintainers; [ atila ];
};
}

View File

@ -0,0 +1,58 @@
#!/usr/bin/env nix-shell
#!nix-shell -i python -p python39Packages.requests python39Packages.pip python39Packages.packaging
import requests
import json
import subprocess
try:
from packaging.version import parse
except ImportError:
from pip._vendor.packaging.version import parse
URL_PATTERN = 'https://pypi.python.org/pypi/{package}/json'
def findLine(key,derivation):
count = 0
lines = []
for line in derivation:
if key in line:
lines.append(count)
count += 1
return lines
def get_version(package, url_pattern=URL_PATTERN):
"""Return version of package on pypi.python.org using json."""
req = requests.get(url_pattern.format(package=package))
version = parse('0')
if req.status_code == requests.codes.ok:
j = json.loads(req.text.encode(req.encoding))
releases = j.get('releases', [])
for release in releases:
ver = parse(release)
if not ver.is_prerelease:
if ver > version:
version = ver
sha256 = j["releases"][release][-1]["digests"]["sha256"]
return version, sha256
if __name__ == '__main__':
nixpkgs = subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).decode("utf-8").strip('\n')
swaytoolsFolder = "/pkgs/tools/wayland/swaytools/"
with open(nixpkgs + swaytoolsFolder + "default.nix", 'r') as arq:
derivation = arq.readlines()
version, sha256 = get_version('swaytools')
key = "version = "
line = findLine(key,derivation)[0]
derivation[line] = f' version = "{version}";\n'
key = "sha256 = "
line = findLine(key,derivation)[0]
derivation[line] = f' sha256 = "{sha256}";\n'
with open(nixpkgs + swaytoolsFolder + "default.nix", 'w') as arq:
arq.writelines(derivation)

View File

@ -2642,6 +2642,8 @@ with pkgs;
swayr = callPackage ../tools/wayland/swayr { };
swaytools = callPackage ../tools/wayland/swaytools { };
wayland-utils = callPackage ../tools/wayland/wayland-utils { };
wayland-proxy-virtwl = callPackage ../tools/wayland/wayland-proxy-virtwl { };