From 0f62567e7329a96e0d7d7ad5ba4e04161b6d894e Mon Sep 17 00:00:00 2001 From: Alad Wenter Date: Mon, 26 Jun 2023 13:58:51 +0200 Subject: [PATCH] sync-rebuild: expand --user home directory --- examples/sync-rebuild | 22 +++++++++++++++++++--- makepkg/PKGBUILD | 5 ++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/examples/sync-rebuild b/examples/sync-rebuild index b73fc5d8..8ca9d4f8 100644 --- a/examples/sync-rebuild +++ b/examples/sync-rebuild @@ -11,10 +11,26 @@ import tempfile from pwd import getpwnam from decimal import Decimal #from pyalpm import vercmp -from xdg import BaseDirectory from srcinfo.parse import parse_srcinfo ARGV0 = 'sync-rebuild' +def xdg_cache_home(user=None): + """Retrieve XDG_CACHE_HOME from the XDG Base Directory specification + """ + if user is not None: + user_home = os.path.expanduser("~" + user) + else: + user_home = os.path.expanduser("~") + cache_home = os.path.join(user_home, '.cache') + + # Note: this only retrieves `XDG_CACHE_HOME` from the current user + # environment regardless if `user` is specified. + if 'XDG_CACHE_HOME' in os.environ: + return os.getenv('XDG_CACHE_HOME') + + return cache_home + + def run_readline(command, check=True): """Run the output from a command line-by-line. @@ -324,11 +340,11 @@ if __name__ == '__main__': raise NotImplementedError('--user requires --chroot') # Get the path to user-specific cache files - # XXX: use the --user $HOME directory, if specified + # Note: this only retrieves `AURDEST` from the current user environment. if 'AURDEST' in os.environ: aurdest = os.getenv('AURDEST') else: - aurdest = os.path.join(BaseDirectory.xdg_cache_home, 'aurutils/sync') + aurdest = os.path.join(xdg_cache_home(args.user), 'aurutils/sync') main({i:1 for i in args.targets}, args.database, aurdest, args.fail_fast, args.no_sync, args.chroot, args.user) diff --git a/makepkg/PKGBUILD b/makepkg/PKGBUILD index 67d04fcc..ed0f65ad 100644 --- a/makepkg/PKGBUILD +++ b/makepkg/PKGBUILD @@ -1,6 +1,6 @@ # Maintainer: Alad Wenter pkgname=aurutils-git -pkgver=15.1.r1.gc27f9894 +pkgver=16.4.r0.g9d8342c5 pkgrel=1 pkgdesc='helper tools for the arch user repository' url='https://github.com/AladW/aurutils' @@ -20,8 +20,7 @@ optdepends=('bash-completion: bash completion' 'ninja: aur-sync ninja support' 'bat: view-delta example script' 'git-delta: view-delta example script' - 'python-srcinfo: sync-rebuild example script' - 'python-pyxdg: sync-rebuild example script') + 'python-srcinfo: sync-rebuild example script') pkgver() { cd aurutils -- 2.11.4.GIT