From: alex Date: Sat, 26 Apr 2025 16:12:45 +0000 (+0200) Subject: Update scripts X-Git-Url: https://xn--ix-yja.es/gitweb/?a=commitdiff_plain;h=63a77d4fcabe403ee6688384b4a71bc9dc81e737;p=alex.git Update scripts - Remove Bitwarden download, ubpkg can do it - Remove newsboat, zfs scripts - Remove appdirs - Migrate to new Bitwarden server - Some fixes --- diff --git a/scripts/p7s/appdirs.py b/scripts/p7s/appdirs.py deleted file mode 100644 index 9ff0ca8..0000000 --- a/scripts/p7s/appdirs.py +++ /dev/null @@ -1,11 +0,0 @@ -import appdirs -import pathlib - - -APPDIRS = appdirs.AppDirs("p7s", "alex@pdp7.net") - - -def user_cache_dir(): - r = pathlib.Path(APPDIRS.user_cache_dir) - r.mkdir(parents=True, exist_ok=True) - return r diff --git a/scripts/p7s/bitwarden.py b/scripts/p7s/bitwarden.py index f3f26dd..ab6cc4f 100644 --- a/scripts/p7s/bitwarden.py +++ b/scripts/p7s/bitwarden.py @@ -1,35 +1,13 @@ import contextlib -import io import json import os import subprocess -import zipfile - -import httpx - -from p7s import appdirs class Bitwarden(): - def download(self, check_version=False): - self.bw_command = appdirs.user_cache_dir() / "bw" - if self.bw_command.exists() and not check_version: - return self.bw_command - r = httpx.get("https://vault.bitwarden.com/download/?app=cli&platform=linux") - location = r.headers["location"] - version = location.split("/")[7] - bw_versioned_command = appdirs.user_cache_dir() / f"bw-{version}" - if not bw_versioned_command.exists(): - with zipfile.ZipFile(io.BytesIO(httpx.get(location, follow_redirects=True).content)) as zip: - with zip.open("bw") as zip_bw: - bw_versioned_command.write_bytes(zip_bw.read()) - bw_versioned_command.chmod(0o755) - self.bw_command.unlink(missing_ok=True) - self.bw_command.symlink_to(bw_versioned_command) - @contextlib.contextmanager def login(self, server, email): - subprocess.run([self.bw_command, "config", "server", server], check=True) + subprocess.run(["bw", "config", "server", server], check=True) status = self.status()["status"] if status == "unauthenticated": command = ["login", email] @@ -37,29 +15,28 @@ class Bitwarden(): command = ["unlock"] else: assert False, f"unexpected status {status}" - command = subprocess.run([self.bw_command] + command, check=True, stdout=subprocess.PIPE, encoding="UTF8") + command = subprocess.run(["bw"] + command, check=True, stdout=subprocess.PIPE, encoding="UTF8") export_line = command.stdout.splitlines()[3] session = export_line.split('"')[1] os.environ["BW_SESSION"] = session try: - yield self.bw_command - subprocess.run([self.bw_command, "lock"], check=True) + yield + subprocess.run(["bw", "logout"], check=True) finally: del os.environ["BW_SESSION"] def sync(self): - subprocess.run([self.bw_command, "sync"], check=True) + subprocess.run(["bw", "sync"], check=True) def status(self): - return json.loads(subprocess.run([self.bw_command, "status"], check=True, stdout=subprocess.PIPE).stdout) + return json.loads(subprocess.run(["bw", "status"], check=True, stdout=subprocess.PIPE).stdout) def get_item(self, uuid): - return json.loads(subprocess.run([self.bw_command, "get", "item", uuid], check=True, stdout=subprocess.PIPE).stdout) + return json.loads(subprocess.run(["bw", "get", "item", uuid], check=True, stdout=subprocess.PIPE).stdout) def get_item(server, email, uuid): b = Bitwarden() - b.download() with b.login(server, email): b.sync() return b.get_item(uuid) diff --git a/scripts/p7s/mail/__init__.py b/scripts/p7s/mail/__init__.py index 0bcbf33..0300e80 100644 --- a/scripts/p7s/mail/__init__.py +++ b/scripts/p7s/mail/__init__.py @@ -7,8 +7,8 @@ from p7s.mail import mbsync def generate_config(): - gmail = bitwarden.get_item("https://bitwarden.pdp7.net", "alex@corcoles.net", "cad137b0-cfd5-4d5c-b167-98a9e792f4cc")["login"] - yahoo = bitwarden.get_item("https://bitwarden.pdp7.net", "alex@corcoles.net", "e24727e7-c0ef-4c97-afd0-8497d547304c")["login"] + gmail = bitwarden.get_item("https://vaultwarden.pdp7.net", "alex@corcoles.net", "f9bba940-769d-430a-82f4-5da10990e8fd")["login"] + yahoo = bitwarden.get_item("https://vaultwarden.pdp7.net", "alex@corcoles.net", "5c4d9e3b-121d-45f5-bab6-03b42d291326")["login"] (pathlib.Path.home() / (".mbsyncrc")).write_text( mbsync.mbsync_gmail(gmail["username"], gmail["password"], "~/Mail") + "\n" + diff --git a/scripts/p7s/newsboat.py b/scripts/p7s/newsboat.py deleted file mode 100644 index ac88ae1..0000000 --- a/scripts/p7s/newsboat.py +++ /dev/null @@ -1,8 +0,0 @@ -import os -import sys - - -def main(): - env = os.environ.copy() - env["LOCALE_ARCHIVE"] = "/usr/lib/locale/locale-archive" - os.execve("/home/alex/.local/bin/nix-portable", ("nix-portable", "nix", "shell", "nixpkgs#newsboat", "-c", "newsboat"), env) diff --git a/scripts/p7s/zfs.py b/scripts/p7s/zfs.py deleted file mode 100644 index d51ff17..0000000 --- a/scripts/p7s/zfs.py +++ /dev/null @@ -1,6 +0,0 @@ -import subprocess - - -def update_zfs(): - version = subprocess.run(["rpm", "-q", "zfs-dkms", '--queryformat=%{VERSION}'], check=True, stdout=subprocess.PIPE, encoding="utf8").stdout - subprocess.run(["sudo", "dkms", "install", f"zfs/{version}"], check=True) diff --git a/scripts/poetry.lock b/scripts/poetry.lock index 9009021..e1c2651 100644 --- a/scripts/poetry.lock +++ b/scripts/poetry.lock @@ -23,28 +23,16 @@ doc = ["Sphinx (>=8.2,<9.0)", "packaging", "sphinx-autodoc-typehints (>=1.2.0)", test = ["anyio[trio]", "blockbuster (>=1.5.23)", "coverage[toml] (>=7)", "exceptiongroup (>=1.2.0)", "hypothesis (>=4.0)", "psutil (>=5.9)", "pytest (>=7.0)", "trustme", "truststore (>=0.9.1)", "uvloop (>=0.21)"] trio = ["trio (>=0.26.1)"] -[[package]] -name = "appdirs" -version = "1.4.4" -description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." -category = "main" -optional = false -python-versions = "*" -files = [ - {file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"}, - {file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"}, -] - [[package]] name = "certifi" -version = "2025.1.31" +version = "2025.4.26" description = "Python package for providing Mozilla's CA Bundle." category = "main" optional = false python-versions = ">=3.6" files = [ - {file = "certifi-2025.1.31-py3-none-any.whl", hash = "sha256:ca78db4565a652026a4db2bcdf68f2fb589ea80d0be70e03929ed730746b84fe"}, - {file = "certifi-2025.1.31.tar.gz", hash = "sha256:3d5da6925056f6f18f119200434a4780a94263f10d1c21d032a6f6b2baa20651"}, + {file = "certifi-2025.4.26-py3-none-any.whl", hash = "sha256:30350364dfe371162649852c63336a15c70c6510c2ad5015b21c2345311805f3"}, + {file = "certifi-2025.4.26.tar.gz", hash = "sha256:0a816057ea3cdefcef70270d2c515e4506bbc954f417fa5ade2021213bb8f0c6"}, ] [[package]] @@ -64,31 +52,31 @@ test = ["pytest (>=6)"] [[package]] name = "h11" -version = "0.14.0" +version = "0.16.0" description = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1" category = "main" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761"}, - {file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"}, + {file = "h11-0.16.0-py3-none-any.whl", hash = "sha256:63cf8bbe7522de3bf65932fda1d9c2772064ffb3dae62d55932da54b31cb6c86"}, + {file = "h11-0.16.0.tar.gz", hash = "sha256:4e35b956cf45792e4caa5885e69fba00bdbc6ffafbfa020300e549b208ee5ff1"}, ] [[package]] name = "httpcore" -version = "1.0.8" +version = "1.0.9" description = "A minimal low-level HTTP client." category = "main" optional = false python-versions = ">=3.8" files = [ - {file = "httpcore-1.0.8-py3-none-any.whl", hash = "sha256:5254cf149bcb5f75e9d1b2b9f729ea4a4b883d1ad7379fc632b727cec23674be"}, - {file = "httpcore-1.0.8.tar.gz", hash = "sha256:86e94505ed24ea06514883fd44d2bc02d90e77e7979c8eb71b90f41d364a1bad"}, + {file = "httpcore-1.0.9-py3-none-any.whl", hash = "sha256:2d400746a40668fc9dec9810239072b40b4484b640a8c38fd654a024c7a1bf55"}, + {file = "httpcore-1.0.9.tar.gz", hash = "sha256:6e34463af53fd2ab5d807f399a9b45ea31c3dfa2276f15a2c3f00afff6e176e8"}, ] [package.dependencies] certifi = "*" -h11 = ">=0.13,<0.15" +h11 = ">=0.16" [package.extras] asyncio = ["anyio (>=4.0,<5.0)"] @@ -98,14 +86,14 @@ trio = ["trio (>=0.22.0,<1.0)"] [[package]] name = "httpx" -version = "0.25.2" +version = "0.28.1" description = "The next generation HTTP client." category = "main" optional = false python-versions = ">=3.8" files = [ - {file = "httpx-0.25.2-py3-none-any.whl", hash = "sha256:a05d3d052d9b2dfce0e3896636467f8a5342fb2b902c819428e1ac65413ca118"}, - {file = "httpx-0.25.2.tar.gz", hash = "sha256:8b8fcaa0c8ea7b05edd69a094e63a2094c4efcb48129fb757361bc423c0ad9e8"}, + {file = "httpx-0.28.1-py3-none-any.whl", hash = "sha256:d909fcccc110f8c7faf814ca82a9a4d816bc5a6dbfea25d6591d6985b8ba59ad"}, + {file = "httpx-0.28.1.tar.gz", hash = "sha256:75e98c5f16b0f35b567856f597f06ff2270a374470a5c2392242528e3e3e42fc"}, ] [package.dependencies] @@ -113,13 +101,13 @@ anyio = "*" certifi = "*" httpcore = ">=1.0.0,<2.0.0" idna = "*" -sniffio = "*" [package.extras] brotli = ["brotli", "brotlicffi"] cli = ["click (>=8.0.0,<9.0.0)", "pygments (>=2.0.0,<3.0.0)", "rich (>=10,<14)"] http2 = ["h2 (>=3,<5)"] socks = ["socksio (>=1.0.0,<2.0.0)"] +zstd = ["zstandard (>=0.18.0)"] [[package]] name = "idna" @@ -163,4 +151,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "a6328570e23a2739e1268265645d92a5d4cfb77f85586e54e9cdf4a161fd690d" +content-hash = "a15a44c6c569da243a1bb92f026303a43577907315935baa2fe0b1fc4aa188a1" diff --git a/scripts/pyproject.toml b/scripts/pyproject.toml index c775609..69b6ab2 100644 --- a/scripts/pyproject.toml +++ b/scripts/pyproject.toml @@ -6,8 +6,7 @@ authors = ["alex "] [tool.poetry.dependencies] python = "^3.9" -appdirs = "^1.4.4" -httpx = "^0.25.0" +httpx = "^0.28.1" [build-system] @@ -17,7 +16,6 @@ build-backend = "poetry.core.masonry.api" [tool.poetry.scripts] ruscreen = 'p7s.ruscreen:main' -newsboat = 'p7s.newsboat:main' mbsync_config = 'p7s.mail:generate_config' db-create = 'p7s.distrobox:create' db-enter = 'p7s.distrobox:enter' @@ -30,4 +28,3 @@ setup_emacs = 'p7s.emacs:setup_emacs' setup_ubpkg = 'p7s.ubpkg:setup_ubpkg' setup_paperwm = 'p7s.paperwm:setup_paperwm' setup_x12 = 'p7s.x12:setup_x12' -update_zfs = 'p7s.zfs:update_zfs'