Permalink
Browse files

Adjust for strftime() handling %Y inconsistantly

On Debian systems, datetime.strftime("%Y") will produce less than a
4-digit year if the value is < 1000. On OS X and Windows sytems, it
will pad on the left with zeros to create a 4-digit year when the
value is < 1000.

I changed the code to detect whether padding was applied and supply
the correct padding if it was missing.

Also added recipe for a Docker container that could be used for
Ubuntu testing and development.

Bump version to 1.1.2
  • Loading branch information...
Dave Hein
Dave Hein committed Jun 9, 2016
1 parent f821a73 commit 09a600f881c78448a6c21b995ffac4addba2b45d
@@ -12,7 +12,7 @@ pushd src > /dev/null
# Register the project
#
twine register -r pypi dist/authenticator-1.1.1.tar.gz
twine register -r pypi dist/authenticator-1.1.1-py3-none-any.whl
twine register -r pypi dist/authenticator-1.1.2.tar.gz
twine register -r pypi dist/authenticator-1.1.2-py3-none-any.whl
popd > /dev/null
@@ -12,8 +12,8 @@ pushd src > /dev/null
# Register the project
#
twine register -r pypitest dist/authenticator-1.1.1.tar.gz
twine register -r pypitest dist/authenticator-1.1.1-py3-none-any.whl
twine register -r pypitest dist/authenticator-1.1.2.tar.gz
twine register -r pypitest dist/authenticator-1.1.2-py3-none-any.whl
# python setup.py register -r https://testpypi.python.org/pypi
popd > /dev/null
@@ -0,0 +1,71 @@
# Using a base Ubuntu 14.04 that has the latest updates already
#
# Base images can be found here: https://hub.docker.com/_/ubuntu/
# Ubuntu 14.04 LTS (Trusty Tahr) is supported through 2019.
# Ubuntu 16.04 LTS (Xenial Xerus) has just been released and probably should
# not be used yet (because dependent software may need to be updated and
# made compatible).
#
FROM ubuntu:14.04.4
MAINTAINER Dave Hein <dhein@acm.org>
# Setting this environment variable prevents errors during package installs
# that look like:
#
# debconf: unable to initialize frontend: Dialog
# debconf: (TERM is not set, so the dialog frontend is not usable.)
# debconf: falling back to frontend: Readline
#
# As per: http://stackoverflow.com/a/35976127/1392864
#
ARG DEBIAN_FRONTEND=noninteractive
# Update apt package info and upgrade installed packages (base image
# has some packages installed)
#
# Install some basic package fetching tools
#
ENV FETCH_REFRESHED_AT 2016-06-08T05:25-0500
RUN apt-get update && apt-get -y upgrade \
apt-get install -yqq software-properties-common python-software-properties && \
apt-get -yqq install wget
# Install Python 3.5
#
ENV PYTHON35_REFRESHED_AT 2016-06-08T05:25-0500
RUN add-apt-repository ppa:fkrull/deadsnakes && \
apt-get update
RUN apt-get install -yqq python3.5
RUN apt-get install -yqq python3.5-dev
RUN apt-get install -yqq libncurses5-dev
RUN apt-get install -yqq python3.5-venv
# Install pip & setuptools
#
ENV PIP3_REFRESHED_AT 2016-06-08T05:47-0500
RUN wget https://bootstrap.pypa.io/get-pip.py
RUN python3 get-pip.py
RUN pip3 install setuptools --upgrade
# Install git
#
ENV GIT_REFRESHED_AT 2016-06-08T05:47-0500
RUN apt-get install -yqq git-core
# Install gcc
#
ENV GCC_REFRESHED_AT 2016-06-08T05:47-0500
RUN apt-get install -yqq \
autoconf \
automake \
g++ \
gcc \
libffi-dev \
libssl-dev \
make \
patch
# Local stuff
ENV LOCALSTUFF_REFRESHED_AT 2016-06-08T06:07-0500
COPY establish-dev.sh /root/trash/
WORKDIR /root/trash
@@ -0,0 +1,5 @@
#! /bin/bash
#
# Create the image ... for the python35 dev environment
#
docker build -t datihein/devauthenticator:python35 .
@@ -0,0 +1,10 @@
#! /bin/bash
#
git clone https://github.com/JeNeSuisPasDave/authenticator
cd authenticator
python3.5 -m venv --clear --copies venv35
. venv35/bin/activate
pip install --quiet --upgrade pip
pip install --quiet --upgrade setuptools
./dev/venv/provision-venv.sh
deactivate
@@ -0,0 +1,7 @@
#! /bin/bash
#
# Start the python35 dev container
#
docker run --rm -t -i \
datihein/devauthenticator:python35
@@ -1,4 +1,4 @@
#! /bin/bash
#
PYTHONPATH="$(pwd)/src" python -m unittest \
tests.test_CLI.CoreCLITests.test_list_with_three_configs_verbose
tests.test_ClientData.CoreClientDataTests.test_string
@@ -40,4 +40,4 @@
__author__ = "Dave Hein <dhein@acm.org>"
__license__ = "MIT"
__version__ = "1.1.1"
__version__ = "1.1.2"
@@ -228,6 +228,10 @@ def _init_last_count_update_time(self, kw_args):
self.__last_count_update_time = datetime(
1, 1, 1, 0, 0, 0, 0, ClientData.utz()).strftime(self._isoFmt)
# Fix issue on some systems, e.g. Debian, where %Y doesn't zero-pad
if self.__last_count_update_time[0:3] != "000":
self.__last_count_update_time = "000" + \
self.__last_count_update_time
if 'lastCountUpdateTime' in kw_args:
t = datetime.min
v = kw_args['lastCountUpdateTime']
@@ -242,6 +246,17 @@ def _init_last_count_update_time(self, kw_args):
if t.tzinfo is None:
t = t.replace(tzinfo=ClientData.utz())
self.__last_count_update_time = t.strftime(self._isoFmt)
# Fix issue on some systems, e.g. Debian, where %Y doesn't zero-pad
tpadding = ""
if 10 > t.year:
tpadding = "000"
elif 100 > t.year:
tpadding = "00"
elif 1000 > t.year:
tpadding = "0"
if "0" != self.__last_count_update_time[0:1]:
self.__last_count_update_time = tpadding + \
self.__last_count_update_time
def _init_period(self, kw_args):
"""Process kw_arg period."""
@@ -482,6 +497,17 @@ def set_last_count_update_time(self, update_time):
if isinstance(update_time, datetime):
self.__last_count_update_time = update_time.strftime(self._isoFmt)
# Fix issue on some systems, e.g. Debian, where %Y doesn't zero-pad
tpadding = ""
if 10 > update_time.year:
tpadding = "000"
elif 100 > update_time.year:
tpadding = "00"
elif 1000 > update_time.year:
tpadding = "0"
if "0" != self.__last_count_update_time[0:1]:
self.__last_count_update_time = tpadding + \
self.__last_count_update_time
else:
self.__last_count_update_time = update_time
@@ -30,7 +30,7 @@
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
#
version='1.1.1',
version='1.1.2',
description='A HOTP/TOTP code generator for the command line.',
long_description=long_description,
@@ -320,6 +320,9 @@ def test_constructor_last_count_update_time(self):
cut = ClientData(**args)
expected = datetime(
1, 1, 1, 0, 0, 0, 0, self.__utz).strftime(self.isoFmt)
# Fix issue on some systems, e.g. Debian, where %Y doesn't zero-pad
if expected[0:3] != "000":
expected = "000" + expected
self.assertEqual(expected, cut.last_count_update_time())
# unix epoch time
#

0 comments on commit 09a600f

Please sign in to comment.