Contents:
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")
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.
>>> 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.
This works similar to os.system() but add some useful optional parameters.
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
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.
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: