Advertisement
Guest User

S

a guest
Sep 6th, 2009
1,255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #
  3. # Copyright (C) 2008 Red Hat, Inc.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. # Author(s): Luke Macken <lmacken@redhat.com>
  19. # Miroslav Lichvar <mlichvar@redhat.com>
  20.  
  21.  
  22. import gmenu, re, sys
  23. from xml.sax.saxutils import escape
  24.  
  25. def walk_menu(entry):
  26. if entry.get_type() == gmenu.TYPE_DIRECTORY:
  27. print '<menu id="%s" label="%s">' \
  28. % (escape(entry.menu_id), escape(entry.get_name()))
  29. map(walk_menu, entry.get_contents())
  30. print '</menu>'
  31. elif entry.get_type() == gmenu.TYPE_ENTRY and not entry.is_excluded:
  32. print ' <item label="%s">' % escape(entry.get_name())
  33. command = re.sub(' [^ ]*%[fFuUdDnNickvm]', '', entry.get_exec())
  34. if entry.launch_in_terminal:
  35. command = 'xterm -title "%s" -e %s' % \
  36. (entry.get_name(), command)
  37. print ' <action name="Execute">' + \
  38. '<command>%s</command></action>' % escape(command)
  39. print ' </item>'
  40.  
  41. if len(sys.argv) > 1:
  42. menu = sys.argv[1] + '.menu'
  43. else:
  44. menu = 'applications.menu'
  45.  
  46. print '<?xml version="1.0" encoding="UTF-8"?>'
  47. print '<openbox_pipe_menu>'
  48. map(walk_menu, gmenu.lookup_tree(menu).root.get_contents())
  49. print '</openbox_pipe_menu>'
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement