Skip to content

Commit 7e5f123

Browse files
committed
#211 print date and time in the attrib output
* Pass the "utc" time to the jinja2 template * Update the default html template to display the date and time Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 60e0c31 commit 7e5f123

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/attributecode/attrib.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import codecs
2222
import collections
23+
import datetime
2324
import os
2425
from posixpath import basename
2526
from posixpath import dirname
@@ -102,11 +103,14 @@ def generate(abouts, template_string=None):
102103
# Add the license name expression string into the about object
103104
about.license_name_expression = lic_name_expression
104105

106+
# Get the current UTC time
107+
utcnow = datetime.datetime.utcnow()
105108
rendered = template.render(abouts=abouts, common_licenses=COMMON_LICENSES,
106109
license_key_and_context=sorted_license_key_and_context,
107110
license_file_name_and_key=license_file_name_and_key,
108111
license_key_to_license_name=license_key_to_license_name,
109-
license_name_to_license_key=license_name_to_license_key)
112+
license_name_to_license_key=license_name_to_license_key,
113+
utcnow=utcnow)
110114
except Exception as e:
111115
line = getattr(e, 'lineno', None)
112116
ln_msg = ' at line: %r' % line if line else ''

src/attributecode/templates/default_html.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
{% endfor %}
8383

8484
<h3><a id="End">End</a></h3>
85+
<i>This file was generated on: {{ utcnow }} (UTC)</i>
8586
</body>
8687
</html>
8788

tests/test_attrib.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ def test_generate_from_file_with_default_template(self):
5757
result = attrib.generate_from_file(abouts)
5858
with open(get_test_loc('attrib_gen/expected_default_attrib.html')) as exp:
5959
expected = exp.read()
60+
# strip the timestamp: the timestamp is wrapped in italic block
6061
self.assertEqual([x.rstrip() for x in expected.splitlines()],
61-
[x.rstrip() for x in result.splitlines()])
62+
[x.rstrip() for x in result.splitlines() if not '<i>' in x])

0 commit comments

Comments
 (0)