Welcome to tendo’s documentation!



class tendo.singleton.SingleInstance[source]

If you want to prevent your script from running in parallel just instantiate SingleInstance() class. If is there another instance already running it will exist the application with the message “Another instance is already running, quitting.”, returning -1 error code.

>>> import tendo
>>> me = SingleInstance()

This option is very useful if you have scripts executed by crontab at small amounts of time.

Remember that this works by creating a lock file with a filename based on the full path to the script file.


Colorer does enable colored logging messages by using ANSI escape sequences.

Under Windows, where the escapes are not supported it does use the Windows API.

The colored output is generated only when the console is a terminal supporting it, so if you redirect the output to a log file you will not see the escape codes in the file.

>>> import colorer, logging
>>> logging.error("red line")
>>> logging.warn("yellow line")
>>> logging.info("gray line")
>>> logging.debug("magenta line")


tendo.unicode.open(filename, mode=u'r', bufsize=-1, fallback_encoding=u'utf_8')[source]

This replaces Python original open() function with an improved version that is Unicode aware.

The new open() does change behaviour only for text files, not binary.

  • mode is by default ‘r’ if not specified and text mode
  • negative bufsize makes it use the default system one (same as not specified)
>>> import tendo.unicode
>>> f = open("file-with-unicode-content.txt")
>>> content = f.read() # Unicode content of the file, without BOM

Shortly by importing unicode, you will repair code that previously was broken when the input files were Unicode.

This will not change the behavior of code that reads the files as binary, it has an effect on text file operations.

Files with BOM will be read properly as Unicode and the BOM will not be part of the text.

If you do not specify the fallback_encoding, files without BOM will be read as UTF-8 instead of ascii.


tendo.tee.system(cmd, cwd=None, logger=None, stdout=None, log_command=<object object at 0x10515e6c0>, timing=<object object at 0x10515e6c0>)[source]

This works similar to os.system() but add some useful optional parameters.

  • cmd - command to be executed
  • cwd - optional working directory to be set before running cmd
  • logger - None, ‘log.txt’, handle or a function like print or logging.Logger.warning()

Returns the exit code reported by the execution of the command, 0 means success.

>>> import os, logging
>>> tee.system("echo test", logger=logging.error)  # output using python logging
>>> tee.system("echo test", logger="log.txt")  # output to a file
>>> f = open("log.txt", "w")
>>> tee.system("echo test", logger=f) # output to a filehandle
>>> tee.system("echo test", logger=print) # use the print() function for output
tendo.tee.system2(cmd, cwd=None, logger=<object object at 0x10515e6c0>, stdout=<object object at 0x10515e6c0>, log_command=<object object at 0x10515e6c0>, timing=<object object at 0x10515e6c0>)[source]

Works exactly like system() but it returns both the exit code and the output as a list of lines.

This method returns a tuple: (return_code, output_lines_as_list). The return code of 0 means success.


tendo.execfile2.execfile2(filename, _globals={}, _locals={}, cmd=None, quiet=False)[source]

Execute a Python script using execfile(). In addition to Python execfile() this method can temporary change the argv params.

This enables you to call an external python script that requires command line arguments without leaving current python interpretor.

cmd can be a string with command line arguments or a list or arguments

The return value is a numeric exit code similar to the one used for command line tools:

  • 0 - if succesfull; this applies if script receives SystemExit with error code 0
  • 1 - if SystemExit does not contain an error code or if other Exception is received.
  • x - the SystemExit error code (if present)

Indices and tables

Table Of Contents

This Page