From 4a7376f17b0306c74b7180b16a08803dac1c522f Mon Sep 17 00:00:00 2001 From: Simon Beginn Date: Wed, 13 Oct 2021 12:54:22 +0200 Subject: [PATCH] Fix pytz and time localization --- docker/docker-py3-kms-minimal/Dockerfile | 2 +- docker/docker-py3-kms/Dockerfile | 2 +- docker/docker-py3-kms/start.sh | 0 docs/Getting Started.md | 2 +- py-kms/pykms_Base.py | 9 +++++++-- 5 files changed, 10 insertions(+), 5 deletions(-) mode change 100644 => 100755 docker/docker-py3-kms/start.sh diff --git a/docker/docker-py3-kms-minimal/Dockerfile b/docker/docker-py3-kms-minimal/Dockerfile index 2fd9768..98eb5ce 100644 --- a/docker/docker-py3-kms-minimal/Dockerfile +++ b/docker/docker-py3-kms-minimal/Dockerfile @@ -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 diff --git a/docker/docker-py3-kms/Dockerfile b/docker/docker-py3-kms/Dockerfile index e98a808..bbe06c7 100644 --- a/docker/docker-py3-kms/Dockerfile +++ b/docker/docker-py3-kms/Dockerfile @@ -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 diff --git a/docker/docker-py3-kms/start.sh b/docker/docker-py3-kms/start.sh old mode 100644 new mode 100755 diff --git a/docs/Getting Started.md b/docs/Getting Started.md index 122e6ae..ce1c633 100644 --- a/docs/Getting Started.md +++ b/docs/Getting Started.md @@ -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 ! diff --git a/py-kms/pykms_Base.py b/py-kms/pykms_Base.py index 6397b4a..dd55f31 100644 --- a/py-kms/pykms_Base.py +++ b/py-kms/pykms_Base.py @@ -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