Developer Tools

Created on Mon Mar 21 21:25:26 2016

@author: Jonas Eschle “Mayou36”

Contains several useful tools for all kind of programs

raredecay.tools.dev_tool.fill_list_var(to_check, length=0, var=1)[source]

Return a list filled with the specified variable and the desired length.

raredecay.tools.dev_tool.make_list_fill_var(to_check, length=0, var=None)[source]

Returns a list with the objects or a list filled with None.

raredecay.tools.dev_tool.is_in_primitive(test_object, allowed_primitives=None)[source]

Actually “equivalent” to: ‘test_object is allowed_primitives’ resp. ‘test_object in allowed_primitives’ but also works for arrays etc.

There is a problem (designproblem?!) with certain container types when comparing them to a certain value, e.g. None and you create an expression with ‘container is None’ and the container (as it is a container) is not None, then the expression is not defined. The code tries to make elementwise comparison. This method allows to fix this error by doing a REAL comparison. E.g. if the test_object is ANY container and the allowed_primitives is None, it will always be False.

Parameters:
  • test_object (any python-object) – The object you want to test whether it is one of the allowed_primitives.
  • allowed_primitives (object or list(obj, obj, obj,..)) – Has to be testable as ‘is obj’. If test_object is any of the allowed_primitives, True will be returned.
Returns:

out – Returns True if test_object is any of the allowed_primitives, otherwise False.

Return type:

boolean

raredecay.tools.dev_tool.make_logger(module_name, logging_mode='both', log_level_file='debug', log_level_console='debug', overwrite_file=True, log_file_name='AAlast_run', log_file_dir=None)[source]

Return a logger with a console-/filehandler or both.

A useful tool to log the run of the program and debug or control it. With logger.debug(“message”) a loging message is produced consisting of: timestamp(from year to ms) - module_name - logger level - message This can be either written to files, the console or both.

Parameters:
  • module_name (string) – Name of the logger, shown in output. Best choose __name__
  • logging_mode ({'both', 'file', 'console'}) – Which logger handler is used; where the log is printed to.
  • log_level_file ({'debug','info','warning','error','critical'}) – Which level of messages are logged. A lower level (left) always also includes the higher (right) levels, but not the other way around. This level specifies the level for the file log (if enabled).
  • log_level_console ({'debug','info','warning','error','critical'}) – Level for console log (if enabled). See also log_level_file.
  • overwrite_file (boolean) – If enabled, the logfiled gets overwritten at every run. Otherwise, a new logfile is created.
  • log_file_name (string) – The name of the logfile
  • log_file_dir (string) – The directory to save the logfile.
Returns:

out – Logger instance

Return type:

loggerObject

Examples

>>> my_logger = make_logger(__name__)
>>> my_logger.info("hello world")
raredecay.tools.dev_tool.play_sound(duration=0.3, frequency=440)[source]

Play a single frequency (Hertz) for a given time (seconds).