Swiss knife module.
$Repo: git://git.sugarlabs.org/alsroot/codelets.git$ $File: src/util.py$ $Data: 2011-11-29$
Make an assertion in runtime.
In comparing with assert, it will all time present in the code. Just a bit of syntax sugar.
Parameters: |
|
---|
Log about exception on low log level.
That might be useful for non-critial exception. Input arguments are the same as for logging.exception function.
Parameters: | args – optional arguments to pass to logging function; the first argument might be a logging.Logger to use instead of using direct logging calls |
---|
Variant of call method with raising exception of errors.
Parameters: |
|
---|
Convenient wrapper around subprocess call.
Note, this function is intended for processes that output finite and not big amount of text.
Parameters: |
|
---|---|
Returns: | None on errors, otherwise str value of stdout |
Remove directory with all its content.
Function will check if owner has permissions for removing directories (it makes sense for 0install implementaion caches).
Parameters: |
|
---|---|
Returns: | None on errors, otherwise str value of stdout |
Efficient version of copying directories.
Function will try to make hard links for copying files at first and will fallback to regular copying overwise.
Parameters: |
|
---|
Atomic new file creation.
Method will create temporaty file in the same directory as the specified one. When file object associated with this temporaty file will be closed, temporaty file will be renamed to the final destination.
Parameters: |
|
---|---|
Returns: | file object |
Return Python call stack frame.
The reason to have this wrapper is that this stack information is a private data and might depend on Python implementaion.
Parameters: | frame_no – number of stack frame starting from caller’s stack position |
---|---|
Returns: | frame object |
Return local time in UTC.
Support testing workflow on multi processes level.
Returns: | datetime.datetime.utcnow() value |
---|
Configuration option.
Option object will be used as command-line argument and configuration file option. All these objects will be automatically collected from sugar_server.env module and from etc module from all services.
Parameters: |
|
---|
Collected by Option.seek() options in original order.
Collected by Option.seek() options by name.
Collected by Option.seek() options by section.
Long command-line argument name.
Get option raw value.
Collect Option objects.
Function will populate Option.unsorted_items, Option.items and Option.sections values. Call this function before any usage of Option objects.
Parameters: |
|
---|
Initilize option usage.
Call this function after invoking Option.seek().
Parameters: |
|
---|
Combine default values with command-line arguments and config files.
Call this function after invoking Option.bind().
Parameters: |
|
---|
Current configuration in human readable form.
Returns: | list of lines |
---|
Service command.
Command is a way to have custom sub-commands in services. All these objects will be automatically collected from etc module from all services.
Parameters: |
|
---|
Collected by Command.seek() commands by name.
Collected by Command.seek() commands by section.
Collect Command objects.
Function will populate Command.items and Command.sections values. Call this function before any usage of Command objects.
Parameters: |
|
---|
Call the command.
Specfied module should contain a function with a name CMD_<command-name>(). All additional Command.call() arguments will be passed as-is to command implementaion function.
Parameters: |
|
---|---|
Returns: | what command implementaion returns |
Auto removed temporary file.
Right after creating TempFilePath object, temporaty file will be created. On TempFilePath object deleting, this file will be removed. The key difference with tempfile.NamedTemporaryFile is that TempFilePath doesn’t keep open file descriptor with removing file right after closing it (though starting form Python 2.6, tempfile.NamedTemporaryFile supports delete argument).