Merge "Expose caps values/names as int enum"

This commit is contained in:
Zuul 2017-12-15 14:54:30 +00:00 committed by Gerrit Code Review
commit e93b540996
1 changed files with 54 additions and 48 deletions

View File

@ -12,11 +12,15 @@
# License for the specific language governing permissions and limitations
# under the License.
import enum
import os
import platform
import sys
import cffi
class Capabilities(enum.IntEnum):
# Generated with:
# awk '/^#define CAP_[A-Z_]+[ \t]+[0-9]+/ {print $2,"=",$3}' \
# include/uapi/linux/capability.h
@ -62,13 +66,15 @@ CAP_BLOCK_SUSPEND = 36
CAP_AUDIT_READ = 37
# Convenience dicts for human readable values
CAPS_BYNAME = {}
CAPS_BYVALUE = {}
for k, v in globals().copy().items():
if k.startswith('CAP_'):
CAPS_BYNAME[k] = v
CAPS_BYVALUE[v] = k
module = sys.modules[__name__]
# Convenience dicts for human readable values
# module attributes for backwards compat/convenience
for c in Capabilities:
CAPS_BYNAME[c.name] = c.value
CAPS_BYVALUE[c.value] = c.name
setattr(module, c.name, c.value)
CDEF = '''
/* Edited highlights from `echo '#include <sys/capability.h>' | gcc -E -` */