Simple Configuration Information API
Configuration files are kept in ~/.config/ (or can be configured through the module’s global base_dir). Configuration parameters are treated as “read-only”. Configuration file format can either be .json or .yaml , the priority being given to .json.
Configuration file names can either be:
The options are listed in order of priority.
Sipi - Simple OS functions
Checks if the current user (i.e. the script) can delete the given path Must check both user & group level permissions
FOR THIS TEST, NEED TO CREATE A DIRECTORY /tmp/_test_root_sipi THROUGH ROOT
>>> p="/tmp/_test_sipi"
>>> rm(p)
('ok', '/tmp/_test_sipi')
>>> touch(p)
('ok', '/tmp/_test_sipi')
>>> can_write(p)
('ok', True)
>>> rm(p)
('ok', '/tmp/_test_sipi')
>>> can_write("/tmp/_test_root_sipi/some_file")
('ok', False)
Simple “get file contents”
>>> rm('/tmp/JustTouching')
('ok', '/tmp/JustTouching')
>>> touch("/tmp/JustTouching")
('ok', '/tmp/JustTouching')
>>> file_contents("/tmp/JustTouching")
('ok', '')
>>> rm('/tmp/JustTouching')
('ok', '/tmp/JustTouching')
>>> file_contents("/tmp/JustTouching")
('error', None)
os.walk generator with an optional limit on the number of files returned
Silently (i.e. no exception thrown) makes a directory structure if possible
>>> mkdir_p("/tmp/JustATestDir")
('ok', '/tmp/JustATestDir')
>>> mkdir_p("/tmp/JustATestDir")
('ok', '/tmp/JustATestDir')
>>> rmdir("/tmp/JustATestDir")
('ok', '/tmp/JustATestDir')
Best effort “write contents to file”
>>> quick_write("/tmp/QuickWriteTest", "{'param': 'value'}")
('ok', ...)
>>> file_contents("/tmp/QuickWriteTest")
('ok', "{'param': 'value'}")
>>> rm('/tmp/QuickWriteTest')
('ok', ...)
>>> remove_common_prefix("/tmp", "/tmp/some_dir/some_file.ext")
('ok', '/some_dir/some_file.ext')
Resolves a path with user and environment variables
>>> resolve_path("~/.config")
'/home/.../.config'
Silently (i.e. no exception thrown) removes a path if possible
>>> rm("/tmp/NotAFile") ## no need to complain if there is no file
('ok', '/tmp/NotAFile')
Created on 2012-01-27 @author: jldupont
Simple Command Line tools
Process input files
line_proc must be a callable which takes 1 tuple as input: (ctx, (code, data))
The parameter ctx contains contextual information:
Codes sent to line_proc:
The parameter parser_args is a list of tuples (pargs, kargs) for parser.add_argument of the standard library module argparse.
The parameter desc is a string description of the command line processor.
Simple Flow tools
Build a pipeline from the list of blocks
The first element of the list must correspond to the first block of the pipeline.
Each block is a tuple (handler_function, name). The handler_function must accept 1 tuple parameter of the following signature: (next_block, (context, msg)).