Hello, the rule classes have lots of
if self.all_foo: foo_txt = _('ALL') else: foo_txt = self.foo in logprof_header_localvars(). To avoid repeating this over and over, split it off to a logprof_value_or_all() function. This function can handle - str (will be returned unmodified - AARE (.regex will be used) - sets/lists/tuples (will be ' '.join()ed and sorted) Other types are returned unmodified. [ 51-split-off-logprof_value_or_all.diff ] === modified file ./utils/apparmor/rule/capability.py --- utils/apparmor/rule/capability.py 2015-12-21 00:42:28.521222690 +0100 +++ utils/apparmor/rule/capability.py 2015-12-26 22:41:41.280645388 +0100 @@ -15,7 +15,7 @@ from apparmor.regex import RE_PROFILE_CAP from apparmor.common import AppArmorBug, AppArmorException, type_is_str -from apparmor.rule import BaseRule, BaseRuleset, parse_modifiers +from apparmor.rule import BaseRule, BaseRuleset, logprof_value_or_all, parse_modifiers import re # setup module translations @@ -137,10 +137,7 @@ return severity def logprof_header_localvars(self): - if self.all_caps: - cap_txt = _('ALL') - else: - cap_txt = ' '.join(sorted(self.capability)) + cap_txt = logprof_value_or_all(self.capability, self.all_caps) return [ _('Capability'), cap_txt, === modified file ./utils/apparmor/rule/change_profile.py --- utils/apparmor/rule/change_profile.py 2015-12-21 00:42:28.521222690 +0100 +++ utils/apparmor/rule/change_profile.py 2015-12-26 22:15:17.763241151 +0100 @@ -15,7 +15,7 @@ from apparmor.regex import RE_PROFILE_CHANGE_PROFILE, strip_quotes from apparmor.common import AppArmorBug, AppArmorException, type_is_str -from apparmor.rule import BaseRule, BaseRuleset, parse_modifiers, quote_if_needed +from apparmor.rule import BaseRule, BaseRuleset, parse_modifiers, logprof_value_or_all, quote_if_needed # setup module translations from apparmor.translations import init_translation @@ -150,15 +150,8 @@ return True def logprof_header_localvars(self): - if self.all_execconds: - execcond_txt = _('ALL') - else: - execcond_txt = self.execcond - - if self.all_targetprofiles: - targetprofiles_txt = _('ALL') - else: - targetprofiles_txt = self.targetprofile + execcond_txt = logprof_value_or_all(self.execcond, self.all_execconds) + targetprofiles_txt = logprof_value_or_all(self.targetprofile, self.all_targetprofiles) return [ _('Exec Condition'), execcond_txt, === modified file ./utils/apparmor/rule/__init__.py --- utils/apparmor/rule/__init__.py 2015-12-23 21:50:28.363843471 +0100 +++ utils/apparmor/rule/__init__.py 2015-12-26 22:42:46.892223987 +0100 @@ -454,6 +454,20 @@ return result_list, False, unknown_items +def logprof_value_or_all(value, all_values): + '''helper for logprof_header() to return 'all' (if all_values is True) or the specified value. + For some types, the value is made more readable.''' + + if all_values: + return _('ALL') + + if type(value) == AARE: + return value.regex + elif type(value) == set or type(value) == list or type(value) == tuple: + return ' '.join(sorted(value)) + else: + return value + def parse_comment(matches): '''returns the comment (with a leading space) from the matches object''' comment = '' === modified file ./utils/apparmor/rule/network.py --- utils/apparmor/rule/network.py 2015-12-21 00:42:28.521222690 +0100 +++ utils/apparmor/rule/network.py 2015-12-26 22:17:23.914390761 +0100 @@ -17,7 +17,7 @@ from apparmor.regex import RE_PROFILE_NETWORK from apparmor.common import AppArmorBug, AppArmorException, type_is_str -from apparmor.rule import BaseRule, BaseRuleset, parse_modifiers +from apparmor.rule import BaseRule, BaseRuleset, logprof_value_or_all, parse_modifiers # setup module translations from apparmor.translations import init_translation @@ -179,15 +179,8 @@ return True def logprof_header_localvars(self): - if self.all_domains: - family = _('ALL') - else: - family = self.domain - - if self.all_type_or_protocols: - sock_type = _('ALL') - else: - sock_type = self.type_or_protocol + family = logprof_value_or_all(self.domain, self.all_domains) + sock_type = logprof_value_or_all(self.type_or_protocol, self.all_type_or_protocols) return [ _('Network Family'), family, === modified file ./utils/apparmor/rule/ptrace.py --- utils/apparmor/rule/ptrace.py 2015-12-23 21:50:28.363843471 +0100 +++ utils/apparmor/rule/ptrace.py 2015-12-26 22:31:16.648759523 +0100 @@ -16,7 +16,7 @@ from apparmor.regex import RE_PROFILE_PTRACE, RE_PROFILE_NAME from apparmor.common import AppArmorBug, AppArmorException -from apparmor.rule import BaseRule, BaseRuleset, check_and_split_list, parse_modifiers, quote_if_needed +from apparmor.rule import BaseRule, BaseRuleset, check_and_split_list, logprof_value_or_all, parse_modifiers, quote_if_needed # setup module translations from apparmor.translations import init_translation @@ -160,15 +160,8 @@ return True def logprof_header_localvars(self): - if self.all_access: - access = _('ALL') - else: - access = ' '.join(sorted(self.access)) - - if self.all_peers: - peer = _('ALL') - else: - peer = self.peer.regex + access = logprof_value_or_all(self.access,self.all_access) + peer = logprof_value_or_all(self.peer, self.all_peers) return [ _('Access mode'), access, === modified file ./utils/apparmor/rule/signal.py --- utils/apparmor/rule/signal.py 2015-12-23 21:50:28.363843471 +0100 +++ utils/apparmor/rule/signal.py 2015-12-26 22:33:12.363974781 +0100 @@ -16,7 +16,7 @@ from apparmor.regex import RE_PROFILE_SIGNAL, RE_PROFILE_NAME from apparmor.common import AppArmorBug, AppArmorException -from apparmor.rule import BaseRule, BaseRuleset, check_and_split_list, parse_modifiers, quote_if_needed +from apparmor.rule import BaseRule, BaseRuleset, check_and_split_list, logprof_value_or_all, parse_modifiers, quote_if_needed # setup module translations from apparmor.translations import init_translation @@ -214,20 +214,9 @@ return True def logprof_header_localvars(self): - if self.all_access: - access = _('ALL') - else: - access = ' '.join(sorted(self.access)) - - if self.all_signals: - signal = _('ALL') - else: - signal = ' '.join(sorted(self.signal)) - - if self.all_peers: - peer = _('ALL') - else: - peer = self.peer.regex + access = logprof_value_or_all(self.access, self.all_access) + signal = logprof_value_or_all(self.signal, self.all_signals) + peer = logprof_value_or_all(self.peer, self.all_peers) return [ _('Access mode'), access, Regards, Christian Boltz -- Java Call Stack Tief in der Scheisse [Patrick Schaaf, FdI#545]
signature.asc
Description: This is a digitally signed message part.
-- AppArmor mailing list AppArmor@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor