| Total Complexity | 0 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | #!/usr/bin/env python3 |
||
| 2 | |||
| 3 | # -*- coding: utf-8 -*- |
||
| 4 | |||
| 5 | # hold global variables and functions for direct use in templates |
||
| 6 | # https://jinja.palletsprojects.com/en/2.11.x/api/#the-global-namespace |
||
| 7 | # https://jinja.palletsprojects.com/en/2.11.x/templates/#list-of-global-functions |
||
| 8 | |||
| 9 | from datetime import datetime, timezone |
||
| 10 | import socket |
||
| 11 | import sys |
||
| 12 | |||
| 13 | _globals = dict( |
||
| 14 | |||
| 15 | now = ( """ Return the timestamp for datetime.now() """, |
||
| 16 | lambda : datetime.now() |
||
| 17 | ), |
||
| 18 | |||
| 19 | strftime = ( """ Return a date string specified in strftime(3) format """, |
||
| 20 | lambda f='%F %T%z', tz='UTC': |
||
| 21 | datetime.now(timezone.utc if tz == 'UTC' else None).strftime(f) |
||
| 22 | ), |
||
| 23 | |||
| 24 | hostname = ( """ Return the current hostname """, |
||
| 25 | lambda : socket.gethostname() |
||
| 26 | ), |
||
| 27 | |||
| 28 | ) |
||
| 29 | |||
| 30 | for k,v in _globals.items(): |
||
| 31 | setattr(sys.modules[__name__], k, v[1]) |
||
| 32 |