Fix pytz and time localization

This commit is contained in:
Simon Beginn 2021-10-13 12:54:22 +02:00
parent 5de292e12a
commit 4a7376f17b
No known key found for this signature in database
GPG key ID: 033A4D4CE4E063D6
5 changed files with 10 additions and 5 deletions

View file

@ -26,7 +26,7 @@ RUN apk add --no-cache --update \
sqlite-libs \
py3-pip \
build-base python3-dev && \
pip3 install peewee tzlocal && \
pip3 install peewee tzlocal pytz && \
apk del git build-base python3-dev
WORKDIR /home/py-kms

View file

@ -29,7 +29,7 @@ RUN apk add --no-cache --update \
git clone https://github.com/coleifer/sqlite-web.git /tmp/sqlite_web && \
mv /tmp/sqlite_web/sqlite_web /home/ && \
rm -rf /tmp/sqlite_web && \
pip3 install peewee tzlocal pysqlite3 && \
pip3 install peewee tzlocal pytz pysqlite3 && \
chmod a+x /usr/bin/start.sh && \
apk del git build-base python3-dev

0
docker/docker-py3-kms/start.sh Normal file → Executable file
View file

View file

@ -15,7 +15,7 @@ If you wish to get _py-kms_ just up and running without installing any dependenc
Docker also solves problems regarding the explicit IPv4 and IPv6 usage (it just supports both). The following
command will download, "install" and start _py-kms_ and also keep it alive after any service disruption.
```bash
docker run -d --name py-kms --restart always -p 1688:1688 pykmsorg/py-kms
docker run -d --name py-kms --restart always -p 1688:1688 -v /etc/localtime:/etc/localtime:ro pykmsorg/py-kms
```
If you just want to use the image and don't want to build them yourself, you can always use the official image at the [Docker Hub](https://hub.docker.com/r/pykmsorg/py-kms) (`pykmsorg/py-kms`). To ensure that you are using always the
latest version you should check something like [watchtower](https://github.com/containrrr/watchtower) out !

View file

@ -119,11 +119,11 @@ class kmsBase:
# Localize the request time, if module "tzlocal" is available.
try:
from datetime import datetime
from tzlocal import get_localzone
from pytz.exceptions import UnknownTimeZoneError
try:
tz = get_localzone()
local_dt = tz.localize(requestDatetime)
local_dt = datetime.fromisoformat(str(requestDatetime)).astimezone(get_localzone())
except UnknownTimeZoneError:
pretty_printer(log_obj = loggersrv.warning,
put_text = "{reverse}{yellow}{bold}Unknown time zone ! Request time not localized.{end}")
@ -132,6 +132,11 @@ class kmsBase:
pretty_printer(log_obj = loggersrv.warning,
put_text = "{reverse}{yellow}{bold}Module 'tzlocal' not available ! Request time not localized.{end}")
local_dt = requestDatetime
except Exception as e:
# Just in case something else goes wrong
loggersrv.warning('Okay, something went horribly wrong while localizing the request time (proceeding anyways): ' + str(e))
local_dt = requestDatetime
pass
# Activation threshold.
# https://docs.microsoft.com/en-us/windows/deployment/volume-activation/activate-windows-10-clients-vamt