5 Commits

Author SHA1 Message Date
fb0b4b0223 Merge 19aa5acd62 into ee7e9ef2a3 2025-05-24 18:17:55 +02:00
19aa5acd62 Update info_api.py
changed options from 1/0 to true/false
2024-03-18 22:39:21 +01:00
d34d9a972d Update config.yaml.dist
changed options from 1/0 to true/false
2024-03-18 22:38:37 +01:00
5629ffa332 Update config.yaml.dist
added the config part of get data dir usage
2024-03-04 01:04:37 +01:00
187869c21d Update info_api.py
added a way to disable getDiskUsageInfo
2024-03-04 01:01:17 +01:00
3 changed files with 22 additions and 16 deletions

View File

@ -121,7 +121,6 @@
.thumbnail
width: 4em
height: 3em
background-position: 50% 30%
li
margin: 0 0.3em 0.3em 0
display: inline-block

View File

@ -177,3 +177,9 @@ privileges:
## usage: schema://user:password@host:port/database_name
## example: postgres://szuru:dog@localhost:5432/szuru_test
#database:
## get the data dir usage
## false disabled
## true enabled ( default )
data_dir_get_usage: true

View File

@ -10,22 +10,23 @@ _cache_result = None # type: Optional[int]
def _get_disk_usage() -> int:
global _cache_time, _cache_result
threshold = timedelta(hours=48)
now = datetime.utcnow()
if _cache_time and _cache_time > now - threshold:
assert _cache_result is not None
return _cache_result
total_size = 0
for dir_path, _, file_names in os.walk(config.config["data_dir"]):
for file_name in file_names:
file_path = os.path.join(dir_path, file_name)
try:
total_size += os.path.getsize(file_path)
except FileNotFoundError:
pass
_cache_time = now
_cache_result = total_size
if config.config["data_dir_get_usage"]:
global _cache_time, _cache_result
threshold = timedelta(hours=48)
now = datetime.utcnow()
if _cache_time and _cache_time > now - threshold:
assert _cache_result is not None
return _cache_result
for dir_path, _, file_names in os.walk(config.config["data_dir"]):
for file_name in file_names:
file_path = os.path.join(dir_path, file_name)
try:
total_size += os.path.getsize(file_path)
except FileNotFoundError:
pass
_cache_time = now
_cache_result = total_size
return total_size