26 return "killed by signal %d" % val, val |
28 return "killed by signal %d" % val, val |
27 elif os.WIFSTOPPED(code): |
29 elif os.WIFSTOPPED(code): |
28 val = os.WSTOPSIG(code) |
30 val = os.WSTOPSIG(code) |
29 return "stopped by signal %d" % val, val |
31 return "stopped by signal %d" % val, val |
30 raise ValueError("invalid exit code") |
32 raise ValueError("invalid exit code") |
|
33 |
|
34 def always(fn): return True |
|
35 def never(fn): return False |
|
36 |
|
37 def globre(pat, head = '^', tail = '$'): |
|
38 "convert a glob pattern into a regexp" |
|
39 i, n = 0, len(pat) |
|
40 res = '' |
|
41 group = False |
|
42 def peek(): return i < n and pat[i] |
|
43 while i < n: |
|
44 c = pat[i] |
|
45 i = i+1 |
|
46 if c == '*': |
|
47 if peek() == '*': |
|
48 i += 1 |
|
49 res += '.*' |
|
50 else: |
|
51 res += '[^/]*' |
|
52 elif c == '?': |
|
53 res += '.' |
|
54 elif c == '[': |
|
55 j = i |
|
56 if j < n and pat[j] in '!]': |
|
57 j += 1 |
|
58 while j < n and pat[j] != ']': |
|
59 j += 1 |
|
60 if j >= n: |
|
61 res += '\\[' |
|
62 else: |
|
63 stuff = pat[i:j].replace('\\','\\\\') |
|
64 i = j + 1 |
|
65 if stuff[0] == '!': |
|
66 stuff = '^' + stuff[1:] |
|
67 elif stuff[0] == '^': |
|
68 stuff = '\\' + stuff |
|
69 res = '%s[%s]' % (res, stuff) |
|
70 elif c == '{': |
|
71 group = True |
|
72 res += '(?:' |
|
73 elif c == '}' and group: |
|
74 res += ')' |
|
75 group = False |
|
76 elif c == ',' and group: |
|
77 res += '|' |
|
78 else: |
|
79 res += re.escape(c) |
|
80 return head + res + tail |
31 |
81 |
32 def system(cmd, errprefix=None): |
82 def system(cmd, errprefix=None): |
33 """execute a shell command that must succeed""" |
83 """execute a shell command that must succeed""" |
34 rc = os.system(cmd) |
84 rc = os.system(cmd) |
35 if rc: |
85 if rc: |