2021-05-19 18:07:42 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
""" Test LDAP """
|
|
|
|
import datetime
|
|
|
|
import logging
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import dateutil.tz
|
|
|
|
import pytz
|
|
|
|
|
2021-05-19 19:19:57 +02:00
|
|
|
from mylib.ldap import format_datetime, format_date, parse_datetime, parse_date
|
2021-05-19 18:07:42 +02:00
|
|
|
from mylib.scripts.helpers import get_opts_parser
|
|
|
|
from mylib.scripts.helpers import init_logging
|
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger('mylib.scripts.ldap_test')
|
|
|
|
|
2021-05-19 19:19:57 +02:00
|
|
|
|
|
|
|
def main(argv=None): # pylint: disable=too-many-locals,too-many-statements
|
2021-05-19 18:07:42 +02:00
|
|
|
""" Script main """
|
|
|
|
if argv is None:
|
|
|
|
argv = sys.argv[1:]
|
|
|
|
|
|
|
|
# Options parser
|
|
|
|
parser = get_opts_parser(just_try=True)
|
|
|
|
options = parser.parse_args()
|
|
|
|
|
2021-05-19 19:19:57 +02:00
|
|
|
# Initialize logs
|
|
|
|
init_logging(options, 'Test LDAP helpers')
|
|
|
|
|
2021-05-19 18:07:42 +02:00
|
|
|
now = datetime.datetime.now().replace(tzinfo=dateutil.tz.tzlocal())
|
2023-01-06 22:13:28 +01:00
|
|
|
print(f'Now = {now}')
|
2021-05-19 18:07:42 +02:00
|
|
|
|
|
|
|
datestring_now = format_datetime(now)
|
2023-01-06 22:13:28 +01:00
|
|
|
print(f'format_datetime : {datestring_now}')
|
|
|
|
print(f'format_datetime (from_timezone=utc) : {format_datetime(now.replace(tzinfo=None), from_timezone=pytz.utc)}')
|
|
|
|
print(f'format_datetime (from_timezone=local) : {format_datetime(now.replace(tzinfo=None), from_timezone=dateutil.tz.tzlocal())}')
|
|
|
|
print(f'format_datetime (from_timezone=local) : {format_datetime(now.replace(tzinfo=None), from_timezone="local")}')
|
|
|
|
print(f'format_datetime (from_timezone=Paris) : {format_datetime(now.replace(tzinfo=None), from_timezone="Europe/Paris")}')
|
|
|
|
print(f'format_datetime (to_timezone=utc) : {format_datetime(now, to_timezone=pytz.utc)}')
|
|
|
|
print(f'format_datetime (to_timezone=local) : {format_datetime(now, to_timezone=dateutil.tz.tzlocal())}')
|
|
|
|
print(f'format_datetime (to_timezone=local) : {format_datetime(now, to_timezone="local")}')
|
|
|
|
print(f'format_datetime (to_timezone=Tokyo) : {format_datetime(now, to_timezone="Asia/Tokyo")}')
|
|
|
|
print(f'format_datetime (naive=True) : {format_datetime(now, naive=True)}')
|
2021-05-19 18:07:42 +02:00
|
|
|
|
2023-01-06 22:13:28 +01:00
|
|
|
print(f'format_date : {format_date(now)}')
|
|
|
|
print(f'format_date (from_timezone=utc) : {format_date(now.replace(tzinfo=None), from_timezone=pytz.utc)}')
|
|
|
|
print(f'format_date (from_timezone=local) : {format_date(now.replace(tzinfo=None), from_timezone=dateutil.tz.tzlocal())}')
|
|
|
|
print(f'format_date (from_timezone=local) : {format_date(now.replace(tzinfo=None), from_timezone="local")}')
|
|
|
|
print(f'format_date (from_timezone=Paris) : {format_date(now.replace(tzinfo=None), from_timezone="Europe/Paris")}')
|
|
|
|
print(f'format_date (to_timezone=utc) : {format_date(now, to_timezone=pytz.utc)}')
|
|
|
|
print(f'format_date (to_timezone=local) : {format_date(now, to_timezone=dateutil.tz.tzlocal())}')
|
|
|
|
print(f'format_date (to_timezone=local) : {format_date(now, to_timezone="local")}')
|
|
|
|
print(f'format_date (to_timezone=Tokyo) : {format_date(now, to_timezone="Asia/Tokyo")}')
|
|
|
|
print(f'format_date (naive=True) : {format_date(now, naive=True)}')
|
2021-05-19 18:07:42 +02:00
|
|
|
|
2023-01-06 22:13:28 +01:00
|
|
|
print(f'parse_datetime : {parse_datetime(datestring_now)}')
|
|
|
|
print(f'parse_datetime (default_timezone=utc) : {parse_datetime(datestring_now[0:-1], default_timezone=pytz.utc)}')
|
|
|
|
print(f'parse_datetime (default_timezone=local) : {parse_datetime(datestring_now[0:-1], default_timezone=dateutil.tz.tzlocal())}')
|
|
|
|
print(f'parse_datetime (default_timezone=local) : {parse_datetime(datestring_now[0:-1], default_timezone="local")}')
|
|
|
|
print(f'parse_datetime (default_timezone=Paris) : {parse_datetime(datestring_now[0:-1], default_timezone="Europe/Paris")}')
|
|
|
|
print(f'parse_datetime (to_timezone=utc) : {parse_datetime(datestring_now, to_timezone=pytz.utc)}')
|
|
|
|
print(f'parse_datetime (to_timezone=local) : {parse_datetime(datestring_now, to_timezone=dateutil.tz.tzlocal())}')
|
|
|
|
print(f'parse_datetime (to_timezone=local) : {parse_datetime(datestring_now, to_timezone="local")}')
|
|
|
|
print(f'parse_datetime (to_timezone=Tokyo) : {parse_datetime(datestring_now, to_timezone="Asia/Tokyo")}')
|
|
|
|
print(f'parse_datetime (naive=True) : {parse_datetime(datestring_now, naive=True)}')
|
2021-05-19 18:07:42 +02:00
|
|
|
|
2023-01-06 22:13:28 +01:00
|
|
|
print(f'parse_date : {parse_date(datestring_now)}')
|
|
|
|
print(f'parse_date (default_timezone=utc) : {parse_date(datestring_now[0:-1], default_timezone=pytz.utc)}')
|
|
|
|
print(f'parse_date (default_timezone=local) : {parse_date(datestring_now[0:-1], default_timezone=dateutil.tz.tzlocal())}')
|
|
|
|
print(f'parse_date (default_timezone=local) : {parse_date(datestring_now[0:-1], default_timezone="local")}')
|
|
|
|
print(f'parse_date (default_timezone=Paris) : {parse_date(datestring_now[0:-1], default_timezone="Europe/Paris")}')
|
|
|
|
print(f'parse_date (to_timezone=utc) : {parse_date(datestring_now, to_timezone=pytz.utc)}')
|
|
|
|
print(f'parse_date (to_timezone=local) : {parse_date(datestring_now, to_timezone=dateutil.tz.tzlocal())}')
|
|
|
|
print(f'parse_date (to_timezone=local) : {parse_date(datestring_now, to_timezone="local")}')
|
|
|
|
print(f'parse_date (to_timezone=Tokyo) : {parse_date(datestring_now, to_timezone="Asia/Tokyo")}')
|
|
|
|
print(f'parse_date (naive=True) : {parse_date(datestring_now, naive=True)}')
|