]>
git.mar77i.info Git - hublib/blob - hub/utils.py
1 from jinja2_simple_tags
import StandaloneTag
3 from .static
import StaticTemplateFile
, TreeFileApp
5 class StaticTag(StandaloneTag
):
10 static_file
: StaticTemplateFile
, hubapp
: str | TreeFileApp |
None
12 h
= static_file
.hubapp
15 elif isinstance(hubapp
, str):
16 return h
.root
.hubapps
[hubapp
]
17 elif isinstance(hubapp
, TreeFileApp
):
19 return static_file
.hubapp
22 self
, filename
: str = "", hubapp
: str | TreeFileApp |
None = None
25 If filename starts with '/', interpret the path as relative to hubapp.base_dir,
26 otherwise assume the path is relative to the current file.
28 static_file
= self
.context
["static_file"]
29 hubapp
= self
.get_hubapp(static_file
, hubapp
)
30 if filename
.startswith("/") or hubapp
!= static_file
.hubapp
:
31 path
= hubapp
.base_dir
/ filename
.lstrip("/")
33 path
= static_file
.path
.parent
/ filename
34 return hubapp
.uri(path
)
37 def get_redis_pass(redis_conf
: str) -> str:
39 Poor man's redis credentials: read the password from redis_conf.
40 Requires redis being configured with a `requirepass` password set.
42 prefix
= "requirepass "
43 with open(redis_conf
, "rt") as fh
:
45 if line
.startswith(prefix
):
46 return line
[len(prefix
) :].rstrip()
47 raise ValueError("No redis password found")