[apparmor] [patch] Improve __repr__() for *Ruleset

Christian Boltz apparmor at cboltz.de
Mon Dec 21 22:10:35 UTC 2015


Hello,

if a *Ruleset is empty, let __repr__() print/return

    <FooRuleset (empty) />

instead of

    <FooRuleset>
</FooRuleset>


I propose this patch for trunk and 2.10.


[ 42-improve-repr-empty-ruleset.diff ]

=== modified file ./utils/apparmor/rule/__init__.py
--- utils/apparmor/rule/__init__.py     2015-12-21 00:42:28.521222690 +0100
+++ utils/apparmor/rule/__init__.py     2015-12-21 22:57:03.421574167 +0100
@@ -291,7 +291,10 @@
 
     def __repr__(self):
         classname = self.__class__.__name__
-        return '<%s>\n' % classname + '\n'.join(self.get_raw(1)) + '</%s>' % classname
+        if self.rules:
+            return '<%s>\n' % classname + '\n'.join(self.get_raw(1)) + '</%s>' % classname
+        else:
+            return '<%s (empty) />' % classname
 
     def add(self, rule):
         '''add a rule object'''


Regards,

Christian Boltz
-- 
> Kann mir jemand sagen, wie unter der neuen SuSE der inetd gestartet
> wird? [...]  Ich such mir hier einen Affen...
hmm, hier? Wo ist hier? Und wenn Du einen findest, was dann?
Was willst Du mit einem Affen? Welchen denn? Wieso hier?
Wenn Du einen findest, kannst ihn ja mal fragen...

Vielleicht hilfts Dir, wenn Du mal in /etc/init.d /etc/syconfig
/etc/rc.config.d usw. suchst. Achso ja, Affen hab ich da noch keinen
gesehen;)         [> Andreas Meyer und Bernd Obermayr in suse-linux]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20151221/89f6d141/attachment.pgp>


More information about the AppArmor mailing list