Hash :
4b5f32a5
Author :
Date :
2012-10-23T13:26:44
Use python2 rather than python python may refer to either python2 or python3 so rather by explicit by using python2. See PEP 394 - http://www.python.org/dev/peps/pep-0394/ for more details.
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#!/usr/bin/python2
def get(old,wc,rc):
if ('xxx' in (rc, wc)):
return "0",-1
if ('add' in (rc, wc)):
events = []
if rc == 'add' or (rc != 'del' and 'r' in old):
events.append("EPOLLIN")
if wc == 'add' or (wc != 'del' and 'w' in old):
events.append("EPOLLOUT")
if old == "0":
op = "EPOLL_CTL_ADD"
else:
op = "EPOLL_CTL_MOD"
return "|".join(events), op
if ('del' in (rc, wc)):
op = "EPOLL_CTL_DEL"
if rc == 'del':
if wc == 'del':
events = "EPOLLIN|EPOLLOUT"
elif 'w' in old:
events = "EPOLLOUT"
op = "EPOLL_CTL_MOD"
else:
events = "EPOLLIN"
else:
assert wc == 'del'
if 'r' in old:
events = "EPOLLIN"
op = "EPOLL_CTL_MOD"
else:
events = "EPOLLOUT"
return events, op
return 0, 0
def fmt(op, ev, old, wc, rc):
entry = "{ %s, %s },"%(op, ev)
assert len(entry)<=36
sp = " "*(36-len(entry))
print "\t%s%s/* old=%2s, write:%3s, read:%3s */" % (
entry, sp, old, wc, rc)
for old in ('0','r','w','rw'):
for wc in ('0', 'add', 'del', 'xxx'):
for rc in ('0', 'add', 'del', 'xxx'):
op,ev = get(old,wc,rc)
fmt(op, ev, old, wc, rc)