Compare commits
18 Commits
s-allius/i
...
s-allius/i
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6a5490229 | ||
|
|
bdf08f64a1 | ||
|
|
25145a9c29 | ||
|
|
628f992922 | ||
|
|
fc93930656 | ||
|
|
e1f0aac9bf | ||
|
|
b321cfce0f | ||
|
|
cf9911f2f1 | ||
|
|
d35c4e7b90 | ||
|
|
911d0a9612 | ||
|
|
4012196fcd | ||
|
|
cfe13a01d1 | ||
|
|
ab2d4ed831 | ||
|
|
089fb92a43 | ||
|
|
6560079d89 | ||
|
|
4688e6a75b | ||
|
|
4f6764e151 | ||
|
|
484df1dc46 |
@@ -7,7 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [unreleased]
|
||||
|
||||
- Update ghcr.io/hassio-addons/base Docker tag to v17.2.5
|
||||
- fix a lot of pytest-asyncio problems in the unit tests
|
||||
- Cleanup startup code for Quart and the Proxy
|
||||
- Redirect the hypercorn traces to a separate log-file
|
||||
|
||||
@@ -1,58 +1,26 @@
|
||||
from quart import render_template
|
||||
from quart_babel import format_datetime, format_decimal, _
|
||||
from quart_babel import format_datetime, format_decimal
|
||||
from quart.helpers import send_from_directory
|
||||
from werkzeug.utils import secure_filename
|
||||
from cnf.config import Config
|
||||
from datetime import datetime
|
||||
from os import DirEntry
|
||||
import os
|
||||
from dateutil import tz
|
||||
|
||||
from . import web
|
||||
|
||||
|
||||
def _get_birth_from_log(path: str) -> None | datetime:
|
||||
'''read timestamp from the first line of a log file'''
|
||||
dt = None
|
||||
try:
|
||||
with open(path) as f:
|
||||
first_line = f.readline()
|
||||
first_line = first_line.lstrip("'")
|
||||
fmt = "%Y-%m-%d %H:%M:%S" if first_line[4] == '-' \
|
||||
else "%d-%m-%Y %H:%M:%S"
|
||||
dt = datetime.strptime(first_line[0:19], fmt). \
|
||||
replace(tzinfo=tz.tzlocal())
|
||||
except Exception:
|
||||
pass
|
||||
return dt
|
||||
|
||||
|
||||
def _get_file(file: DirEntry) -> dict:
|
||||
def _get_file(file):
|
||||
'''build one row for the connection table'''
|
||||
entry = {}
|
||||
entry['name'] = file.name
|
||||
stat = file.stat()
|
||||
entry['size'] = format_decimal(stat.st_size)
|
||||
try:
|
||||
dt = stat.st_birthtime
|
||||
|
||||
except Exception:
|
||||
dt = _get_birth_from_log(file.path)
|
||||
|
||||
if dt:
|
||||
entry['created'] = format_datetime(dt, format="short")
|
||||
|
||||
# sort by creating date, if available
|
||||
entry['date'] = dt if isinstance(dt, float) else dt.timestamp()
|
||||
else:
|
||||
entry['created'] = _('n/a')
|
||||
entry['date'] = stat.st_mtime
|
||||
|
||||
entry['date'] = stat.st_mtime
|
||||
entry['created'] = format_datetime(stat.st_ctime, format="short")
|
||||
entry['modified'] = format_datetime(stat.st_mtime, format="short")
|
||||
return entry
|
||||
|
||||
|
||||
def get_list_data() -> list:
|
||||
def get_list_data():
|
||||
'''build the connection table'''
|
||||
file_list = []
|
||||
with os.scandir(Config.get_log_path()) as it:
|
||||
|
||||
@@ -9,8 +9,6 @@ from cnf.config import Config
|
||||
from mock import patch
|
||||
from proxy import Proxy
|
||||
import os, errno
|
||||
from os import DirEntry, stat_result
|
||||
import datetime
|
||||
|
||||
pytest_plugins = ('pytest_asyncio',)
|
||||
|
||||
@@ -203,33 +201,14 @@ async def test_notes_fetch(client, config_conn):
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_file_fetch(client, config_conn, monkeypatch):
|
||||
async def test_file_fetch(client, config_conn):
|
||||
"""Test the data-fetch route."""
|
||||
_ = config_conn
|
||||
assert Config.log_path == 'app/tests/log/'
|
||||
def my_stat1(*arg):
|
||||
stat = stat_result
|
||||
stat.st_size = 20
|
||||
stat.st_birthtime = datetime.datetime(2024, 1, 31, 10, 30, 15)
|
||||
stat.st_mtime = datetime.datetime(2024, 1, 1, 1, 30, 15).timestamp()
|
||||
return stat
|
||||
|
||||
monkeypatch.setattr(DirEntry, "stat", my_stat1)
|
||||
response = await client.get('/file-fetch')
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def my_stat2(*arg):
|
||||
stat = stat_result
|
||||
stat.st_size = 20
|
||||
stat.st_mtime = datetime.datetime(2024, 1, 1, 1, 30, 15).timestamp()
|
||||
return stat
|
||||
|
||||
monkeypatch.setattr(DirEntry, "stat", my_stat2)
|
||||
monkeypatch.delattr(stat_result, "st_birthtime")
|
||||
response = await client.get('/file-fetch')
|
||||
assert response.status_code == 200
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_file(client, config_conn):
|
||||
"""Test the send-file route."""
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# 1 Build Base Image #
|
||||
######################
|
||||
|
||||
ARG BUILD_FROM="ghcr.io/hassio-addons/base:17.2.5"
|
||||
ARG BUILD_FROM="ghcr.io/hassio-addons/base:17.2.4"
|
||||
# hadolint ignore=DL3006
|
||||
FROM $BUILD_FROM AS base
|
||||
|
||||
|
||||
Reference in New Issue
Block a user