summaryrefslogtreecommitdiffstats
path: root/helpers.py
blob: 18871a21477a50db8b24d34a30391074cecbd0fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import sys, os

logprefix = ''
verbose = 0

def log(s):
    try:
        sys.stdout.flush()
        sys.stderr.write(logprefix + s)
        sys.stderr.flush()
    except IOError:
        # this could happen if stderr gets forcibly disconnected, eg. because
        # our tty closes.  That sucks, but it's no reason to abort the program.
        pass

def debug1(s):
    if verbose >= 1:
        log(s)

def debug2(s):
    if verbose >= 2:
        log(s)

def debug3(s):
    if verbose >= 3:
        log(s)


class Fatal(Exception):
    pass


def list_contains_any(l, sub):
    for i in sub:
        if i in l:
            return True
    return False