diff options
author | Ben Pfaff <blp@nicira.com> | 2010-08-25 10:26:40 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2010-08-25 14:55:48 -0700 |
commit | 991559357f6a03c3a5b70c053c8c2554aa8d5ee4 (patch) | |
tree | 8731002433c65ea41dbe94648c0e39737f666469 /python/ovs/process.py | |
parent | d1b680c61626595b2777f4bf25997a9178acb60c (diff) |
Implement initial Python bindings for Open vSwitch database.
These initial bindings pass a few hundred of the corresponding tests
for C implementations of various bits of the Open vSwitch library API.
The poorest part of them is actually the Python IDL interface in
ovs.db.idl, which has not received enough attention yet. It appears
to work, but it doesn't yet support writes (transactions) and it is
difficult to use. I hope to improve it as it becomes clear what
semantics Python applications actually want from an IDL.
Diffstat (limited to 'python/ovs/process.py')
-rw-r--r-- | python/ovs/process.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/python/ovs/process.py b/python/ovs/process.py new file mode 100644 index 00000000..094e0853 --- /dev/null +++ b/python/ovs/process.py @@ -0,0 +1,39 @@ +# Copyright (c) 2010 Nicira Networks +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import signal + +def _signal_status_msg(type, signr): + s = "%s by signal %d" % (type, signr) + for name in signal.__dict__: + if name.startswith("SIG") and signal.__dict__[name] == signr: + return "%s (%s)" % (s, name) + return s + +def status_msg(status): + """Given 'status', which is a process status in the form reported by + waitpid(2) and returned by process_status(), returns a string describing + how the process terminated.""" + if os.WIFEXITED(status): + s = "exit status %d" % os.WEXITSTATUS(status) + elif os.WIFSIGNALED(status): + s = _signal_status_msg("killed", os.WTERMSIG(status)) + elif os.WIFSTOPPED(status): + s = _signal_status_msg("stopped", os.WSTOPSIG(status)) + else: + s = "terminated abnormally (%x)" % status + if os.WCOREDUMP(status): + s += ", core dumped" + return s |