Utils

Timers

Timer decorators

luna_configurator.crutches_on_wheels.cow.utils.timer.printLogger(self, func, duration)[source]

Print timing to log

Parameters:
  • self – class instance with logger

  • func – measured function

  • duration – calling duration of function in secs

Return type:

None

luna_configurator.crutches_on_wheels.cow.utils.timer.timer(func)[source]

Decorator for function work time estimation.

Parameters:

func – decorating function

Returns:

decorated function.

Return type:

Callable

Common regexps

luna_configurator.crutches_on_wheels.cow.utils.regexps.REQUEST_ID_REGEXP

compiled regexp for request id string

Loggers

Loggers module.

class luna_configurator.crutches_on_wheels.cow.utils.log.Logger(template='', requestId=None)[source]

Subclass to add support for requestIdCtx.

property requestId: str

Get current request id

Returns:

  1. request id from __init__ 2) from requestIdCtx 3) default

Return type:

request id. priority

Return type:

str

luna_configurator.crutches_on_wheels.cow.utils.log.logger

disable-msg=C0103

Type:

pylint

Module realizes getting and checking request id

luna_configurator.crutches_on_wheels.cow.utils.rid.checkRequestId(requestId)[source]

Validate request id str

Parameters:

requestId – str for checking

Returns:

True if requestId match with REQUEST_ID_REGEXP otherwise False

Return type:

bool

luna_configurator.crutches_on_wheels.cow.utils.rid.generateRequestId(timeIsLocal)[source]

Generate correct request id.

Parameters:

timeIsLocal – timestamp generate in localtime or not

Returns:

standard request id string.

Return type:

str

Module realizes useful function.

async luna_configurator.crutches_on_wheels.cow.utils.functions.addCallBack(callableFunction, sleepTime=0)[source]

Function creates infinity loop, where call function :param callableFunction: function to call :param sleepTime: time in secods if callback is periodic, in seconds

Return type:

None

luna_configurator.crutches_on_wheels.cow.utils.functions.convertDateTimeToCurrentFormatDateTime(dateTimeString, currentTimeFormat)[source]

Convert datetime string from UTC or LOCAL to datetime :param dateTimeString: str with datetime :param currentTimeFormat: LOCAL or UTC

Returns:

datetime with/without timezone depends on currentTimeFormat

>>> t1 = convertDateTimeToCurrentFormatDateTime('2018-12-25 12:21:46.652495Z', 'LOCAL')
>>> print(type(t1), t1)
<class 'datetime.datetime'> 2018-12-25 12:21:46.652495
>>> t2 = convertDateTimeToCurrentFormatDateTime('2018-12-25 15:21:46.652495+03:00', 'LOCAL')
>>> print(type(t2), t2)
<class 'datetime.datetime'> 2018-12-25 12:21:46.652495
>>> t1 = convertDateTimeToCurrentFormatDateTime('2018-12-25 12:21:46.652495Z', 'UTC')
>>> print(type(t1), t1)
<class 'datetime.datetime'> 2018-12-25 12:21:46.652495+00:00
>>> t2 = convertDateTimeToCurrentFormatDateTime('2018-12-25 15:21:46.652495+03:00', 'UTC')
>>> print(type(t2), t2)
<class 'datetime.datetime'> 2018-12-25 15:21:46.652495+03:00
Return type:

datetime

luna_configurator.crutches_on_wheels.cow.utils.functions.convertDateTimeToCurrentFormatStr(dateTimeString, currentTimeFormat)[source]

Convert datetime string from UTC or LOCAL to string, considering current STORAGE_TIME :param dateTimeString: str with datetime :param currentTimeFormat: LOCAL or UTC

Returns:

str with datetime in current format

Return type:

str

luna_configurator.crutches_on_wheels.cow.utils.functions.convertEnumToSnakeDict(enum)[source]

Convert enum with camelCase name to dict with snake_case keys

Parameters:

enum – enum

Returns:

dict

Return type:

dict

luna_configurator.crutches_on_wheels.cow.utils.functions.currentDateTime(currentTimeFormat)[source]

Function get current date-time in ISO format.

Parameters:

currentTimeFormat – LOCAL or UTC

Returns:

20:30.45+01:00)

Return type:

date-time in rfc3339 format (e.g. 1997-07-16T19

Return type:

str

luna_configurator.crutches_on_wheels.cow.utils.functions.currentTimestamp(logTime='LOCAL', dbType='postgres')[source]

Function get time (local or UTC, depends on logTime). The function is needed to correctly fill in the fields in different databases

Parameters:
  • logTime – LOCAL or UTC, LOCAL for default

  • dbType – db type (oracle/postgres), postgres for default

Returns:

%M:%S.%fZ’

Return type:

Timestamp if format ‘%Y-%m-%dT%H

Return type:

Union[str, datetime]

async luna_configurator.crutches_on_wheels.cow.utils.functions.downloadImage(url, logger, timeout, accountId=None)[source]

Download image. Add Luna-Account-Id header for request. If request to lis, apply account id to request.

Parameters:
  • url – image url

  • logger – logger

  • timeout – client timeout

  • accountId – account id

Returns:

tuple with image bytes and its content type

Raises:

VLException(Error.FailDownloadImage.format(url), 400, isCriticalError=False) if failed to download image

Return type:

tuple[bytes, str]

luna_configurator.crutches_on_wheels.cow.utils.functions.getPageCount(objectCount, pageSize)[source]

Calculate count of pages with adjusted page size and object count

Parameters:
  • objectCount – count of objects

  • pageSize – page size

Returns:

count of pages

Return type:

int

luna_configurator.crutches_on_wheels.cow.utils.functions.workingDirectory(path)[source]

Changes working directory and returns to previous on exit. :param path: temporary working directory