update_symlink(target, link_name) does the equivalent of ln -sf, i.e.
force replacement of link_name with a new sysmlink, if it existed
before the call.
Signed-off-by: Jan Lindemann <jan@janware.com>
An application based on Cmds will now try to read StringTree
formatted config data from a file $HOME/.<name>rc, and make the data
available via the newly added conf_value() method.
Signed-off-by: Jan Lindemann <jan@janware.com>
log.add_log_file(path) allows to pass a file path log messages will
be written into. Special characters (e.g. console color codes) will
be removed from the messages.
Signed-off-by: Jan Lindemann <jan@janware.com>
The Options constructor takes an options string, parses it and
makes the options available via __getitem__().
Signed-off-by: Jan Lindemann <jan@janware.com>
Do "from . import log" instead of "from jwutils import log". It works
and looks cleaner than a module referencing itself. Not entirely sure
if that's the way to go, I must admit.
Signed-off-by: Jan Lindemann <jan@janware.com>
Add class ShellCmd, an easy API to run shell commands as
async subprocesses, capture their exit status, and have them log to slog().
Signed-off-by: Jan Lindemann <jan@janware.com>
Commit 72d56d9 (Move type argument into config) swapped the order of
arguments in Auth.load(), but the ctor of ldap.Auth didn't follow the
change, fix that.
Signed-off-by: Jan Lindemann <jan@janware.com>
Auth.load() takes a "tp" argument, specifying the Auth module name to
load. In case of jw-devops, this is part of the configuration, which
is also passed as an argument. Make taking 'type' from the config the
default. Note that this changes the prototype.
Signed-off-by: Jan Lindemann <jan@janware.com>
jw-client-devops configures its databases with a set of config keys
which are identical - except for the 'bind_pw' key, which is called
'password'. Allow that, too.
Signed-off-by: Jan Lindemann <jan@janware.com>
ldap.Auth lost a lot of code when jwutils.ldap was introduced, and
rightfully so, because jwutils.ldap contains most of it. OTOH, it was
used wrongly, fix that.
Signed-off-by: Jan Lindemann <jan@janware.com>
MapAttr2Shape is a class which allows processing GraphML files, such
that nodes get added shape attributes understood by the yEd editor,
based on the values of other node attributes. This allows to
programmatically visualize node attributes.
Signed-off-by: Jan Lindemann <jan@janware.com>
jwutils.Bunch is a simple wrapper around a dictionary, which allows
member-type access to to dictionary data.
Signed-off-by: Jan Lindemann <jan@janware.com>
argcomplete takes the arguments added to argparse, and builds bash
completion with it. Add it to all Cmds based executables.
Signed-off-by: Jan Lindemann <jan@janware.com>
- Add coding statement
- Import all modules in one line where possible
- Order: __future__, typing, plain imports, from imports,
janware modules
Signed-off-by: Jan Lindemann <jan@janware.com>
ArgsContainer.specified_args is a list of arguments that were
explicitly specified, i.e. not defaults, in the order they were
specified in.
Signed-off-by: Jan Lindemann <jan@janware.com>
WSGI doesn't like sys.exit() being called, so avoid it. Two cases
need to be taken into consideration:
1. No exception thrown by self.args.func()
The variable exit_status is zero, we can check that and _not_
call sys.exit()
2. Exception thrown by self.args.func()
In that case, the exception should be raised, to be caught by
WSGI / ASGI whatever to do what they want with it. The code
calling sys.exit() is never reached. Hence, we need to add
--backtrace to the invocation options.
Signed-off-by: Jan Lindemann <jan@janware.com>
cast.from_env() takes an environment variable name instead of the
string as the first argument and does the obvious thing. It also
takes a default and saves the conversion in case the environment
variable doesn't exist.
Signed-off-by: Jan Lindemann <jan@janware.com>
"A string which contains 'single quotes'" or 'a string containing
"double quotes"' is not tokenized as quoted. Fix that.
Signed-off-by: Jan Lindemann <jan@janware.com>
<W> jw-client-devops-web.py [ 29] Exiting jw-client-devops-web.py
Exception ignored in: <function App.__del__ at 0x7f3ddeb8f560>
Traceback (most recent call last):
File "/home/jan/local/src/jw.dev/proj/jw-client-devops-web/src/python/jw/devops/client/web/cmds/App.py", line 43, in __del__
File "/home/jan/local/src/jw.dev/proj/jw-python/tools/python/jwutils/log.py", line 167, in slog
File "/home/jan/local/src/jw.dev/proj/jw-python/tools/python/jwutils/log.py", line 126, in get_caller_pos
AttributeError: 'NoneType' object has no attribute '__name__'
Signed-off-by: Jan Lindemann <jan@janware.com>
Add an option which makes the program write profiling statistics in pstats
format to a specified file.
Visualize e.g. with:
gprof2dot -f pstats <filename> -o <dotfile>
dot -Tpng | display <dotfile>
Signed-off-by: Jan Lindemann <jan@janware.com>
add_argument() at the face of it looks much like
ArgumentParser.add_argument(), but is a function, not a class method.
It takes the ArgsContainer|ArgParser instance as first argument, then
decides what type it is, and proceeds to use this knowledge to decide
whether or not the argument to be added already has a definition.
Signed-off-by: Jan Lindemann <jan@janware.com>
Add functions log.(add|rm)_capture_stream(). The functions are meant
to capture everything passed to syslog into the stream objects
installed by it. Not sure about future semantics changes:
add_capture_stream() takes a currently unused flags argument, and it
suppresses everything else logged until the stream is removed again.
Signed-off-by: Jan Lindemann <jan@janware.com>
Make log.set_level() return the flags that were set before setting
the flags passed as argument.
Support None as flags argument, in which case it doesn't change
anything and only returns the currently set flags.
Signed-off-by: Jan Lindemann <jan@janware.com>
If module is present in the log flags string, the module is prepended
to each log message. The length of the module prefix can be set via
the new set_module_name_length() function.
Signed-off-by: Jan Lindemann <jan@janware.com>
Wrap all execution in try-block, don't raise in except block unless
--backtrace is passed to the command line.
Signed-off-by: Jan Lindemann <jan@janware.com>