[docs]classOneTickLib(object):""" Singleton class for otq.OneTickLib to initialize it once usage: OneTickLib() - returns existing otq.OneTickLib if it is intialized or otq.OneTickLib(None) if it is not OneTickLib(*args) - returns pyomf.OneTickLib(*args) """__instance=None__args=Nonedef__init__(self,*args,log_file=None):ifnotOneTickLib.__instance:ifnotargs:args=(None,)OneTickLib.__instance=otq.OneTickLib(*args)iflog_file:self.set_log_file(log_file)OneTickLib.__args=argselifargs!=OneTickLib.__argsandargs:raiseException("OneTickLib was already initialized with different ""parameters: Was: {} Now: {}".format(OneTickLib.__args,args))def__eq__(self,otl):returnself.__dict__==otl.__dict__def__ne__(self,otl):returnself.__dict__!=otl.__dict__def__str__(self):return"Instance: {}".format(self.__instance.get_one_tick_lib())
[docs]defcleanup(self):""" Destroy otq.OneTickLib instance and reset singleton class """delOneTickLib.__instancegc.collect()OneTickLib.__instance=NoneOneTickLib.__args=None
[docs]defset_log_file(self,log_file):""" Set log file for given instance of OneTickLib :param log_file: path to log file """OneTickLib.__instance.set_log_file(str(log_file))ifhasattr(OneTickLib.__instance,'close_log_file_in_destructor'):# we need to check it to prevent failing CI on the builds that do not have this featureOneTickLib.__instance.close_log_file_in_destructor()
[docs]defset_logging_level(self,lvl:LoggingLevel):""" Logging level can be specified by using LoggingLevel Enum class :param lvl: available values are LoggingLevel.MIN, LoggingLevel.LOW, LoggingLevel.MEDIUM or LoggingLevel.MAX :return: """OneTickLib.__instance.set_logging_level(lvl)
[docs]defset_authentication_token(self,auth_token:str):""" Set authentication token for given instance of OneTickLib :param auth_token: authentication token """OneTickLib.__instance.set_authentication_token(auth_token)
[docs]@staticmethoddefoverride_config_value(config_parameter_name:str,config_parameter_value):""" Override config value of OneTickConfig :param config_parameter_name: param to override (could be both set or not set in OneTickConfig) :param config_parameter_value: new value of the param """ifOneTickLib.__instance:raiseException('This method should be called before OneTickLib object is constructed to have affect.')pyomd.OneTickLib.override_config_value(config_parameter_name,config_parameter_value)