moa.utils¶
A set of random utilities used by Moa
-
moa.utils.
deprecated
(func)¶ Decorator function to flag a function as deprecated
Parameters: func – any function
-
moa.utils.
flog
(f)¶ A simple logger - uses the
moa.logger
code to log the calling function. Use as a decorator:@moa.utils.flog def any_function(*args); ...
This is for debugging purposes (obviously)
Parameters: func – Any python function
-
moa.utils.
getCwd
()¶ Do not use os.getcwd() - need to make sure symbolic links do not get dereferenced
hijacked some code from: http://stackoverflow.com/questions/123958/how-to-get-set-logical-directory-path-in-python
-
moa.utils.
getMoaBase
()¶ Return MOABASE - the directory where Moa is installed. This function also sets an environment variable MOABASE
>>> d = getMoaBase() >>> assert(os.path.isdir(d)) >>> assert(os.path.isfile(os.path.join(d, 'README'))) >>> assert(os.path.isdir(os.path.join(d, 'lib')))
Return type: string (path)
-
moa.utils.
getProcessInfo
(pid)¶ Return some info on a process
-
moa.utils.
moaDirOrExit
(job)¶ Check if the job contains a proper Moa job, if not, exit with an error message and a non-zero exit code.
Parameters: job – An instance of moa.job.Job
-
moa.utils.
niceRunTime
(d)¶ Nice representation of the run time d is time duration string
-
moa.utils.
printstack
(func)¶ Decorator function to print stack
Parameters: func – any function
-
moa.utils.
removeIndent
(txt)¶ Removes indentation from a txt - for use by moa.args and moa.api
-
moa.utils.
sendmail
(server, sender, recipient, subject, message)¶ Send an email.
-
moa.utils.
simple_decorator
(decorator)¶ This decorator can be used to turn simple functions into well-behaved decorators, so long as the decorators are fairly simple. If a decorator expects a function and returns a function (no descriptors), and if it doesn’t modify function attributes or docstring, then it is eligible to use this. Simply apply @simple_decorator to your decorator and it will automatically preserve the docstring and function attributes of functions to which it is applied.
Note; I got this code from somehwere, but forgot where exactly. This seems the most likely source:
http://svn.navi.cx/misc/trunk/djblets/djblets/util/decorators.py