2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-23 10:37:27 +00:00
apparmor/Tools/aa-cleanprof.py

42 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/python
import os
import argparse
import apparmor.aa as apparmor
parser = argparse.ArgumentParser(description='Cleanup the profiles for the given programs')
parser.add_argument('-d', type=str, help='path to profiles')
parser.add_argument('program', type=str, nargs='+', help='name of program')
args = parser.parse_args()
profiling = args.program
profiledir = args.d
if profiledir:
apparmor.profile_dir = apparmor.get_full_path(profiledir)
if not os.path.isdir(apparmor.profile_dir):
2013-08-26 00:41:15 +05:30
raise apparmor.AppArmorException("%s is not a directory."%profiledir)
2013-08-26 00:41:15 +05:30
for p in sorted(profiling):
if not p:
continue
program = None
if os.path.exists(p):
program = apparmor.get_full_path(p).strip()
else:
which = apparmor.which(p)
if which:
program = apparmor.get_full_path(which)
if os.path.exists(program):
apparmor.read_profiles()
filename = apparmor.get_profile_filename(program)
2013-08-26 00:41:15 +05:30
if filename:
apparmor.write_profile_ui_feedback(program)
apparmor.reload_base(program)
else:
2013-08-26 00:41:15 +05:30
raise apparmor.AppArmorException(_('The profile for %s does not exists. Nothing to clean.')%p)