~lioploum/offpunk-devel

offpunk: implement set cache directory v1 PROPOSED

prx: 1
 implement set cache directory

 2 files changed, 13 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~lioploum/offpunk-devel/patches/48820/mbox | git am -3
Learn more about email & git

[PATCH offpunk] implement set cache directory Export this patch

Hi,
find below a patch which let user set a custom chache folder.

Environment variable OFFPUNK_CACHE_PATH is used.
This way, it can be set globally in a profile, or occasionnaly before running offpunk.
It also avoid the pain to parse options and dealing with flags in scripts.
Thank you for your attention.
Regards.

prx
---
 man/netcache.1 | 9 +++++++++
 offutils.py    | 5 ++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/man/netcache.1 b/man/netcache.1
index d2aab99..eeaf485 100644
--- a/man/netcache.1
+++ b/man/netcache.1
@@ -27,6 +27,15 @@ otherwise it would always refresh it from the version available online.
It is also useful for mapping a given URL to its location in the cache,
independently of whether it has been downloaded first.
.Pp
Default cache path is
.Pa ~/.cache/offpunk .
Set
.Ev OFFPUNK_CACHE_PATH
environment variable to use another location.
.Bd -literal
OFFPUNK_CACHE_PATH=/home/ploum/custom-cache netcache.py gemini://some.url
.Ed
.Pp
.Xr Offpunk 1
is a command-line browser and feed reader dedicated to browsing the Web,
Gemini, Gopher and Spartan.
diff --git a/offutils.py b/offutils.py
index ff34ef0..a2097e9 100644
--- a/offutils.py
+++ b/offutils.py
@@ -62,9 +62,12 @@ def xdg(folder="cache"):
    #if no XDG .local/share and not XDG .config, we use the old config
    if not os.path.exists(data_home) and os.path.exists(_old_config):
        _DATA_DIR = _CONFIG_DIR
    ## get _CACHE_PATH from OFFPUNK_CACHE_PATH environment variable
    #  if OFFPUNK_CACHE_PATH empty, set default to ~/.cache/offpunk
    cache_home = os.environ.get('XDG_CACHE_HOME') or\
                    os.path.join(_home,'.cache')
    _CACHE_PATH = os.path.join(os.path.expanduser(cache_home),"offpunk/")
    _CACHE_PATH = os.environ.get('OFFPUNK_CACHE_PATH', \
        os.path.join(os.path.expanduser(cache_home),"offpunk/"))
    os.makedirs(_CACHE_PATH,exist_ok=True)
    if folder == "cache" and not UPGRADED:
        upgrade_cache(_CACHE_PATH)
-- 
2.38.5

---- Fin du message transféré -----