]>
git.mar77i.info Git - hublib/blob - hub/utils.py
b66fd97992c224a41e37928e5b68fc997349eb0e
1 from jinja2_simple_tags
import StandaloneTag
3 from .hubapp
import TreeFileApp
5 class StaticTag(StandaloneTag
):
9 self
, filename
: str = "", hubapp
: str | TreeFileApp |
None = None
12 If filename starts with '/', interpret the path as relative to hubapp.base_dir,
13 otherwise assume the path is relative to the current file.
15 static_file
= self
.context
["static_file"]
16 h
= static_file
.hubapp
17 if isinstance(hubapp
, str):
18 h
= h
.app
.hubapps
[hubapp
]
19 elif isinstance(hubapp
, TreeFileApp
):
22 if filename
.startswith("/") or h
!= static_file
.hubapp
:
23 path
= h
.base_dir
/ filename
.lstrip("/")
25 path
= static_file
.path
.parent
/ filename
29 def get_redis_pass(redis_conf
):
31 Poor man's redis credentials: read the password from redis_conf.
32 Requires redis being configured with a `requirepass` password set.
34 prefix
= "requirepass "
35 with open(redis_conf
, "rt") as fh
:
37 if line
.startswith(prefix
):
38 return line
[len(prefix
) :].rstrip()