kibitzr package

Subpackages

Submodules

kibitzr.app module

class kibitzr.app.Application[source]

Bases: object

before_start(checkers)[source]

Loads entry points named kibitzr.before_start and call each one with two arguments:

  1. Application instance;

  2. List of configured checkers

static bootstrap()[source]
check_forever(checkers)[source]
connect_signals()[source]
disconnect_signals()[source]
execute_all(checkers)[source]
static execute_conf(conf)[source]
on_backdoor(*args, **kwargs)[source]
on_interrupt(*args, **kwargs)[source]
on_reload_config(*args, **kwargs)[source]
run(once=False, log_level=20, names=None)[source]
run_firefox()[source]
static send_reload()[source]

Sends SIGUSR1 to all processes that execute kibitzr

static setup_logger(log_level=20)[source]
static telegram_chat()[source]

kibitzr.bash module

Kibitzr accepts shell scripts in 3 places:

  • Fetch

  • Transform

  • Notify

Execute code from notifier with transformation result passed via stdin.

Here is a simplistic example of kibitzr.yml file, that uses all three:

checks:
  - name: Shell example
    script: |
      for i in seq 1 3
      do
          echo "Number $i"
      done
    transform:
      - shell: grep 2
    notify:
      - shell: tac

Let’s break it down.

Shell Fetcher

If script’s value is a string, it will be used as shell script. Alternatively script can hold a dictionary of one item. Item’s key can be shell (or python for Python fetcher). If script’s only key is shell, then it’s value will be executed as a Shell script. Under Linux, executor is bash, under Windows - cmd.exe. Script is an arbitrary shell code. It’s output will be passed to transforms. If exit code is not zero, check will be aborted. Shell scripts don’t have access to credentials, but inherit Kibitzr environment.

Shell Transform and Notifier

Transform and notifier are similar to fetcher. Except that they receive content via stdin, and notifier’s stdout is ignored.

Example

Returning to the example, execution will go as follows:

[DEBUG] kibitzr.conf: Loading settings from /home/deminp/kibitzr/tmp/kibitzr.yml
[INFO] kibitzr.fetcher.loader: Fetching 'Shell' using script
[DEBUG] kibitzr.bash: Saving code to '/tmp/tmpTTPSxA.bat'
[DEBUG] kibitzr.bash: Launching script '/tmp/tmpTTPSxA.bat'
[DEBUG] kibitzr.bash: Command exit code: 0
[DEBUG] kibitzr.bash: Command stdout: Number 1
Number 2
Number 3

[DEBUG] kibitzr.bash: Command stderr:
[DEBUG] kibitzr.bash: Saving code to '/tmp/tmpV4Grg8.bat'
[DEBUG] kibitzr.bash: Launching script '/tmp/tmpV4Grg8.bat'
[DEBUG] kibitzr.bash: Command exit code: 0
[DEBUG] kibitzr.bash: Command stdout: Number 2
[DEBUG] kibitzr.bash: Command stderr:
[DEBUG] kibitzr.notifier.factory: Sending report: u'Number 2'
[DEBUG] kibitzr.bash: Saving code to '/tmp/tmpm6sRVx.bat'
[DEBUG] kibitzr.bash: Launching script '/tmp/tmpm6sRVx.bat'
[DEBUG] kibitzr.bash: Command exit code: 0
[DEBUG] kibitzr.bash: Command stdout: 2 rebmuN
[DEBUG] kibitzr.bash: Command stderr:

Fetcher script produced output:

Number 1
Number 2
Number 3

Shell transform filtered lines that contain 2:

Number 2

Notifier echoed reversed line:

2 rebmuN

Notifier’s stdout is ignored, so we don’t see it along Kibitzr output.

And here is what happens when shell script produces error:

$ cat kibitzr.yml
checks:
  - name: Shell
    script: ls /non-existing
    notify:
      - shell: rev

$ kibitzr -l debug once
[DEBUG] kibitzr.conf: Loading settings from /home/deminp/kibitzr/tmp/kibitzr.yml
[INFO] kibitzr.fetcher.loader: Fetching 'Shell' using script
[DEBUG] kibitzr.bash: Saving code to '/tmp/tmpyNakOP.bat'
[DEBUG] kibitzr.bash: Launching script '/tmp/tmpyNakOP.bat'
[ERROR] kibitzr.bash: Command exit code: 2
[ERROR] kibitzr.bash: Command stdout:
[ERROR] kibitzr.bash: Command stderr: ls: cannot access '/non-existing': No such file or directory
[DEBUG] kibitzr.transformer.factory: Notifying on error
[DEBUG] kibitzr.notifier.factory: Sending report: u"ls: cannot access '/non-existing': No such file or directory"
[DEBUG] kibitzr.bash: Saving code to '/tmp/tmpqdZwKI.bat'
[DEBUG] kibitzr.bash: Launching script '/tmp/tmpqdZwKI.bat'
[DEBUG] kibitzr.bash: Command exit code: 0
[DEBUG] kibitzr.bash: Command stdout: yrotcerid ro elif hcus oN :'gnitsixe-non/' ssecca tonnac :sl
[DEBUG] kibitzr.bash: Command stderr:
class kibitzr.bash.BashExecutor(code)[source]

Bases: object

ARGS = []
EXECUTABLE = 'bash'
execute(stdin=None)[source]
static make_report(ok, result)[source]
classmethod run_scipt(name, stdin)[source]
temp_file()[source]

Create temporary file with code and yield its path. Works both on Windows and Linux

class kibitzr.bash.WindowsExecutor(code)[source]

Bases: BashExecutor

ARGS = ['/Q', '/C']
EXECUTABLE = 'cmd.exe'
classmethod run_scipt(name, stdin)[source]
kibitzr.bash.ensure_text(text)[source]
kibitzr.bash.execute_bash(code, stdin=None)[source]

kibitzr.bootstrap module

kibitzr.bootstrap.create_boilerplate()[source]

Create kibitzr.yml and kibitzr-creds.yml in current directory if they do not exist.

kibitzr.checker module

class kibitzr.checker.Checker(conf)[source]

Bases: object

check()[source]
classmethod create_from_settings(checks, names=None)[source]

kibitzr.cli module

kibitzr.cli.load_extensions()[source]

Return list of Kibitzr CLI extensions

kibitzr.cli.merge_extensions(click_group)[source]

Each extension is called with click group for ultimate agility while preserving cli context.

kibitzr.compat module

exception kibitzr.compat.SMTPNotSupportedError[source]

Bases: SMTPException

The command or option is not supported by the SMTP server.

This exception is raised when an attempt is made to run a command or a command with an option which is not supported by the server.

kibitzr.conf module

class kibitzr.conf.CompositeCreds(config_dir)[source]

Bases: object

get(key, default=None)[source]
load_extensions()[source]
reread()[source]
class kibitzr.conf.PlainYamlCreds(config_dir)[source]

Bases: object

CREDENTIALS_FILENAME = 'kibitzr-creds.yml'
open_creds()[source]
reread()[source]

Read and parse credentials file. If something goes wrong, log exception and continue.

class kibitzr.conf.ReloadableSettings(config_dir)[source]

Bases: object

CONFIG_DIRS = ('', '~/.config/kibitzr/', '~/')
CONFIG_FILENAME = 'kibitzr.yml'
RE_PUNCTUATION = re.compile('\\W+')
UNNAMED_PATTERN = 'Unnamed check {0}'
classmethod detect_config_dir()[source]
classmethod instance()[source]
open_conf()[source]
read_conf()[source]

Read and parse configuration file

reread()[source]

Read configuration file and substitute references into checks conf

class kibitzr.conf.SettingsParser[source]

Bases: object

RE_PUNCTUATION = re.compile('\\W+')
UNNAMED_PATTERN = 'Unnamed check {0}'
static expand_schedule(check)[source]
classmethod inject_missing_names(checks)[source]
static inject_notifiers(check, notifiers)[source]
static inject_scenarios(check, scenarios)[source]
parse_checks(conf)[source]

Unpack configuration from human-friendly form to strict check definitions.

static unpack_batches(checks)[source]
static unpack_templates(checks, templates)[source]
classmethod url_to_name(url)[source]
kibitzr.conf.settings()[source]

Returns singleton instance of settings

kibitzr.exceptions module

exception kibitzr.exceptions.ConfigurationError[source]

Bases: RuntimeError

kibitzr.stash module

class kibitzr.stash.LazyStash[source]

Bases: Stash

get(key, default=None)[source]
class kibitzr.stash.Stash[source]

Bases: object

FILENAME = 'stash.db'
open()[source]
classmethod print_content()[source]
read()[source]
write(data)[source]

kibitzr.storage module

class kibitzr.storage.ChangesReporter(git, subject, style=None)[source]

Bases: object

default()[source]

Return last changes in truncated unified diff format

new()[source]
verbose()[source]

Return changes in human-friendly format #14

word()[source]

Return last changes with word diff

class kibitzr.storage.PageHistory(conf, storage_dir=None, style=None)[source]

Bases: object

Single file changes history using git.

STORAGE_DIR = 'pages'
static clean()[source]

Remove storage dir (delete all git repos)

commit()[source]

git commit and return whether there were changes

ensure_repo_exists()[source]

Create git repo if one does not exist yet

report_changes(content)[source]

Save contents and commit it to git.

  1. Write changes in file.

  2. Commit changes in git.

  3. If something changed, return tuple(True, changes).

  4. If nothing changed, return tuple(False, None).

If style is “verbose”, return changes in human-friendly format, else use unified diff

write(content)[source]

Save content on disk

kibitzr.storage.ensure_unicode(text)[source]
kibitzr.storage.report_changes(conf, content)[source]

kibitzr.timeline module

class kibitzr.timeline.Timeline(scheduler=None)[source]

Bases: object

RE_TIME = re.compile('\\d?\\d:\\d\\d')
classmethod parse_check(check)[source]
schedule_checks(checkers)[source]
class kibitzr.timeline.TimelineRule(interval, unit, at)

Bases: tuple

at

Alias for field number 2

interval

Alias for field number 0

unit

Alias for field number 1

kibitzr.timeline.parse_check(check)[source]
kibitzr.timeline.run_pending()[source]
kibitzr.timeline.schedule_checks(checkers)[source]

kibitzr.utils module

kibitzr.utils.normalize_filename(text)[source]

ORIGIN: https://github.com/django/django/blob/master/django/utils/text.py

Returns the given string converted to a string that can be used for a clean filename. Specifically, leading and trailing spaces are removed; other spaces are converted to underscores; and anything that is not a unicode alphanumeric, dash, underscore, or dot, is removed. >>> get_valid_filename(“john’s portrait in 2004.jpg”) ‘johns_portrait_in_2004.jpg’

Module contents