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