Add introduction to section 6 plugins.
[libguestfs-talks.git] / 2011-seminar / 300-python / firefox.py
1 #!/usr/bin/python
2
3 import sys
4 import re
5 import guestfs
6
7 assert (len (sys.argv) == 2)
8 disk = sys.argv[1]
9
10 g = guestfs.GuestFS ()
11 g.add_drive_opts (disk, readonly=1)
12 g.launch ()
13
14 roots = g.inspect_os ()
15 if len (roots) == 0:
16     raise (Error ("inspect_vm: no operating systems found"))
17
18 for root in roots:
19     mps = g.inspect_get_mountpoints (root)
20     def compare (a, b):
21         if len(a[0]) > len(b[0]):
22             return 1
23         elif len(a[0]) == len(b[0]):
24             return 0
25         else:
26             return -1
27     mps.sort (compare)
28     for mp_dev in mps:
29         try:
30             g.mount_ro (mp_dev[1], mp_dev[0])
31         except RuntimeError as msg:
32             print "%s (ignored)" % msg
33
34     apps = g.inspect_list_applications (root)
35     for app in apps:
36         if re.search ('firefox', app['app_name'], re.I):
37             print ("'%s' version: %s" % (app['app_name'], app['app_version']))
38
39     g.umount_all ()