Passed
Push — develop ( 503712...bde8f9 )
by Shalom
02:13
created

inji.globals   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 0
eloc 15
dl 0
loc 32
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 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 1
from datetime import datetime, timezone
10 1
import socket
11 1
import sys
12
13 1
_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 1
for k,v in _globals.items():
31
  setattr(sys.modules[__name__], k, v[1])
32