Skip to content

Commit 09a600f

Browse files
author
Dave Hein
committedJun 9, 2016
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
1 parent f821a73 commit 09a600f

11 files changed

+129
-7
lines changed
 

‎dev/build/register-package.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pushd src > /dev/null
1212

1313
# Register the project
1414
#
15-
twine register -r pypi dist/authenticator-1.1.1.tar.gz
16-
twine register -r pypi dist/authenticator-1.1.1-py3-none-any.whl
15+
twine register -r pypi dist/authenticator-1.1.2.tar.gz
16+
twine register -r pypi dist/authenticator-1.1.2-py3-none-any.whl
1717

1818
popd > /dev/null

‎dev/build/test-register-package.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ pushd src > /dev/null
1212

1313
# Register the project
1414
#
15-
twine register -r pypitest dist/authenticator-1.1.1.tar.gz
16-
twine register -r pypitest dist/authenticator-1.1.1-py3-none-any.whl
15+
twine register -r pypitest dist/authenticator-1.1.2.tar.gz
16+
twine register -r pypitest dist/authenticator-1.1.2-py3-none-any.whl
1717
# python setup.py register -r https://testpypi.python.org/pypi
1818

1919
popd > /dev/null

‎dev/docker/Dockerfile

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Using a base Ubuntu 14.04 that has the latest updates already
2+
#
3+
# Base images can be found here: https://hub.docker.com/_/ubuntu/
4+
# Ubuntu 14.04 LTS (Trusty Tahr) is supported through 2019.
5+
# Ubuntu 16.04 LTS (Xenial Xerus) has just been released and probably should
6+
# not be used yet (because dependent software may need to be updated and
7+
# made compatible).
8+
#
9+
FROM ubuntu:14.04.4
10+
MAINTAINER Dave Hein <dhein@acm.org>
11+
12+
# Setting this environment variable prevents errors during package installs
13+
# that look like:
14+
#
15+
# debconf: unable to initialize frontend: Dialog
16+
# debconf: (TERM is not set, so the dialog frontend is not usable.)
17+
# debconf: falling back to frontend: Readline
18+
#
19+
# As per: http://stackoverflow.com/a/35976127/1392864
20+
#
21+
ARG DEBIAN_FRONTEND=noninteractive
22+
23+
# Update apt package info and upgrade installed packages (base image
24+
# has some packages installed)
25+
#
26+
# Install some basic package fetching tools
27+
#
28+
ENV FETCH_REFRESHED_AT 2016-06-08T05:25-0500
29+
RUN apt-get update && apt-get -y upgrade \
30+
apt-get install -yqq software-properties-common python-software-properties && \
31+
apt-get -yqq install wget
32+
33+
# Install Python 3.5
34+
#
35+
ENV PYTHON35_REFRESHED_AT 2016-06-08T05:25-0500
36+
RUN add-apt-repository ppa:fkrull/deadsnakes && \
37+
apt-get update
38+
RUN apt-get install -yqq python3.5
39+
RUN apt-get install -yqq python3.5-dev
40+
RUN apt-get install -yqq libncurses5-dev
41+
RUN apt-get install -yqq python3.5-venv
42+
43+
# Install pip & setuptools
44+
#
45+
ENV PIP3_REFRESHED_AT 2016-06-08T05:47-0500
46+
RUN wget https://bootstrap.pypa.io/get-pip.py
47+
RUN python3 get-pip.py
48+
RUN pip3 install setuptools --upgrade
49+
50+
# Install git
51+
#
52+
ENV GIT_REFRESHED_AT 2016-06-08T05:47-0500
53+
RUN apt-get install -yqq git-core
54+
55+
# Install gcc
56+
#
57+
ENV GCC_REFRESHED_AT 2016-06-08T05:47-0500
58+
RUN apt-get install -yqq \
59+
autoconf \
60+
automake \
61+
g++ \
62+
gcc \
63+
libffi-dev \
64+
libssl-dev \
65+
make \
66+
patch
67+
68+
# Local stuff
69+
ENV LOCALSTUFF_REFRESHED_AT 2016-06-08T06:07-0500
70+
COPY establish-dev.sh /root/trash/
71+
WORKDIR /root/trash

‎dev/docker/build.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#! /bin/bash
2+
#
3+
# Create the image ... for the python35 dev environment
4+
#
5+
docker build -t datihein/devauthenticator:python35 .

‎dev/docker/establish-dev.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#! /bin/bash
2+
#
3+
git clone https://github.com/JeNeSuisPasDave/authenticator
4+
cd authenticator
5+
python3.5 -m venv --clear --copies venv35
6+
. venv35/bin/activate
7+
pip install --quiet --upgrade pip
8+
pip install --quiet --upgrade setuptools
9+
./dev/venv/provision-venv.sh
10+
deactivate

‎dev/docker/run.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#! /bin/bash
2+
#
3+
4+
# Start the python35 dev container
5+
#
6+
docker run --rm -t -i \
7+
datihein/devauthenticator:python35

‎dev/runonetest.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#! /bin/bash
22
#
33
PYTHONPATH="$(pwd)/src" python -m unittest \
4-
tests.test_CLI.CoreCLITests.test_list_with_three_configs_verbose
4+
tests.test_ClientData.CoreClientDataTests.test_string

‎src/authenticator/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@
4040

4141
__author__ = "Dave Hein <dhein@acm.org>"
4242
__license__ = "MIT"
43-
__version__ = "1.1.1"
43+
__version__ = "1.1.2"

‎src/authenticator/data.py

+26
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ def _init_last_count_update_time(self, kw_args):
228228

229229
self.__last_count_update_time = datetime(
230230
1, 1, 1, 0, 0, 0, 0, ClientData.utz()).strftime(self._isoFmt)
231+
# Fix issue on some systems, e.g. Debian, where %Y doesn't zero-pad
232+
if self.__last_count_update_time[0:3] != "000":
233+
self.__last_count_update_time = "000" + \
234+
self.__last_count_update_time
231235
if 'lastCountUpdateTime' in kw_args:
232236
t = datetime.min
233237
v = kw_args['lastCountUpdateTime']
@@ -242,6 +246,17 @@ def _init_last_count_update_time(self, kw_args):
242246
if t.tzinfo is None:
243247
t = t.replace(tzinfo=ClientData.utz())
244248
self.__last_count_update_time = t.strftime(self._isoFmt)
249+
# Fix issue on some systems, e.g. Debian, where %Y doesn't zero-pad
250+
tpadding = ""
251+
if 10 > t.year:
252+
tpadding = "000"
253+
elif 100 > t.year:
254+
tpadding = "00"
255+
elif 1000 > t.year:
256+
tpadding = "0"
257+
if "0" != self.__last_count_update_time[0:1]:
258+
self.__last_count_update_time = tpadding + \
259+
self.__last_count_update_time
245260

246261
def _init_period(self, kw_args):
247262
"""Process kw_arg period."""
@@ -482,6 +497,17 @@ def set_last_count_update_time(self, update_time):
482497

483498
if isinstance(update_time, datetime):
484499
self.__last_count_update_time = update_time.strftime(self._isoFmt)
500+
# Fix issue on some systems, e.g. Debian, where %Y doesn't zero-pad
501+
tpadding = ""
502+
if 10 > update_time.year:
503+
tpadding = "000"
504+
elif 100 > update_time.year:
505+
tpadding = "00"
506+
elif 1000 > update_time.year:
507+
tpadding = "0"
508+
if "0" != self.__last_count_update_time[0:1]:
509+
self.__last_count_update_time = tpadding + \
510+
self.__last_count_update_time
485511
else:
486512
self.__last_count_update_time = update_time
487513

‎src/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# the version across setup.py and the project code, see
3131
# https://packaging.python.org/en/latest/single_source_version.html
3232
#
33-
version='1.1.1',
33+
version='1.1.2',
3434

3535
description='A HOTP/TOTP code generator for the command line.',
3636
long_description=long_description,

‎tests/test_ClientData.py

+3
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ def test_constructor_last_count_update_time(self):
320320
cut = ClientData(**args)
321321
expected = datetime(
322322
1, 1, 1, 0, 0, 0, 0, self.__utz).strftime(self.isoFmt)
323+
# Fix issue on some systems, e.g. Debian, where %Y doesn't zero-pad
324+
if expected[0:3] != "000":
325+
expected = "000" + expected
323326
self.assertEqual(expected, cut.last_count_update_time())
324327
# unix epoch time
325328
#

0 commit comments

Comments
 (0)
Please sign in to comment.