[apparmor] [patch] common.py: add recursive_print()

Jamie Strandboge jamie at canonical.com
Thu Feb 27 20:29:35 UTC 2014


On 02/27/2014 02:04 PM, Christian Boltz wrote:
> Hello,
> 
> Am Donnerstag, 27. Februar 2014 schrieb Jamie Strandboge:
>> On 02/26/2014 06:48 PM, Christian Boltz wrote:
>>> this patch adds recursive_print() to common.py.
>>>
>>> It prints a data structure in an easily readable output and is quite
>>> useful[1] for debugging. However, I don't recommend to call it in
>>> production code ;-)
>>
>> Is pprint not an option?
> 
> Not really - I gave it a short test, but it resulted in a very long line.
> Here's the head -c1000 of pprint'ing "aa", the hasher that stores all
> profiles:
> 
> defaultdict(<function hasher at 0x1e9d320>, {u'/usr/lib/Adobe/Reader9/Reader/intellinux/bin/acroread': defaultdict(<function hasher at 0x1e9d320>, {u'/usr/lib/Adobe/Reader9/Reader/intellinux/bin/acroread': defaultdict(<function hasher at 0x1e9d320>, {'deny': defaultdict(<function hasher at 0x1e9d320>, {'path': defaultdict(<function hasher at 0x1e9d320>, {u'/dev/shm/pulse-shm-*': defaultdict(<function hasher at 0x1e9d320>, {'audit': set([]), 'mode': set(['::w', 'w'])}), u'/home/cb/.thumbnails/**': defaultdict(<function hasher at 0x1e9d320>, {'audit': set([]), 'mode': set(['r', '::r'])}), u'/home/cb/.pulse/': defaultdict(<function hasher at 0x1e9d320>, {'audit': set([]), 'mode': set(['::w', 'r', '::r', 'w'])}), u'/etc/fstab': defaultdict(<function hasher at 0x1e9d320>, {'audit': set([]), 'mode': set(['r', '::r'])}), u'/home/cb/.pulse-cookie': defaultdict(<function hasher at 0x1e9d320>, {'audit': set([]), 'mode': set(['::w', 'k', '::r', 'r', '::k', 'w'])})})}), 
> 
> That's not very readable IMHO ;-)
> 
> (If there's an option to add newlines at the right[tm] place and I just 
> didn't find it, please tell me ;-)
> 

Hmmm, pprint has formatting options; I'm not sure why they wouldn't be working
for you. From http://docs.python.org/3/library/pprint.html:

"pprint.pprint(object, stream=None, indent=1, width=80, depth=None)

    Prints the formatted representation of object on stream, followed by a
newline. If stream is None, sys.stdout is used. This may be used in the
interactive interpreter instead of the print() function for inspecting values
(you can even reassign print = pprint.pprint for use within a scope). indent,
width and depth will be passed to the PrettyPrinter constructor as formatting
parameters."

http://stackoverflow.com/questions/8168654/python-pprint-issues suggested using
a width of '1'.

-- 
Jamie Strandboge                 http://www.ubuntu.com/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 884 bytes
Desc: OpenPGP digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20140227/b5cdf2af/attachment.pgp>


More information about the AppArmor mailing list