diff --exclude-from=exclude -N -u -r nsalibselinux/src/selinuxswig_python.i libselinux-2.0.76/src/selinuxswig_python.i --- nsalibselinux/src/selinuxswig_python.i 2008-08-28 09:34:24.000000000 -0400 +++ libselinux-2.0.76/src/selinuxswig_python.i 2008-12-02 09:14:48.000000000 -0500 @@ -6,6 +6,32 @@ #include "selinux/selinux.h" %} +%pythoncode %{ + +import shutil, os, stat + +def restorecon(path, recursive=False): + """ Restore SELinux context on a given path """ + mode = os.lstat(path)[stat.ST_MODE] + status, context = matchpathcon(path, mode) + if status == 0: + lsetfilecon(path, context) + if recursive: + os.path.walk(path, lambda arg, dirname, fnames: + map(restorecon, [os.path.join(dirname, fname) + for fname in fnames]), None) + +def copytree(src, dest): + """ An SELinux-friendly shutil.copytree method """ + shutil.copytree(src, dest) + restorecon(dest, recursive=True) + +def install(src, dest): + """ An SELinux-friendly shutil.move method """ + shutil.move(src, dest) + restorecon(dest, recursive=True) +%} + /* security_get_boolean_names() typemap */ %typemap(argout) (char ***names, int *len) { PyObject* list = PyList_New(*$2);