nwo
stringlengths 10
28
| sha
stringlengths 40
40
| path
stringlengths 11
97
| identifier
stringlengths 1
64
| parameters
stringlengths 2
2.24k
| return_statement
stringlengths 0
2.17k
| docstring
stringlengths 0
5.45k
| docstring_summary
stringlengths 0
3.83k
| func_begin
int64 1
13.4k
| func_end
int64 2
13.4k
| function
stringlengths 28
56.4k
| url
stringlengths 106
209
| project
int64 1
48
| executed_lines
list | executed_lines_pc
float64 0
153
| missing_lines
list | missing_lines_pc
float64 0
100
| covered
bool 2
classes | filecoverage
float64 2.53
100
| function_lines
int64 2
1.46k
| mccabe
int64 1
253
| coverage
float64 0
100
| docstring_lines
int64 0
112
| function_nodoc
stringlengths 9
56.4k
| id
int64 0
29.8k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
timeslice
|
(period, when)
|
return int(when - (when % period))
| 319 | 320 |
def timeslice(period, when):
return int(when - (when % period))
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L319-L320
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 99.086758 | 2 | 1 | 100 | 0 |
def timeslice(period, when):
return int(when - (when % period))
| 4,308 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
profile
|
(cmd, globals, locals, sort_order, callers)
| 323 | 342 |
def profile(cmd, globals, locals, sort_order, callers): # pragma: no cover
try:
import cProfile as profile
except ImportError:
import profile
import pstats
import tempfile
fd, fn = tempfile.mkstemp()
try:
profile.runctx(cmd, globals, locals, fn)
stats = pstats.Stats(fn)
stats.strip_dirs()
# calls,time,cumulative and cumulative,calls,time are useful
stats.sort_stats(*sort_order or ('cumulative', 'calls', 'time'))
if callers:
stats.print_callers(.3)
else:
stats.print_stats(.3)
finally:
os.remove(fn)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L323-L342
| 6 |
[] | 0 |
[] | 0 | false | 99.086758 | 20 | 4 | 100 | 0 |
def profile(cmd, globals, locals, sort_order, callers): # pragma: no cover
try:
import cProfile as profile
except ImportError:
import profile
import pstats
import tempfile
fd, fn = tempfile.mkstemp()
try:
profile.runctx(cmd, globals, locals, fn)
stats = pstats.Stats(fn)
stats.strip_dirs()
# calls,time,cumulative and cumulative,calls,time are useful
stats.sort_stats(*sort_order or ('cumulative', 'calls', 'time'))
if callers:
stats.print_callers(.3)
else:
stats.print_stats(.3)
finally:
os.remove(fn)
| 4,309 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
main
|
(args=None, test=False)
| 346 | 364 |
def main(args=None, test=False):
assert os.name == "posix", "This code makes Unix-specific assumptions"
# if we hup, restart by making a new Supervisor()
first = True
while 1:
options = ServerOptions()
options.realize(args, doc=__doc__)
options.first = first
options.test = test
if options.profile_options:
sort_order, callers = options.profile_options
profile('go(options)', globals(), locals(), sort_order, callers)
else:
go(options)
options.close_httpservers()
options.close_logger()
first = False
if test or (options.mood < SupervisorStates.RESTARTING):
break
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L346-L364
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
13,
14,
15,
16,
17,
18
] | 94.736842 |
[] | 0 | false | 99.086758 | 19 | 6 | 100 | 0 |
def main(args=None, test=False):
assert os.name == "posix", "This code makes Unix-specific assumptions"
# if we hup, restart by making a new Supervisor()
first = True
while 1:
options = ServerOptions()
options.realize(args, doc=__doc__)
options.first = first
options.test = test
if options.profile_options:
sort_order, callers = options.profile_options
profile('go(options)', globals(), locals(), sort_order, callers)
else:
go(options)
options.close_httpservers()
options.close_logger()
first = False
if test or (options.mood < SupervisorStates.RESTARTING):
break
| 4,310 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
go
|
(options)
| 366 | 371 |
def go(options): # pragma: no cover
d = Supervisor(options)
try:
d.main()
except asyncore.ExitNow:
pass
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L366-L371
| 6 |
[] | 0 |
[] | 0 | false | 99.086758 | 6 | 2 | 100 | 0 |
def go(options): # pragma: no cover
d = Supervisor(options)
try:
d.main()
except asyncore.ExitNow:
pass
| 4,311 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
Supervisor.__init__
|
(self, options)
| 54 | 57 |
def __init__(self, options):
self.options = options
self.process_groups = {}
self.ticks = {}
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L54-L57
| 6 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 99.086758 | 4 | 1 | 100 | 0 |
def __init__(self, options):
self.options = options
self.process_groups = {}
self.ticks = {}
| 4,312 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
Supervisor.main
|
(self)
| 59 | 78 |
def main(self):
if not self.options.first:
# prevent crash on libdispatch-based systems, at least for the
# first request
self.options.cleanup_fds()
self.options.set_uid_or_exit()
if self.options.first:
self.options.set_rlimits_or_exit()
# this sets the options.logger object
# delay logger instantiation until after setuid
self.options.make_logger()
if not self.options.nocleanup:
# clean up old automatic logs
self.options.clear_autochildlogdir()
self.run()
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L59-L78
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19
] | 100 |
[] | 0 | true | 99.086758 | 20 | 4 | 100 | 0 |
def main(self):
if not self.options.first:
# prevent crash on libdispatch-based systems, at least for the
# first request
self.options.cleanup_fds()
self.options.set_uid_or_exit()
if self.options.first:
self.options.set_rlimits_or_exit()
# this sets the options.logger object
# delay logger instantiation until after setuid
self.options.make_logger()
if not self.options.nocleanup:
# clean up old automatic logs
self.options.clear_autochildlogdir()
self.run()
| 4,313 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
Supervisor.run
|
(self)
| 80 | 96 |
def run(self):
self.process_groups = {} # clear
self.stop_groups = None # clear
events.clear()
try:
for config in self.options.process_group_configs:
self.add_process_group(config)
self.options.openhttpservers(self)
self.options.setsignals()
if (not self.options.nodaemon) and self.options.first:
self.options.daemonize()
# writing pid file needs to come *after* daemonizing or pid
# will be wrong
self.options.write_pidfile()
self.runforever()
finally:
self.options.cleanup()
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L80-L96
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
16
] | 94.117647 |
[] | 0 | false | 99.086758 | 17 | 4 | 100 | 0 |
def run(self):
self.process_groups = {} # clear
self.stop_groups = None # clear
events.clear()
try:
for config in self.options.process_group_configs:
self.add_process_group(config)
self.options.openhttpservers(self)
self.options.setsignals()
if (not self.options.nodaemon) and self.options.first:
self.options.daemonize()
# writing pid file needs to come *after* daemonizing or pid
# will be wrong
self.options.write_pidfile()
self.runforever()
finally:
self.options.cleanup()
| 4,314 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
Supervisor.diff_to_active
|
(self)
|
return added, changed, removed
| 98 | 111 |
def diff_to_active(self):
new = self.options.process_group_configs
cur = [group.config for group in self.process_groups.values()]
curdict = dict(zip([cfg.name for cfg in cur], cur))
newdict = dict(zip([cfg.name for cfg in new], new))
added = [cand for cand in new if cand.name not in curdict]
removed = [cand for cand in cur if cand.name not in newdict]
changed = [cand for cand in new
if cand != curdict.get(cand.name, cand)]
return added, changed, removed
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L98-L111
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
12,
13
] | 92.857143 |
[] | 0 | false | 99.086758 | 14 | 7 | 100 | 0 |
def diff_to_active(self):
new = self.options.process_group_configs
cur = [group.config for group in self.process_groups.values()]
curdict = dict(zip([cfg.name for cfg in cur], cur))
newdict = dict(zip([cfg.name for cfg in new], new))
added = [cand for cand in new if cand.name not in curdict]
removed = [cand for cand in cur if cand.name not in newdict]
changed = [cand for cand in new
if cand != curdict.get(cand.name, cand)]
return added, changed, removed
| 4,315 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
Supervisor.add_process_group
|
(self, config)
|
return False
| 113 | 120 |
def add_process_group(self, config):
name = config.name
if name not in self.process_groups:
config.after_setuid()
self.process_groups[name] = config.make_group()
events.notify(events.ProcessGroupAddedEvent(name))
return True
return False
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L113-L120
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7
] | 100 |
[] | 0 | true | 99.086758 | 8 | 2 | 100 | 0 |
def add_process_group(self, config):
name = config.name
if name not in self.process_groups:
config.after_setuid()
self.process_groups[name] = config.make_group()
events.notify(events.ProcessGroupAddedEvent(name))
return True
return False
| 4,316 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
Supervisor.remove_process_group
|
(self, name)
|
return True
| 122 | 128 |
def remove_process_group(self, name):
if self.process_groups[name].get_unstopped_processes():
return False
self.process_groups[name].before_remove()
del self.process_groups[name]
events.notify(events.ProcessGroupRemovedEvent(name))
return True
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L122-L128
| 6 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 99.086758 | 7 | 2 | 100 | 0 |
def remove_process_group(self, name):
if self.process_groups[name].get_unstopped_processes():
return False
self.process_groups[name].before_remove()
del self.process_groups[name]
events.notify(events.ProcessGroupRemovedEvent(name))
return True
| 4,317 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
Supervisor.get_process_map
|
(self)
|
return process_map
| 130 | 134 |
def get_process_map(self):
process_map = {}
for group in self.process_groups.values():
process_map.update(group.get_dispatchers())
return process_map
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L130-L134
| 6 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 99.086758 | 5 | 2 | 100 | 0 |
def get_process_map(self):
process_map = {}
for group in self.process_groups.values():
process_map.update(group.get_dispatchers())
return process_map
| 4,318 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
Supervisor.shutdown_report
|
(self)
|
return unstopped
| 136 | 154 |
def shutdown_report(self):
unstopped = []
for group in self.process_groups.values():
unstopped.extend(group.get_unstopped_processes())
if unstopped:
# throttle 'waiting for x to die' reports
now = time.time()
if now > (self.lastshutdownreport + 3): # every 3 secs
names = [ as_string(p.config.name) for p in unstopped ]
namestr = ', '.join(names)
self.options.logger.info('waiting for %s to die' % namestr)
self.lastshutdownreport = now
for proc in unstopped:
state = getProcessStateDescription(proc.get_state())
self.options.logger.blather(
'%s state: %s' % (proc.config.name, state))
return unstopped
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L136-L154
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
18
] | 94.736842 |
[] | 0 | false | 99.086758 | 19 | 6 | 100 | 0 |
def shutdown_report(self):
unstopped = []
for group in self.process_groups.values():
unstopped.extend(group.get_unstopped_processes())
if unstopped:
# throttle 'waiting for x to die' reports
now = time.time()
if now > (self.lastshutdownreport + 3): # every 3 secs
names = [ as_string(p.config.name) for p in unstopped ]
namestr = ', '.join(names)
self.options.logger.info('waiting for %s to die' % namestr)
self.lastshutdownreport = now
for proc in unstopped:
state = getProcessStateDescription(proc.get_state())
self.options.logger.blather(
'%s state: %s' % (proc.config.name, state))
return unstopped
| 4,319 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
Supervisor.ordered_stop_groups_phase_1
|
(self)
| 156 | 159 |
def ordered_stop_groups_phase_1(self):
if self.stop_groups:
# stop the last group (the one with the "highest" priority)
self.stop_groups[-1].stop_all()
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L156-L159
| 6 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 99.086758 | 4 | 2 | 100 | 0 |
def ordered_stop_groups_phase_1(self):
if self.stop_groups:
# stop the last group (the one with the "highest" priority)
self.stop_groups[-1].stop_all()
| 4,320 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
Supervisor.ordered_stop_groups_phase_2
|
(self)
| 161 | 172 |
def ordered_stop_groups_phase_2(self):
# after phase 1 we've transitioned and reaped, let's see if we
# can remove the group we stopped from the stop_groups queue.
if self.stop_groups:
# pop the last group (the one with the "highest" priority)
group = self.stop_groups.pop()
if group.get_unstopped_processes():
# if any processes in the group aren't yet in a
# stopped state, we're not yet done shutting this
# group down, so push it back on to the end of the
# stop group queue
self.stop_groups.append(group)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L161-L172
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11
] | 100 |
[] | 0 | true | 99.086758 | 12 | 3 | 100 | 0 |
def ordered_stop_groups_phase_2(self):
# after phase 1 we've transitioned and reaped, let's see if we
# can remove the group we stopped from the stop_groups queue.
if self.stop_groups:
# pop the last group (the one with the "highest" priority)
group = self.stop_groups.pop()
if group.get_unstopped_processes():
# if any processes in the group aren't yet in a
# stopped state, we're not yet done shutting this
# group down, so push it back on to the end of the
# stop group queue
self.stop_groups.append(group)
| 4,321 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
Supervisor.runforever
|
(self)
| 174 | 252 |
def runforever(self):
events.notify(events.SupervisorRunningEvent())
timeout = 1 # this cannot be fewer than the smallest TickEvent (5)
socket_map = self.options.get_socket_map()
while 1:
combined_map = {}
combined_map.update(socket_map)
combined_map.update(self.get_process_map())
pgroups = list(self.process_groups.values())
pgroups.sort()
if self.options.mood < SupervisorStates.RUNNING:
if not self.stopping:
# first time, set the stopping flag, do a
# notification and set stop_groups
self.stopping = True
self.stop_groups = pgroups[:]
events.notify(events.SupervisorStoppingEvent())
self.ordered_stop_groups_phase_1()
if not self.shutdown_report():
# if there are no unstopped processes (we're done
# killing everything), it's OK to shutdown or reload
raise asyncore.ExitNow
for fd, dispatcher in combined_map.items():
if dispatcher.readable():
self.options.poller.register_readable(fd)
if dispatcher.writable():
self.options.poller.register_writable(fd)
r, w = self.options.poller.poll(timeout)
for fd in r:
if fd in combined_map:
try:
dispatcher = combined_map[fd]
self.options.logger.blather(
'read event caused by %(dispatcher)r',
dispatcher=dispatcher)
dispatcher.handle_read_event()
if not dispatcher.readable():
self.options.poller.unregister_readable(fd)
except asyncore.ExitNow:
raise
except:
combined_map[fd].handle_error()
for fd in w:
if fd in combined_map:
try:
dispatcher = combined_map[fd]
self.options.logger.blather(
'write event caused by %(dispatcher)r',
dispatcher=dispatcher)
dispatcher.handle_write_event()
if not dispatcher.writable():
self.options.poller.unregister_writable(fd)
except asyncore.ExitNow:
raise
except:
combined_map[fd].handle_error()
for group in pgroups:
group.transition()
self.reap()
self.handle_signal()
self.tick()
if self.options.mood < SupervisorStates.RUNNING:
self.ordered_stop_groups_phase_2()
if self.options.test:
break
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L174-L252
| 6 |
[
0,
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,
44,
45,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
59,
60,
62,
63,
64,
65,
66,
67,
68,
69,
70,
71,
72,
73,
74,
75,
76,
77,
78
] | 92.405063 |
[
46,
61
] | 2.531646 | false | 99.086758 | 79 | 21 | 97.468354 | 0 |
def runforever(self):
events.notify(events.SupervisorRunningEvent())
timeout = 1 # this cannot be fewer than the smallest TickEvent (5)
socket_map = self.options.get_socket_map()
while 1:
combined_map = {}
combined_map.update(socket_map)
combined_map.update(self.get_process_map())
pgroups = list(self.process_groups.values())
pgroups.sort()
if self.options.mood < SupervisorStates.RUNNING:
if not self.stopping:
# first time, set the stopping flag, do a
# notification and set stop_groups
self.stopping = True
self.stop_groups = pgroups[:]
events.notify(events.SupervisorStoppingEvent())
self.ordered_stop_groups_phase_1()
if not self.shutdown_report():
# if there are no unstopped processes (we're done
# killing everything), it's OK to shutdown or reload
raise asyncore.ExitNow
for fd, dispatcher in combined_map.items():
if dispatcher.readable():
self.options.poller.register_readable(fd)
if dispatcher.writable():
self.options.poller.register_writable(fd)
r, w = self.options.poller.poll(timeout)
for fd in r:
if fd in combined_map:
try:
dispatcher = combined_map[fd]
self.options.logger.blather(
'read event caused by %(dispatcher)r',
dispatcher=dispatcher)
dispatcher.handle_read_event()
if not dispatcher.readable():
self.options.poller.unregister_readable(fd)
except asyncore.ExitNow:
raise
except:
combined_map[fd].handle_error()
for fd in w:
if fd in combined_map:
try:
dispatcher = combined_map[fd]
self.options.logger.blather(
'write event caused by %(dispatcher)r',
dispatcher=dispatcher)
dispatcher.handle_write_event()
if not dispatcher.writable():
self.options.poller.unregister_writable(fd)
except asyncore.ExitNow:
raise
except:
combined_map[fd].handle_error()
for group in pgroups:
group.transition()
self.reap()
self.handle_signal()
self.tick()
if self.options.mood < SupervisorStates.RUNNING:
self.ordered_stop_groups_phase_2()
if self.options.test:
break
| 4,322 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
Supervisor.tick
|
(self, now=None)
|
Send one or more 'tick' events when the timeslice related to
the period for the event type rolls over
|
Send one or more 'tick' events when the timeslice related to
the period for the event type rolls over
| 254 | 269 |
def tick(self, now=None):
""" Send one or more 'tick' events when the timeslice related to
the period for the event type rolls over """
if now is None:
# now won't be None in unit tests
now = time.time()
for event in events.TICK_EVENTS:
period = event.period
last_tick = self.ticks.get(period)
if last_tick is None:
# we just started up
last_tick = self.ticks[period] = timeslice(period, now)
this_tick = timeslice(period, now)
if this_tick != last_tick:
self.ticks[period] = this_tick
events.notify(event(this_tick, self))
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L254-L269
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15
] | 100 |
[] | 0 | true | 99.086758 | 16 | 5 | 100 | 2 |
def tick(self, now=None):
if now is None:
# now won't be None in unit tests
now = time.time()
for event in events.TICK_EVENTS:
period = event.period
last_tick = self.ticks.get(period)
if last_tick is None:
# we just started up
last_tick = self.ticks[period] = timeslice(period, now)
this_tick = timeslice(period, now)
if this_tick != last_tick:
self.ticks[period] = this_tick
events.notify(event(this_tick, self))
| 4,323 |
|
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
Supervisor.reap
|
(self, once=False, recursionguard=0)
| 271 | 286 |
def reap(self, once=False, recursionguard=0):
if recursionguard == 100:
return
pid, sts = self.options.waitpid()
if pid:
process = self.options.pidhistory.get(pid, None)
if process is None:
_, msg = decode_wait_status(sts)
self.options.logger.info('reaped unknown pid %s (%s)' % (pid, msg))
else:
process.finish(pid, sts)
del self.options.pidhistory[pid]
if not once:
# keep reaping until no more kids to reap, but don't recurse
# infinitely
self.reap(once=False, recursionguard=recursionguard+1)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L271-L286
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
10,
11,
12,
13,
14,
15
] | 93.75 |
[] | 0 | false | 99.086758 | 16 | 5 | 100 | 0 |
def reap(self, once=False, recursionguard=0):
if recursionguard == 100:
return
pid, sts = self.options.waitpid()
if pid:
process = self.options.pidhistory.get(pid, None)
if process is None:
_, msg = decode_wait_status(sts)
self.options.logger.info('reaped unknown pid %s (%s)' % (pid, msg))
else:
process.finish(pid, sts)
del self.options.pidhistory[pid]
if not once:
# keep reaping until no more kids to reap, but don't recurse
# infinitely
self.reap(once=False, recursionguard=recursionguard+1)
| 4,324 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
Supervisor.handle_signal
|
(self)
| 288 | 314 |
def handle_signal(self):
sig = self.options.get_signal()
if sig:
if sig in (signal.SIGTERM, signal.SIGINT, signal.SIGQUIT):
self.options.logger.warn(
'received %s indicating exit request' % signame(sig))
self.options.mood = SupervisorStates.SHUTDOWN
elif sig == signal.SIGHUP:
if self.options.mood == SupervisorStates.SHUTDOWN:
self.options.logger.warn(
'ignored %s indicating restart request (shutdown in progress)' % signame(sig))
else:
self.options.logger.warn(
'received %s indicating restart request' % signame(sig))
self.options.mood = SupervisorStates.RESTARTING
elif sig == signal.SIGCHLD:
self.options.logger.debug(
'received %s indicating a child quit' % signame(sig))
elif sig == signal.SIGUSR2:
self.options.logger.info(
'received %s indicating log reopen request' % signame(sig))
self.options.reopenlogs()
for group in self.process_groups.values():
group.reopenlogs()
else:
self.options.logger.blather(
'received %s indicating nothing' % signame(sig))
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L288-L314
| 6 |
[
0,
1,
2,
3,
4,
6,
7,
8,
9,
12,
14,
15,
16,
18,
19,
21,
22,
23,
25
] | 70.37037 |
[] | 0 | false | 99.086758 | 27 | 8 | 100 | 0 |
def handle_signal(self):
sig = self.options.get_signal()
if sig:
if sig in (signal.SIGTERM, signal.SIGINT, signal.SIGQUIT):
self.options.logger.warn(
'received %s indicating exit request' % signame(sig))
self.options.mood = SupervisorStates.SHUTDOWN
elif sig == signal.SIGHUP:
if self.options.mood == SupervisorStates.SHUTDOWN:
self.options.logger.warn(
'ignored %s indicating restart request (shutdown in progress)' % signame(sig))
else:
self.options.logger.warn(
'received %s indicating restart request' % signame(sig))
self.options.mood = SupervisorStates.RESTARTING
elif sig == signal.SIGCHLD:
self.options.logger.debug(
'received %s indicating a child quit' % signame(sig))
elif sig == signal.SIGUSR2:
self.options.logger.info(
'received %s indicating log reopen request' % signame(sig))
self.options.reopenlogs()
for group in self.process_groups.values():
group.reopenlogs()
else:
self.options.logger.blather(
'received %s indicating nothing' % signame(sig))
| 4,325 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/supervisord.py
|
Supervisor.get_state
|
(self)
|
return self.options.mood
| 316 | 317 |
def get_state(self):
return self.options.mood
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/supervisord.py#L316-L317
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 99.086758 | 2 | 1 | 100 | 0 |
def get_state(self):
return self.options.mood
| 4,326 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
_levelNumbers
|
()
|
return bynumber
| 39 | 44 |
def _levelNumbers():
bynumber = {}
for name, number in LevelsByName.__dict__.items():
if not name.startswith('_'):
bynumber[number] = name
return bynumber
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L39-L44
| 6 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 97.841727 | 6 | 3 | 100 | 0 |
def _levelNumbers():
bynumber = {}
for name, number in LevelsByName.__dict__.items():
if not name.startswith('_'):
bynumber[number] = name
return bynumber
| 4,327 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
getLevelNumByDescription
|
(description)
|
return num
| 48 | 50 |
def getLevelNumByDescription(description):
num = getattr(LevelsByDescription, description, None)
return num
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L48-L50
| 6 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.841727 | 3 | 1 | 100 | 0 |
def getLevelNumByDescription(description):
num = getattr(LevelsByDescription, description, None)
return num
| 4,328 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
getLogger
|
(level=None)
|
return Logger(level)
| 382 | 383 |
def getLogger(level=None):
return Logger(level)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L382-L383
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.841727 | 2 | 1 | 100 | 0 |
def getLogger(level=None):
return Logger(level)
| 4,329 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
handle_boundIO
|
(logger, fmt, maxbytes=_2MB)
|
Attach a new BoundIO handler to an existing Logger
|
Attach a new BoundIO handler to an existing Logger
| 387 | 394 |
def handle_boundIO(logger, fmt, maxbytes=_2MB):
"""Attach a new BoundIO handler to an existing Logger"""
io = BoundIO(maxbytes)
handler = StreamHandler(io)
handler.setLevel(logger.level)
handler.setFormat(fmt)
logger.addHandler(handler)
logger.getvalue = io.getvalue
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L387-L394
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7
] | 100 |
[] | 0 | true | 97.841727 | 8 | 1 | 100 | 1 |
def handle_boundIO(logger, fmt, maxbytes=_2MB):
io = BoundIO(maxbytes)
handler = StreamHandler(io)
handler.setLevel(logger.level)
handler.setFormat(fmt)
logger.addHandler(handler)
logger.getvalue = io.getvalue
| 4,330 |
|
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
handle_stdout
|
(logger, fmt)
|
Attach a new StreamHandler with stdout handler to an existing Logger
|
Attach a new StreamHandler with stdout handler to an existing Logger
| 396 | 401 |
def handle_stdout(logger, fmt):
"""Attach a new StreamHandler with stdout handler to an existing Logger"""
handler = StreamHandler(sys.stdout)
handler.setFormat(fmt)
handler.setLevel(logger.level)
logger.addHandler(handler)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L396-L401
| 6 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 97.841727 | 6 | 1 | 100 | 1 |
def handle_stdout(logger, fmt):
handler = StreamHandler(sys.stdout)
handler.setFormat(fmt)
handler.setLevel(logger.level)
logger.addHandler(handler)
| 4,331 |
|
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
handle_syslog
|
(logger, fmt)
|
Attach a new Syslog handler to an existing Logger
|
Attach a new Syslog handler to an existing Logger
| 403 | 408 |
def handle_syslog(logger, fmt):
"""Attach a new Syslog handler to an existing Logger"""
handler = SyslogHandler()
handler.setFormat(fmt)
handler.setLevel(logger.level)
logger.addHandler(handler)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L403-L408
| 6 |
[
0,
1,
2,
3,
4,
5
] | 100 |
[] | 0 | true | 97.841727 | 6 | 1 | 100 | 1 |
def handle_syslog(logger, fmt):
handler = SyslogHandler()
handler.setFormat(fmt)
handler.setLevel(logger.level)
logger.addHandler(handler)
| 4,332 |
|
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
handle_file
|
(logger, filename, fmt, rotating=False, maxbytes=0, backups=0)
|
Attach a new file handler to an existing Logger. If the filename
is the magic name of 'syslog' then make it a syslog handler instead.
|
Attach a new file handler to an existing Logger. If the filename
is the magic name of 'syslog' then make it a syslog handler instead.
| 410 | 422 |
def handle_file(logger, filename, fmt, rotating=False, maxbytes=0, backups=0):
"""Attach a new file handler to an existing Logger. If the filename
is the magic name of 'syslog' then make it a syslog handler instead."""
if filename == 'syslog': # TODO remove this
handler = SyslogHandler()
else:
if rotating is False:
handler = FileHandler(filename)
else:
handler = RotatingFileHandler(filename, 'a', maxbytes, backups)
handler.setFormat(fmt)
handler.setLevel(logger.level)
logger.addHandler(handler)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L410-L422
| 6 |
[
0,
1,
2,
3,
6,
7,
9,
10,
11,
12
] | 76.923077 |
[
4
] | 7.692308 | false | 97.841727 | 13 | 3 | 92.307692 | 2 |
def handle_file(logger, filename, fmt, rotating=False, maxbytes=0, backups=0):
if filename == 'syslog': # TODO remove this
handler = SyslogHandler()
else:
if rotating is False:
handler = FileHandler(filename)
else:
handler = RotatingFileHandler(filename, 'a', maxbytes, backups)
handler.setFormat(fmt)
handler.setLevel(logger.level)
logger.addHandler(handler)
| 4,333 |
|
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Handler.__init__
|
(self, stream=None)
| 56 | 58 |
def __init__(self, stream=None):
self.stream = stream
self.closed = False
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L56-L58
| 6 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.841727 | 3 | 1 | 100 | 0 |
def __init__(self, stream=None):
self.stream = stream
self.closed = False
| 4,334 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Handler.setFormat
|
(self, fmt)
| 60 | 61 |
def setFormat(self, fmt):
self.fmt = fmt
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L60-L61
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.841727 | 2 | 1 | 100 | 0 |
def setFormat(self, fmt):
self.fmt = fmt
| 4,335 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Handler.setLevel
|
(self, level)
| 63 | 64 |
def setLevel(self, level):
self.level = level
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L63-L64
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.841727 | 2 | 1 | 100 | 0 |
def setLevel(self, level):
self.level = level
| 4,336 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Handler.flush
|
(self)
| 66 | 72 |
def flush(self):
try:
self.stream.flush()
except IOError as why:
# if supervisor output is piped, EPIPE can be raised at exit
if why.args[0] != errno.EPIPE:
raise
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L66-L72
| 6 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 97.841727 | 7 | 3 | 100 | 0 |
def flush(self):
try:
self.stream.flush()
except IOError as why:
# if supervisor output is piped, EPIPE can be raised at exit
if why.args[0] != errno.EPIPE:
raise
| 4,337 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Handler.close
|
(self)
| 74 | 87 |
def close(self):
if not self.closed:
if hasattr(self.stream, 'fileno'):
try:
fd = self.stream.fileno()
except IOError:
# on python 3, io.IOBase objects always have fileno()
# but calling it may raise io.UnsupportedOperation
pass
else:
if fd < 3: # don't ever close stdout or stderr
return
self.stream.close()
self.closed = True
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L74-L87
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
10,
11,
12,
13
] | 92.857143 |
[] | 0 | false | 97.841727 | 14 | 5 | 100 | 0 |
def close(self):
if not self.closed:
if hasattr(self.stream, 'fileno'):
try:
fd = self.stream.fileno()
except IOError:
# on python 3, io.IOBase objects always have fileno()
# but calling it may raise io.UnsupportedOperation
pass
else:
if fd < 3: # don't ever close stdout or stderr
return
self.stream.close()
self.closed = True
| 4,338 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Handler.emit
|
(self, record)
| 89 | 111 |
def emit(self, record):
try:
binary = (self.fmt == '%(message)s' and
isinstance(record.msg, bytes) and
(not record.kw or record.kw == {'exc_info': None}))
binary_stream = not is_text_stream(self.stream)
if binary:
msg = record.msg
else:
msg = self.fmt % record.asdict()
if binary_stream:
msg = msg.encode('utf-8')
try:
self.stream.write(msg)
except UnicodeError:
# TODO sort out later
# this only occurs because of a test stream type
# which deliberately raises an exception the first
# time it's called. So just do it again
self.stream.write(msg)
self.flush()
except:
self.handleError()
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L89-L111
| 6 |
[
0,
1,
2,
5,
6,
7,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22
] | 86.956522 |
[] | 0 | false | 97.841727 | 23 | 8 | 100 | 0 |
def emit(self, record):
try:
binary = (self.fmt == '%(message)s' and
isinstance(record.msg, bytes) and
(not record.kw or record.kw == {'exc_info': None}))
binary_stream = not is_text_stream(self.stream)
if binary:
msg = record.msg
else:
msg = self.fmt % record.asdict()
if binary_stream:
msg = msg.encode('utf-8')
try:
self.stream.write(msg)
except UnicodeError:
# TODO sort out later
# this only occurs because of a test stream type
# which deliberately raises an exception the first
# time it's called. So just do it again
self.stream.write(msg)
self.flush()
except:
self.handleError()
| 4,339 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Handler.handleError
|
(self)
| 113 | 116 |
def handleError(self):
ei = sys.exc_info()
traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr)
del ei
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L113-L116
| 6 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 97.841727 | 4 | 1 | 100 | 0 |
def handleError(self):
ei = sys.exc_info()
traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr)
del ei
| 4,340 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
StreamHandler.__init__
|
(self, strm=None)
| 119 | 120 |
def __init__(self, strm=None):
Handler.__init__(self, strm)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L119-L120
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.841727 | 2 | 1 | 100 | 0 |
def __init__(self, strm=None):
Handler.__init__(self, strm)
| 4,341 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
StreamHandler.remove
|
(self)
| 122 | 124 |
def remove(self):
if hasattr(self.stream, 'clear'):
self.stream.clear()
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L122-L124
| 6 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.841727 | 3 | 2 | 100 | 0 |
def remove(self):
if hasattr(self.stream, 'clear'):
self.stream.clear()
| 4,342 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
BoundIO.__init__
|
(self, maxbytes, buf=b'')
| 130 | 132 |
def __init__(self, maxbytes, buf=b''):
self.maxbytes = maxbytes
self.buf = buf
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L130-L132
| 6 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.841727 | 3 | 1 | 100 | 0 |
def __init__(self, maxbytes, buf=b''):
self.maxbytes = maxbytes
self.buf = buf
| 4,343 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
BoundIO.close
|
(self)
| 137 | 138 |
def close(self):
self.clear()
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L137-L138
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.841727 | 2 | 1 | 100 | 0 |
def close(self):
self.clear()
| 4,344 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
BoundIO.write
|
(self, b)
| 140 | 144 |
def write(self, b):
blen = len(b)
if len(self.buf) + blen > self.maxbytes:
self.buf = self.buf[blen:]
self.buf += b
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L140-L144
| 6 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 97.841727 | 5 | 2 | 100 | 0 |
def write(self, b):
blen = len(b)
if len(self.buf) + blen > self.maxbytes:
self.buf = self.buf[blen:]
self.buf += b
| 4,345 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
BoundIO.getvalue
|
(self)
|
return self.buf
| 146 | 147 |
def getvalue(self):
return self.buf
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L146-L147
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.841727 | 2 | 1 | 100 | 0 |
def getvalue(self):
return self.buf
| 4,346 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
BoundIO.clear
|
(self)
| 149 | 150 |
def clear(self):
self.buf = b''
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L149-L150
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.841727 | 2 | 1 | 100 | 0 |
def clear(self):
self.buf = b''
| 4,347 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
FileHandler.__init__
|
(self, filename, mode='ab')
| 156 | 173 |
def __init__(self, filename, mode='ab'):
Handler.__init__(self)
try:
self.stream = open(filename, mode)
except OSError as e:
if mode == 'ab' and e.errno == errno.ESPIPE:
# Python 3 can't open special files like
# /dev/stdout in 'a' mode due to an implicit seek call
# that fails with ESPIPE. Retry in 'w' mode.
# See: http://bugs.python.org/issue27805
mode = 'wb'
self.stream = open(filename, mode)
else:
raise
self.baseFilename = filename
self.mode = mode
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L156-L173
| 6 |
[
0,
1,
2,
3,
4,
15,
16,
17
] | 44.444444 |
[
5,
6,
11,
12,
14
] | 27.777778 | false | 97.841727 | 18 | 4 | 72.222222 | 0 |
def __init__(self, filename, mode='ab'):
Handler.__init__(self)
try:
self.stream = open(filename, mode)
except OSError as e:
if mode == 'ab' and e.errno == errno.ESPIPE:
# Python 3 can't open special files like
# /dev/stdout in 'a' mode due to an implicit seek call
# that fails with ESPIPE. Retry in 'w' mode.
# See: http://bugs.python.org/issue27805
mode = 'wb'
self.stream = open(filename, mode)
else:
raise
self.baseFilename = filename
self.mode = mode
| 4,348 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
FileHandler.reopen
|
(self)
| 175 | 178 |
def reopen(self):
self.close()
self.stream = open(self.baseFilename, self.mode)
self.closed = False
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L175-L178
| 6 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 97.841727 | 4 | 1 | 100 | 0 |
def reopen(self):
self.close()
self.stream = open(self.baseFilename, self.mode)
self.closed = False
| 4,349 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
FileHandler.remove
|
(self)
| 180 | 186 |
def remove(self):
self.close()
try:
os.remove(self.baseFilename)
except OSError as why:
if why.args[0] != errno.ENOENT:
raise
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L180-L186
| 6 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 97.841727 | 7 | 3 | 100 | 0 |
def remove(self):
self.close()
try:
os.remove(self.baseFilename)
except OSError as why:
if why.args[0] != errno.ENOENT:
raise
| 4,350 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
RotatingFileHandler.__init__
|
(self, filename, mode='ab', maxBytes=512*1024*1024,
backupCount=10)
|
Open the specified file and use it as the stream for logging.
By default, the file grows indefinitely. You can specify particular
values of maxBytes and backupCount to allow the file to rollover at
a predetermined size.
Rollover occurs whenever the current log file is nearly maxBytes in
length. If backupCount is >= 1, the system will successively create
new files with the same pathname as the base file, but with extensions
".1", ".2" etc. appended to it. For example, with a backupCount of 5
and a base file name of "app.log", you would get "app.log",
"app.log.1", "app.log.2", ... through to "app.log.5". The file being
written to is always "app.log" - when it gets filled up, it is closed
and renamed to "app.log.1", and if files "app.log.1", "app.log.2" etc.
exist, then they are renamed to "app.log.2", "app.log.3" etc.
respectively.
If maxBytes is zero, rollover never occurs.
|
Open the specified file and use it as the stream for logging.
| 189 | 217 |
def __init__(self, filename, mode='ab', maxBytes=512*1024*1024,
backupCount=10):
"""
Open the specified file and use it as the stream for logging.
By default, the file grows indefinitely. You can specify particular
values of maxBytes and backupCount to allow the file to rollover at
a predetermined size.
Rollover occurs whenever the current log file is nearly maxBytes in
length. If backupCount is >= 1, the system will successively create
new files with the same pathname as the base file, but with extensions
".1", ".2" etc. appended to it. For example, with a backupCount of 5
and a base file name of "app.log", you would get "app.log",
"app.log.1", "app.log.2", ... through to "app.log.5". The file being
written to is always "app.log" - when it gets filled up, it is closed
and renamed to "app.log.1", and if files "app.log.1", "app.log.2" etc.
exist, then they are renamed to "app.log.2", "app.log.3" etc.
respectively.
If maxBytes is zero, rollover never occurs.
"""
if maxBytes > 0:
mode = 'ab' # doesn't make sense otherwise!
FileHandler.__init__(self, filename, mode)
self.maxBytes = maxBytes
self.backupCount = backupCount
self.counter = 0
self.every = 10
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L189-L217
| 6 |
[
0,
21,
22,
23,
24,
25,
26,
27,
28
] | 31.034483 |
[] | 0 | false | 97.841727 | 29 | 2 | 100 | 18 |
def __init__(self, filename, mode='ab', maxBytes=512*1024*1024,
backupCount=10):
if maxBytes > 0:
mode = 'ab' # doesn't make sense otherwise!
FileHandler.__init__(self, filename, mode)
self.maxBytes = maxBytes
self.backupCount = backupCount
self.counter = 0
self.every = 10
| 4,351 |
|
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
RotatingFileHandler.emit
|
(self, record)
|
Emit a record.
Output the record to the file, catering for rollover as described
in doRollover().
|
Emit a record.
| 219 | 227 |
def emit(self, record):
"""
Emit a record.
Output the record to the file, catering for rollover as described
in doRollover().
"""
FileHandler.emit(self, record)
self.doRollover()
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L219-L227
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 97.841727 | 9 | 1 | 100 | 4 |
def emit(self, record):
FileHandler.emit(self, record)
self.doRollover()
| 4,352 |
|
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
RotatingFileHandler._remove
|
(self, fn)
|
return os.remove(fn)
| 229 | 231 |
def _remove(self, fn): # pragma: no cover
# this is here to service stubbing in unit tests
return os.remove(fn)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L229-L231
| 6 |
[] | 0 |
[] | 0 | false | 97.841727 | 3 | 1 | 100 | 0 |
def _remove(self, fn): # pragma: no cover
# this is here to service stubbing in unit tests
return os.remove(fn)
| 4,353 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
RotatingFileHandler._rename
|
(self, src, tgt)
|
return os.rename(src, tgt)
| 233 | 235 |
def _rename(self, src, tgt): # pragma: no cover
# this is here to service stubbing in unit tests
return os.rename(src, tgt)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L233-L235
| 6 |
[] | 0 |
[] | 0 | false | 97.841727 | 3 | 1 | 100 | 0 |
def _rename(self, src, tgt): # pragma: no cover
# this is here to service stubbing in unit tests
return os.rename(src, tgt)
| 4,354 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
RotatingFileHandler._exists
|
(self, fn)
|
return os.path.exists(fn)
| 237 | 239 |
def _exists(self, fn): # pragma: no cover
# this is here to service stubbing in unit tests
return os.path.exists(fn)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L237-L239
| 6 |
[] | 0 |
[] | 0 | false | 97.841727 | 3 | 1 | 100 | 0 |
def _exists(self, fn): # pragma: no cover
# this is here to service stubbing in unit tests
return os.path.exists(fn)
| 4,355 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
RotatingFileHandler.removeAndRename
|
(self, sfn, dfn)
| 241 | 255 |
def removeAndRename(self, sfn, dfn):
if self._exists(dfn):
try:
self._remove(dfn)
except OSError as why:
# catch race condition (destination already deleted)
if why.args[0] != errno.ENOENT:
raise
try:
self._rename(sfn, dfn)
except OSError as why:
# catch exceptional condition (source deleted)
# E.g. cleanup script removes active log.
if why.args[0] != errno.ENOENT:
raise
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L241-L255
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14
] | 100 |
[] | 0 | true | 97.841727 | 15 | 6 | 100 | 0 |
def removeAndRename(self, sfn, dfn):
if self._exists(dfn):
try:
self._remove(dfn)
except OSError as why:
# catch race condition (destination already deleted)
if why.args[0] != errno.ENOENT:
raise
try:
self._rename(sfn, dfn)
except OSError as why:
# catch exceptional condition (source deleted)
# E.g. cleanup script removes active log.
if why.args[0] != errno.ENOENT:
raise
| 4,356 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
RotatingFileHandler.doRollover
|
(self)
|
Do a rollover, as described in __init__().
|
Do a rollover, as described in __init__().
| 257 | 276 |
def doRollover(self):
"""
Do a rollover, as described in __init__().
"""
if self.maxBytes <= 0:
return
if not (self.stream.tell() >= self.maxBytes):
return
self.stream.close()
if self.backupCount > 0:
for i in range(self.backupCount - 1, 0, -1):
sfn = "%s.%d" % (self.baseFilename, i)
dfn = "%s.%d" % (self.baseFilename, i + 1)
if os.path.exists(sfn):
self.removeAndRename(sfn, dfn)
dfn = self.baseFilename + ".1"
self.removeAndRename(self.baseFilename, dfn)
self.stream = open(self.baseFilename, 'wb')
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L257-L276
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19
] | 100 |
[] | 0 | true | 97.841727 | 20 | 6 | 100 | 1 |
def doRollover(self):
if self.maxBytes <= 0:
return
if not (self.stream.tell() >= self.maxBytes):
return
self.stream.close()
if self.backupCount > 0:
for i in range(self.backupCount - 1, 0, -1):
sfn = "%s.%d" % (self.baseFilename, i)
dfn = "%s.%d" % (self.baseFilename, i + 1)
if os.path.exists(sfn):
self.removeAndRename(sfn, dfn)
dfn = self.baseFilename + ".1"
self.removeAndRename(self.baseFilename, dfn)
self.stream = open(self.baseFilename, 'wb')
| 4,357 |
|
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
LogRecord.__init__
|
(self, level, msg, **kw)
| 279 | 283 |
def __init__(self, level, msg, **kw):
self.level = level
self.msg = msg
self.kw = kw
self.dictrepr = None
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L279-L283
| 6 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 97.841727 | 5 | 1 | 100 | 0 |
def __init__(self, level, msg, **kw):
self.level = level
self.msg = msg
self.kw = kw
self.dictrepr = None
| 4,358 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
LogRecord.asdict
|
(self)
|
return self.dictrepr
| 285 | 297 |
def asdict(self):
if self.dictrepr is None:
now = time.time()
msecs = (now - long(now)) * 1000
part1 = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now))
asctime = '%s,%03d' % (part1, msecs)
levelname = LOG_LEVELS_BY_NUM[self.level]
msg = as_string(self.msg)
if self.kw:
msg = msg % self.kw
self.dictrepr = {'message':msg, 'levelname':levelname,
'asctime':asctime}
return self.dictrepr
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L285-L297
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
12
] | 92.307692 |
[] | 0 | false | 97.841727 | 13 | 3 | 100 | 0 |
def asdict(self):
if self.dictrepr is None:
now = time.time()
msecs = (now - long(now)) * 1000
part1 = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now))
asctime = '%s,%03d' % (part1, msecs)
levelname = LOG_LEVELS_BY_NUM[self.level]
msg = as_string(self.msg)
if self.kw:
msg = msg % self.kw
self.dictrepr = {'message':msg, 'levelname':levelname,
'asctime':asctime}
return self.dictrepr
| 4,359 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Logger.__init__
|
(self, level=None, handlers=None)
| 300 | 307 |
def __init__(self, level=None, handlers=None):
if level is None:
level = LevelsByName.INFO
self.level = level
if handlers is None:
handlers = []
self.handlers = handlers
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L300-L307
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7
] | 100 |
[] | 0 | true | 97.841727 | 8 | 3 | 100 | 0 |
def __init__(self, level=None, handlers=None):
if level is None:
level = LevelsByName.INFO
self.level = level
if handlers is None:
handlers = []
self.handlers = handlers
| 4,360 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Logger.close
|
(self)
| 309 | 311 |
def close(self):
for handler in self.handlers:
handler.close()
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L309-L311
| 6 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.841727 | 3 | 2 | 100 | 0 |
def close(self):
for handler in self.handlers:
handler.close()
| 4,361 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Logger.blather
|
(self, msg, **kw)
| 313 | 315 |
def blather(self, msg, **kw):
if LevelsByName.BLAT >= self.level:
self.log(LevelsByName.BLAT, msg, **kw)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L313-L315
| 6 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.841727 | 3 | 2 | 100 | 0 |
def blather(self, msg, **kw):
if LevelsByName.BLAT >= self.level:
self.log(LevelsByName.BLAT, msg, **kw)
| 4,362 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Logger.trace
|
(self, msg, **kw)
| 317 | 319 |
def trace(self, msg, **kw):
if LevelsByName.TRAC >= self.level:
self.log(LevelsByName.TRAC, msg, **kw)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L317-L319
| 6 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.841727 | 3 | 2 | 100 | 0 |
def trace(self, msg, **kw):
if LevelsByName.TRAC >= self.level:
self.log(LevelsByName.TRAC, msg, **kw)
| 4,363 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Logger.debug
|
(self, msg, **kw)
| 321 | 323 |
def debug(self, msg, **kw):
if LevelsByName.DEBG >= self.level:
self.log(LevelsByName.DEBG, msg, **kw)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L321-L323
| 6 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.841727 | 3 | 2 | 100 | 0 |
def debug(self, msg, **kw):
if LevelsByName.DEBG >= self.level:
self.log(LevelsByName.DEBG, msg, **kw)
| 4,364 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Logger.info
|
(self, msg, **kw)
| 325 | 327 |
def info(self, msg, **kw):
if LevelsByName.INFO >= self.level:
self.log(LevelsByName.INFO, msg, **kw)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L325-L327
| 6 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.841727 | 3 | 2 | 100 | 0 |
def info(self, msg, **kw):
if LevelsByName.INFO >= self.level:
self.log(LevelsByName.INFO, msg, **kw)
| 4,365 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Logger.warn
|
(self, msg, **kw)
| 329 | 331 |
def warn(self, msg, **kw):
if LevelsByName.WARN >= self.level:
self.log(LevelsByName.WARN, msg, **kw)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L329-L331
| 6 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.841727 | 3 | 2 | 100 | 0 |
def warn(self, msg, **kw):
if LevelsByName.WARN >= self.level:
self.log(LevelsByName.WARN, msg, **kw)
| 4,366 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Logger.error
|
(self, msg, **kw)
| 333 | 335 |
def error(self, msg, **kw):
if LevelsByName.ERRO >= self.level:
self.log(LevelsByName.ERRO, msg, **kw)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L333-L335
| 6 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.841727 | 3 | 2 | 100 | 0 |
def error(self, msg, **kw):
if LevelsByName.ERRO >= self.level:
self.log(LevelsByName.ERRO, msg, **kw)
| 4,367 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Logger.critical
|
(self, msg, **kw)
| 337 | 339 |
def critical(self, msg, **kw):
if LevelsByName.CRIT >= self.level:
self.log(LevelsByName.CRIT, msg, **kw)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L337-L339
| 6 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.841727 | 3 | 2 | 100 | 0 |
def critical(self, msg, **kw):
if LevelsByName.CRIT >= self.level:
self.log(LevelsByName.CRIT, msg, **kw)
| 4,368 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Logger.log
|
(self, level, msg, **kw)
| 341 | 345 |
def log(self, level, msg, **kw):
record = LogRecord(level, msg, **kw)
for handler in self.handlers:
if level >= handler.level:
handler.emit(record)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L341-L345
| 6 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 97.841727 | 5 | 3 | 100 | 0 |
def log(self, level, msg, **kw):
record = LogRecord(level, msg, **kw)
for handler in self.handlers:
if level >= handler.level:
handler.emit(record)
| 4,369 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
Logger.addHandler
|
(self, hdlr)
| 347 | 348 |
def addHandler(self, hdlr):
self.handlers.append(hdlr)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L347-L348
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.841727 | 2 | 1 | 100 | 0 |
def addHandler(self, hdlr):
self.handlers.append(hdlr)
| 4,370 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
SyslogHandler.__init__
|
(self)
| 354 | 356 |
def __init__(self):
Handler.__init__(self)
assert syslog is not None, "Syslog module not present"
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L354-L356
| 6 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.841727 | 3 | 2 | 100 | 0 |
def __init__(self):
Handler.__init__(self)
assert syslog is not None, "Syslog module not present"
| 4,371 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
SyslogHandler._syslog
|
(self, msg)
| 364 | 366 |
def _syslog(self, msg): # pragma: no cover
# this exists only for unit test stubbing
syslog.syslog(msg)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L364-L366
| 6 |
[] | 0 |
[] | 0 | false | 97.841727 | 3 | 1 | 100 | 0 |
def _syslog(self, msg): # pragma: no cover
# this exists only for unit test stubbing
syslog.syslog(msg)
| 4,372 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/loggers.py
|
SyslogHandler.emit
|
(self, record)
| 368 | 380 |
def emit(self, record):
try:
params = record.asdict()
message = params['message']
for line in message.rstrip('\n').split('\n'):
params['message'] = line
msg = self.fmt % params
try:
self._syslog(msg)
except UnicodeError:
self._syslog(msg.encode("UTF-8"))
except:
self.handleError()
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/loggers.py#L368-L380
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
] | 100 |
[] | 0 | true | 97.841727 | 13 | 4 | 100 | 0 |
def emit(self, record):
try:
params = record.asdict()
message = params['message']
for line in message.rstrip('\n').split('\n'):
params['message'] = line
msg = self.fmt % params
try:
self._syslog(msg)
except UnicodeError:
self._syslog(msg.encode("UTF-8"))
except:
self.handleError()
| 4,373 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
subscribe
|
(type, callback)
| 6 | 7 |
def subscribe(type, callback):
callbacks.append((type, callback))
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L6-L7
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.647059 | 2 | 1 | 100 | 0 |
def subscribe(type, callback):
callbacks.append((type, callback))
| 4,374 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
unsubscribe
|
(type, callback)
| 9 | 10 |
def unsubscribe(type, callback):
callbacks.remove((type, callback))
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L9-L10
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.647059 | 2 | 1 | 100 | 0 |
def unsubscribe(type, callback):
callbacks.remove((type, callback))
| 4,375 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
notify
|
(event)
| 12 | 15 |
def notify(event):
for type, callback in callbacks:
if isinstance(event, type):
callback(event)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L12-L15
| 6 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 97.647059 | 4 | 3 | 100 | 0 |
def notify(event):
for type, callback in callbacks:
if isinstance(event, type):
callback(event)
| 4,376 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
clear
|
()
| 17 | 18 |
def clear():
callbacks[:] = []
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L17-L18
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.647059 | 2 | 1 | 100 | 0 |
def clear():
callbacks[:] = []
| 4,377 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
getEventNameByType
|
(requested)
| 229 | 232 |
def getEventNameByType(requested):
for name, typ in EventTypes.__dict__.items():
if typ is requested:
return name
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L229-L232
| 6 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 97.647059 | 4 | 3 | 100 | 0 |
def getEventNameByType(requested):
for name, typ in EventTypes.__dict__.items():
if typ is requested:
return name
| 4,378 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
register
|
(name, event)
| 234 | 235 |
def register(name, event):
setattr(EventTypes, name, event)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L234-L235
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.647059 | 2 | 1 | 100 | 0 |
def register(name, event):
setattr(EventTypes, name, event)
| 4,379 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
ProcessLogEvent.__init__
|
(self, process, pid, data)
| 27 | 30 |
def __init__(self, process, pid, data):
self.process = process
self.pid = pid
self.data = data
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L27-L30
| 6 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 97.647059 | 4 | 1 | 100 | 0 |
def __init__(self, process, pid, data):
self.process = process
self.pid = pid
self.data = data
| 4,380 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
ProcessLogEvent.payload
|
(self)
|
return result
| 32 | 47 |
def payload(self):
groupname = ''
if self.process.group is not None:
groupname = self.process.group.config.name
try:
data = as_string(self.data)
except UnicodeDecodeError:
data = 'Undecodable: %r' % self.data
# On Python 2, stuff needs to be in Unicode before invoking the
# % operator, otherwise implicit encodings to ASCII can cause
# failures
fmt = as_string('processname:%s groupname:%s pid:%s channel:%s\n%s')
result = fmt % (as_string(self.process.config.name),
as_string(groupname), self.pid,
as_string(self.channel), data)
return result
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L32-L47
| 6 |
[
0,
1,
2,
3,
4,
5,
10,
11,
12,
15
] | 62.5 |
[
6,
7
] | 12.5 | false | 97.647059 | 16 | 3 | 87.5 | 0 |
def payload(self):
groupname = ''
if self.process.group is not None:
groupname = self.process.group.config.name
try:
data = as_string(self.data)
except UnicodeDecodeError:
data = 'Undecodable: %r' % self.data
# On Python 2, stuff needs to be in Unicode before invoking the
# % operator, otherwise implicit encodings to ASCII can cause
# failures
fmt = as_string('processname:%s groupname:%s pid:%s channel:%s\n%s')
result = fmt % (as_string(self.process.config.name),
as_string(groupname), self.pid,
as_string(self.channel), data)
return result
| 4,381 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
ProcessCommunicationEvent.__init__
|
(self, process, pid, data)
| 61 | 64 |
def __init__(self, process, pid, data):
self.process = process
self.pid = pid
self.data = data
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L61-L64
| 6 |
[
0,
1,
2,
3
] | 100 |
[] | 0 | true | 97.647059 | 4 | 1 | 100 | 0 |
def __init__(self, process, pid, data):
self.process = process
self.pid = pid
self.data = data
| 4,382 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
ProcessCommunicationEvent.payload
|
(self)
|
return 'processname:%s groupname:%s pid:%s\n%s' % (
self.process.config.name,
groupname,
self.pid,
data)
| 66 | 78 |
def payload(self):
groupname = ''
if self.process.group is not None:
groupname = self.process.group.config.name
try:
data = as_string(self.data)
except UnicodeDecodeError:
data = 'Undecodable: %r' % self.data
return 'processname:%s groupname:%s pid:%s\n%s' % (
self.process.config.name,
groupname,
self.pid,
data)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L66-L78
| 6 |
[
0,
1,
2,
3,
4,
5,
8
] | 53.846154 |
[
6,
7
] | 15.384615 | false | 97.647059 | 13 | 3 | 84.615385 | 0 |
def payload(self):
groupname = ''
if self.process.group is not None:
groupname = self.process.group.config.name
try:
data = as_string(self.data)
except UnicodeDecodeError:
data = 'Undecodable: %r' % self.data
return 'processname:%s groupname:%s pid:%s\n%s' % (
self.process.config.name,
groupname,
self.pid,
data)
| 4,383 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
RemoteCommunicationEvent.__init__
|
(self, type, data)
| 87 | 89 |
def __init__(self, type, data):
self.type = type
self.data = data
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L87-L89
| 6 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.647059 | 3 | 1 | 100 | 0 |
def __init__(self, type, data):
self.type = type
self.data = data
| 4,384 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
RemoteCommunicationEvent.payload
|
(self)
|
return 'type:%s\n%s' % (self.type, self.data)
| 91 | 92 |
def payload(self):
return 'type:%s\n%s' % (self.type, self.data)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L91-L92
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.647059 | 2 | 1 | 100 | 0 |
def payload(self):
return 'type:%s\n%s' % (self.type, self.data)
| 4,385 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
SupervisorStateChangeEvent.payload
|
(self)
|
return ''
| 96 | 97 |
def payload(self):
return ''
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L96-L97
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.647059 | 2 | 1 | 100 | 0 |
def payload(self):
return ''
| 4,386 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
EventRejectedEvent.__init__
|
(self, process, event)
| 106 | 108 |
def __init__(self, process, event):
self.process = process
self.event = event
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L106-L108
| 6 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.647059 | 3 | 1 | 100 | 0 |
def __init__(self, process, event):
self.process = process
self.event = event
| 4,387 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
ProcessStateEvent.__init__
|
(self, process, from_state, expected=True)
| 114 | 120 |
def __init__(self, process, from_state, expected=True):
self.process = process
self.from_state = from_state
self.expected = expected
# we eagerly render these so if the process pid, etc changes beneath
# us, we stash the values at the time the event was sent
self.extra_values = self.get_extra_values()
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L114-L120
| 6 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 97.647059 | 7 | 1 | 100 | 0 |
def __init__(self, process, from_state, expected=True):
self.process = process
self.from_state = from_state
self.expected = expected
# we eagerly render these so if the process pid, etc changes beneath
# us, we stash the values at the time the event was sent
self.extra_values = self.get_extra_values()
| 4,388 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
ProcessStateEvent.payload
|
(self)
|
return s
| 122 | 130 |
def payload(self):
groupname = ''
if self.process.group is not None:
groupname = self.process.group.config.name
L = [('processname', self.process.config.name), ('groupname', groupname),
('from_state', getProcessStateDescription(self.from_state))]
L.extend(self.extra_values)
s = ' '.join( [ '%s:%s' % (name, val) for (name, val) in L ] )
return s
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L122-L130
| 6 |
[
0,
1,
2,
3,
4,
6,
7,
8
] | 88.888889 |
[] | 0 | false | 97.647059 | 9 | 3 | 100 | 0 |
def payload(self):
groupname = ''
if self.process.group is not None:
groupname = self.process.group.config.name
L = [('processname', self.process.config.name), ('groupname', groupname),
('from_state', getProcessStateDescription(self.from_state))]
L.extend(self.extra_values)
s = ' '.join( [ '%s:%s' % (name, val) for (name, val) in L ] )
return s
| 4,389 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
ProcessStateEvent.get_extra_values
|
(self)
|
return []
| 132 | 133 |
def get_extra_values(self):
return []
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L132-L133
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.647059 | 2 | 1 | 100 | 0 |
def get_extra_values(self):
return []
| 4,390 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
ProcessStateExitedEvent.get_extra_values
|
(self)
|
return [('expected', int(self.expected)), ('pid', self.process.pid)]
| 152 | 153 |
def get_extra_values(self):
return [('expected', int(self.expected)), ('pid', self.process.pid)]
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L152-L153
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.647059 | 2 | 1 | 100 | 0 |
def get_extra_values(self):
return [('expected', int(self.expected)), ('pid', self.process.pid)]
| 4,391 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
ProcessStateRunningEvent.get_extra_values
|
(self)
|
return [('pid', self.process.pid)]
| 156 | 157 |
def get_extra_values(self):
return [('pid', self.process.pid)]
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L156-L157
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.647059 | 2 | 1 | 100 | 0 |
def get_extra_values(self):
return [('pid', self.process.pid)]
| 4,392 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
ProcessGroupEvent.__init__
|
(self, group)
| 168 | 169 |
def __init__(self, group):
self.group = group
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L168-L169
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.647059 | 2 | 1 | 100 | 0 |
def __init__(self, group):
self.group = group
| 4,393 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
ProcessGroupEvent.payload
|
(self)
|
return 'groupname:%s\n' % self.group
| 171 | 172 |
def payload(self):
return 'groupname:%s\n' % self.group
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L171-L172
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.647059 | 2 | 1 | 100 | 0 |
def payload(self):
return 'groupname:%s\n' % self.group
| 4,394 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
TickEvent.__init__
|
(self, when, supervisord)
| 182 | 184 |
def __init__(self, when, supervisord):
self.when = when
self.supervisord = supervisord
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L182-L184
| 6 |
[
0,
1,
2
] | 100 |
[] | 0 | true | 97.647059 | 3 | 1 | 100 | 0 |
def __init__(self, when, supervisord):
self.when = when
self.supervisord = supervisord
| 4,395 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/events.py
|
TickEvent.payload
|
(self)
|
return 'when:%s' % self.when
| 186 | 187 |
def payload(self):
return 'when:%s' % self.when
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/events.py#L186-L187
| 6 |
[
0,
1
] | 100 |
[] | 0 | true | 97.647059 | 2 | 1 | 100 | 0 |
def payload(self):
return 'when:%s' % self.when
| 4,396 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/datatypes.py
|
process_or_group_name
|
(name)
|
return s
|
Ensures that a process or group name is not created with
characters that break the eventlistener protocol or web UI URLs
|
Ensures that a process or group name is not created with
characters that break the eventlistener protocol or web UI URLs
| 12 | 19 |
def process_or_group_name(name):
"""Ensures that a process or group name is not created with
characters that break the eventlistener protocol or web UI URLs"""
s = str(name).strip()
for character in ' :/':
if character in s:
raise ValueError("Invalid name: %r because of character: %r" % (name, character))
return s
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/datatypes.py#L12-L19
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7
] | 100 |
[] | 0 | true | 100 | 8 | 3 | 100 | 2 |
def process_or_group_name(name):
s = str(name).strip()
for character in ' :/':
if character in s:
raise ValueError("Invalid name: %r because of character: %r" % (name, character))
return s
| 4,397 |
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/datatypes.py
|
integer
|
(value)
| 21 | 25 |
def integer(value):
try:
return int(value)
except (ValueError, OverflowError):
return long(value)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/datatypes.py#L21-L25
| 6 |
[
0,
1,
2,
3,
4
] | 100 |
[] | 0 | true | 100 | 5 | 2 | 100 | 0 |
def integer(value):
try:
return int(value)
except (ValueError, OverflowError):
return long(value)
| 4,398 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/datatypes.py
|
boolean
|
(s)
|
Convert a string value to a boolean value.
|
Convert a string value to a boolean value.
| 30 | 38 |
def boolean(s):
"""Convert a string value to a boolean value."""
ss = str(s).lower()
if ss in TRUTHY_STRINGS:
return True
elif ss in FALSY_STRINGS:
return False
else:
raise ValueError("not a valid boolean value: " + repr(s))
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/datatypes.py#L30-L38
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 100 | 9 | 3 | 100 | 1 |
def boolean(s):
ss = str(s).lower()
if ss in TRUTHY_STRINGS:
return True
elif ss in FALSY_STRINGS:
return False
else:
raise ValueError("not a valid boolean value: " + repr(s))
| 4,399 |
|
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/datatypes.py
|
list_of_strings
|
(arg)
| 40 | 46 |
def list_of_strings(arg):
if not arg:
return []
try:
return [x.strip() for x in arg.split(',')]
except:
raise ValueError("not a valid list of strings: " + repr(arg))
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/datatypes.py#L40-L46
| 6 |
[
0,
1,
2,
3,
4,
5,
6
] | 100 |
[] | 0 | true | 100 | 7 | 4 | 100 | 0 |
def list_of_strings(arg):
if not arg:
return []
try:
return [x.strip() for x in arg.split(',')]
except:
raise ValueError("not a valid list of strings: " + repr(arg))
| 4,400 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/datatypes.py
|
list_of_ints
|
(arg)
| 48 | 55 |
def list_of_ints(arg):
if not arg:
return []
else:
try:
return list(map(int, arg.split(",")))
except:
raise ValueError("not a valid list of ints: " + repr(arg))
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/datatypes.py#L48-L55
| 6 |
[
0,
1,
2,
4,
5,
6,
7
] | 87.5 |
[] | 0 | false | 100 | 8 | 3 | 100 | 0 |
def list_of_ints(arg):
if not arg:
return []
else:
try:
return list(map(int, arg.split(",")))
except:
raise ValueError("not a valid list of ints: " + repr(arg))
| 4,401 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/datatypes.py
|
list_of_exitcodes
|
(arg)
| 57 | 65 |
def list_of_exitcodes(arg):
try:
vals = list_of_ints(arg)
for val in vals:
if (val > 255) or (val < 0):
raise ValueError('Invalid exit code "%s"' % val)
return vals
except:
raise ValueError("not a valid list of exit codes: " + repr(arg))
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/datatypes.py#L57-L65
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8
] | 100 |
[] | 0 | true | 100 | 9 | 5 | 100 | 0 |
def list_of_exitcodes(arg):
try:
vals = list_of_ints(arg)
for val in vals:
if (val > 255) or (val < 0):
raise ValueError('Invalid exit code "%s"' % val)
return vals
except:
raise ValueError("not a valid list of exit codes: " + repr(arg))
| 4,402 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/datatypes.py
|
dict_of_key_value_pairs
|
(arg)
|
return D
|
parse KEY=val,KEY2=val2 into {'KEY':'val', 'KEY2':'val2'}
Quotes can be used to allow commas in the value
|
parse KEY=val,KEY2=val2 into {'KEY':'val', 'KEY2':'val2'}
Quotes can be used to allow commas in the value
| 67 | 86 |
def dict_of_key_value_pairs(arg):
""" parse KEY=val,KEY2=val2 into {'KEY':'val', 'KEY2':'val2'}
Quotes can be used to allow commas in the value
"""
lexer = shlex.shlex(str(arg))
lexer.wordchars += '/.+-():'
tokens = list(lexer)
tokens_len = len(tokens)
D = {}
i = 0
while i < tokens_len:
k_eq_v = tokens[i:i+3]
if len(k_eq_v) != 3 or k_eq_v[1] != '=':
raise ValueError(
"Unexpected end of key/value pairs in value '%s'" % arg)
D[k_eq_v[0]] = k_eq_v[2].strip('\'"')
i += 4
return D
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/datatypes.py#L67-L86
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19
] | 100 |
[] | 0 | true | 100 | 20 | 4 | 100 | 2 |
def dict_of_key_value_pairs(arg):
lexer = shlex.shlex(str(arg))
lexer.wordchars += '/.+-():'
tokens = list(lexer)
tokens_len = len(tokens)
D = {}
i = 0
while i < tokens_len:
k_eq_v = tokens[i:i+3]
if len(k_eq_v) != 3 or k_eq_v[1] != '=':
raise ValueError(
"Unexpected end of key/value pairs in value '%s'" % arg)
D[k_eq_v[0]] = k_eq_v[2].strip('\'"')
i += 4
return D
| 4,403 |
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/datatypes.py
|
logfile_name
|
(val)
| 99 | 112 |
def logfile_name(val):
if hasattr(val, 'lower'):
coerced = val.lower()
else:
coerced = val
if coerced in LOGFILE_NONES:
return None
elif coerced in LOGFILE_AUTOS:
return Automatic
elif coerced in LOGFILE_SYSLOGS:
return Syslog
else:
return existing_dirpath(val)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/datatypes.py#L99-L112
| 6 |
[
0,
1,
2,
4,
5,
6,
7,
8,
9,
10,
11,
13
] | 85.714286 |
[] | 0 | false | 100 | 14 | 5 | 100 | 0 |
def logfile_name(val):
if hasattr(val, 'lower'):
coerced = val.lower()
else:
coerced = val
if coerced in LOGFILE_NONES:
return None
elif coerced in LOGFILE_AUTOS:
return Automatic
elif coerced in LOGFILE_SYSLOGS:
return Syslog
else:
return existing_dirpath(val)
| 4,404 |
|||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/datatypes.py
|
inet_address
|
(s)
|
return host, port
| 134 | 150 |
def inet_address(s):
# returns (host, port) tuple
host = ''
if ":" in s:
host, s = s.rsplit(":", 1)
if not s:
raise ValueError("no port number specified in %r" % s)
port = port_number(s)
host = host.lower()
else:
try:
port = port_number(s)
except ValueError:
raise ValueError("not a valid port number: %r " %s)
if not host or host == '*':
host = ''
return host, port
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/datatypes.py#L134-L150
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
10,
11,
12,
13,
14,
15,
16
] | 94.117647 |
[] | 0 | false | 100 | 17 | 6 | 100 | 0 |
def inet_address(s):
# returns (host, port) tuple
host = ''
if ":" in s:
host, s = s.rsplit(":", 1)
if not s:
raise ValueError("no port number specified in %r" % s)
port = port_number(s)
host = host.lower()
else:
try:
port = port_number(s)
except ValueError:
raise ValueError("not a valid port number: %r " %s)
if not host or host == '*':
host = ''
return host, port
| 4,405 |
||
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/datatypes.py
|
colon_separated_user_group
|
(arg)
|
Find a user ID and group ID from a string like 'user:group'. Returns
a tuple (uid, gid). If the string only contains a user like 'user'
then (uid, -1) will be returned. Raises ValueError if either
the user or group can't be resolved to valid IDs on the system.
|
Find a user ID and group ID from a string like 'user:group'. Returns
a tuple (uid, gid). If the string only contains a user like 'user'
then (uid, -1) will be returned. Raises ValueError if either
the user or group can't be resolved to valid IDs on the system.
| 278 | 293 |
def colon_separated_user_group(arg):
""" Find a user ID and group ID from a string like 'user:group'. Returns
a tuple (uid, gid). If the string only contains a user like 'user'
then (uid, -1) will be returned. Raises ValueError if either
the user or group can't be resolved to valid IDs on the system. """
try:
parts = arg.split(':', 1)
if len(parts) == 1:
uid = name_to_uid(parts[0])
gid = -1
else:
uid = name_to_uid(parts[0])
gid = name_to_gid(parts[1])
return (uid, gid)
except:
raise ValueError('Invalid user:group definition %s' % arg)
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/datatypes.py#L278-L293
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
11,
12,
13,
14,
15
] | 93.75 |
[] | 0 | false | 100 | 16 | 3 | 100 | 4 |
def colon_separated_user_group(arg):
try:
parts = arg.split(':', 1)
if len(parts) == 1:
uid = name_to_uid(parts[0])
gid = -1
else:
uid = name_to_uid(parts[0])
gid = name_to_gid(parts[1])
return (uid, gid)
except:
raise ValueError('Invalid user:group definition %s' % arg)
| 4,406 |
|
Supervisor/supervisor
|
a7cb60d58b5eb610feb76c675208f87501d4bc4b
|
supervisor/datatypes.py
|
name_to_uid
|
(name)
|
return uid
|
Find a user ID from a string containing a user name or ID.
Raises ValueError if the string can't be resolved to a valid
user ID on the system.
|
Find a user ID from a string containing a user name or ID.
Raises ValueError if the string can't be resolved to a valid
user ID on the system.
| 295 | 312 |
def name_to_uid(name):
""" Find a user ID from a string containing a user name or ID.
Raises ValueError if the string can't be resolved to a valid
user ID on the system. """
try:
uid = int(name)
except ValueError:
try:
pwdrec = pwd.getpwnam(name)
except KeyError:
raise ValueError("Invalid user name %s" % name)
uid = pwdrec[2]
else:
try:
pwd.getpwuid(uid) # check if uid is valid
except KeyError:
raise ValueError("Invalid user id %s" % name)
return uid
|
https://github.com/Supervisor/supervisor/blob/a7cb60d58b5eb610feb76c675208f87501d4bc4b/project6/supervisor/datatypes.py#L295-L312
| 6 |
[
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
13,
14,
15,
16,
17
] | 94.444444 |
[] | 0 | false | 100 | 18 | 4 | 100 | 3 |
def name_to_uid(name):
try:
uid = int(name)
except ValueError:
try:
pwdrec = pwd.getpwnam(name)
except KeyError:
raise ValueError("Invalid user name %s" % name)
uid = pwdrec[2]
else:
try:
pwd.getpwuid(uid) # check if uid is valid
except KeyError:
raise ValueError("Invalid user id %s" % name)
return uid
| 4,407 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.