Oxford Automation Sprint - 2009

Gnome Menu Application Launching

Specification for Automation

Problems found

   1 #!/usr/bin/python
   2 """
   3 Simple python script that shows how to get the list of currently
   4 installed applications listed in the menu using gmenu 
   5 """
   6 import sys, optparse, gmenu
   7 
   8 def main(argv):
   9     options = parse_options(argv)
  10 
  11     tree = gmenu.lookup_tree(options.menu)
  12     root = tree.root
  13 
  14     applications = []
  15     if isinstance(root, gmenu.Directory):
  16         add_directory_apps(root, applications)
  17 
  18     for app in applications:
  19         print ("Name: '%s'\n"
  20                "Exec: '%s'"
  21                % (app.get_name(),
  22                   app.get_exec()))
  23         
  24 def add_directory_apps(dir, apps):
  25     """
  26     Explore directories recursively and append every application found
  27     in to the list of applications 
  28     """    
  29     contents = dir.get_contents()
  30     
  31     for object in contents:
  32         if isinstance(object, gmenu.Directory):
  33             add_directory_apps(object, apps)
  34         elif isinstance(object, gmenu.Entry):
  35             apps.append(object)
  36         else:
  37             print >> sys.stderr, "Skipping %s" % object
  38 
  39 def parse_options(argv):
  40     parser = optparse.OptionParser()
  41     parser.add_option('-m', '--menu',
  42                       default='applications.menu',
  43                       help=("Menu file to be used as root of the tree"
  44                             "('%default' by default)"))
  45     (options, args) = parser.parse_args(argv)
  46     return options
  47 
  48 
  49 if __name__ == "__main__":
  50     main(sys.argv)

Testing/Automation/OxfordSprint2009/App-Launching-Automation-Spec (last edited 2009-03-16 11:04:29 by 121)