ksconf.util package


ksconf.util.compare module

ksconf.util.compare.cmp_sets(a, b)

Result tuples in format (a-only, common, b-only)

ksconf.util.compare.file_compare(fn1, fn2)
ksconf.util.compare.fileobj_compare(f1, f2)

ksconf.util.completers module

ksconf.util.completers.DirectoriesCompleter(*args, **kwargs)
ksconf.util.completers.FilesCompleter(*args, **kwargs)
ksconf.util.completers.autocomplete(*args, **kwargs)

ksconf.util.file module

class ksconf.util.file.ReluctantWriter(path, *args, **kwargs)

Bases: object

Context manager to intelligently handle updates to an existing file. New content is written to a temp file, and then compared to the current file’s content. The file file will be overwritten only if the contents changed.


Ensure that the directory exists

ksconf.util.file.expand_glob_list(iterable, do_sort=False)
ksconf.util.file.file_fingerprint(path, compare_to=None)
ksconf.util.file.file_hash(path, algorithm='sha256')
ksconf.util.file.match_bwlist(value, bwlist, escape=True)
ksconf.util.file.relwalk(top, topdown=True, onerror=None, followlinks=False)

Relative path walker Like os.walk() except that it doesn’t include the “top” prefix in the resulting ‘dirpath’.

ksconf.util.file.smart_copy(src, dest)

Copy (overwrite) file only if the contents have changed.

ksconf.util.rest module

ksconf.util.rest.build_rest_namespace(base, owner=None, app=None)
ksconf.util.rest.build_rest_url(base, service, owner=None, app=None)

ksconf.util.terminal module

class ksconf.util.terminal.TermColor(stream)

Bases: object

Simple color setting helper class that’s a context manager wrapper around a stream. This ensure that the color is always reset at the end of a session.

ksconf.util.terminal.tty_color(stream, *codes)

Module contents


If the ‘KSCONF_DEBUG’ environmental variable is set, then show a stack trace.

ksconf.util.handle_py3_kw_only_args(kw, *default_args)

Python 2.7 workaround for Python 3 style kw arg after ‘*’ arg.

Example Python 3 syntax:

def f(arg, *args, a=True, b=False):

Example Python 2 syntax with this helper function:

def f(arg, *args, **kw_only):
    a, b = handle_py3_kw_only_args(kw_only, ("a", True), ("b", False))
  • kw (dict) – keyword arguments provided to the calling function. Be aware that this dict will be empty after this function is done.
  • default_args (tuple) – pairs of keyword argument to the caller function in argument (arg_name, default_value) order.

TypeError – if kw contains any keys not defined in args This mirrors Python’s native behavior when an unexpected argument is passed to a function.