Browse Source

Use the print function from __future__

This should make it easier to port to python3 later
pull/5/head
George Vlahavas 9 years ago
parent
commit
e214b54c5e
  1. 128
      src/xdgmenumaker

128
src/xdgmenumaker

@ -1,6 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python
# coding: utf-8 # coding: utf-8
from __future__ import print_function
import os import os
import sys import sys
import getopt import getopt
@ -131,24 +133,24 @@ def main(argv):
sys.exit(2) sys.exit(2)
def usage(): def usage():
print 'USAGE:', os.path.basename(sys.argv[0]), '[OPTIONS]' print('USAGE:', os.path.basename(sys.argv[0]), '[OPTIONS]')
print print()
print 'OPTIONS:' print('OPTIONS:')
print ' -f, --format the output format to use.' print(' -f, --format the output format to use.')
print ' Valid options are fluxbox, icewm,' print(' Valid options are fluxbox, icewm,')
print ' jwm, windowmaker and pekwm' print(' jwm, windowmaker and pekwm')
print ' -i, --icons enable support for icons in the' print(' -i, --icons enable support for icons in the')
print ' menus. Does not work with windowmaker' print(' menus. Does not work with windowmaker')
print ' -s, --size preferred icon size in pixels (default: 16)' print(' -s, --size preferred icon size in pixels (default: 16)')
print ' -n, --no-submenu do not create a submenu. Does not work with' print(' -n, --no-submenu do not create a submenu. Does not work with')
print ' windowmaker' print(' windowmaker')
print ' --pekwm-dynamic generate dynamic menus for pekwm' print(' --pekwm-dynamic generate dynamic menus for pekwm')
print ' -h, --help show this help message' print(' -h, --help show this help message')
print ' You have to specify the output format using the -f switch.' print(' You have to specify the output format using the -f switch.')
print print()
print 'EXAMPLES:' print('EXAMPLES:')
print ' xdgmenumaker -f windowmaker' print(' xdgmenumaker -f windowmaker')
print ' xdgmenumaker -i -f fluxbox' print(' xdgmenumaker -i -f fluxbox')
class MenuEntry: class MenuEntry:
def __init__(self, category, name, icon, command, path): def __init__(self, category, name, icon, command, path):
@ -341,11 +343,11 @@ def fluxboxmenu():
if seticon: if seticon:
app_icon = icon_full_path(applications_icon) app_icon = icon_full_path(applications_icon)
if app_icon is None: if app_icon is None:
print '[submenu] ('+applications+')' print('[submenu] ('+applications+')')
else: else:
print '[submenu] ('+applications+') <'+app_icon+'>' print('[submenu] ('+applications+') <'+app_icon+'>')
else: else:
print '[submenu] ('+applications+')' print('[submenu] ('+applications+')')
else: else:
spacing = '' spacing = ''
for i in menu(): for i in menu():
@ -354,11 +356,11 @@ def fluxboxmenu():
cat_icon = category_icon(category) cat_icon = category_icon(category)
cat_icon = icon_full_path(cat_icon) cat_icon = icon_full_path(cat_icon)
if cat_icon: if cat_icon:
print spacing+'[submenu] ('+category+') <'+cat_icon+'>' print(spacing+'[submenu] ('+category+') <'+cat_icon+'>')
else: else:
print spacing+'[submenu] ('+category+')' print(spacing+'[submenu] ('+category+')')
else: else:
print spacing+'[submenu] ('+category+')' print(spacing+'[submenu] ('+category+')')
for j in i[1]: for j in i[1]:
# closing parentheses need to be escaped, otherwise they are # closing parentheses need to be escaped, otherwise they are
# cropped out, along with everything that comes after them # cropped out, along with everything that comes after them
@ -369,24 +371,24 @@ def fluxboxmenu():
if path is not None: if path is not None:
command = 'cd '+path+' ; '+command command = 'cd '+path+' ; '+command
if icon is None: if icon is None:
print spacing+' [exec] ('+name+') {'+command+'}' print(spacing+' [exec] ('+name+') {'+command+'}')
else: else:
print spacing+' [exec] ('+name+') {'+command+'} <'+icon+'>' print(spacing+' [exec] ('+name+') {'+command+'} <'+icon+'>')
print spacing+'[end] # ('+category+')' print(spacing+'[end] # ('+category+')')
if submenu: if submenu:
print '[end] # ('+applications+')' print('[end] # ('+applications+')')
def windowmakermenu(): def windowmakermenu():
print '"'+applications+'" MENU' print('"'+applications+'" MENU')
for i in menu(): for i in menu():
category = i[0] category = i[0]
print ' "'+category+'" MENU' print(' "'+category+'" MENU')
for j in i[1]: for j in i[1]:
name = j[0] name = j[0]
command = j[2] command = j[2]
print ' "'+name+'" EXEC '+command print(' "'+name+'" EXEC '+command)
print ' "'+category+'" END' print(' "'+category+'" END')
print '"'+applications+'" END' print('"'+applications+'" END')
def icewmmenu(): def icewmmenu():
if submenu: if submenu:
@ -395,9 +397,9 @@ def icewmmenu():
app_icon = icon_full_path(applications_icon) app_icon = icon_full_path(applications_icon)
if app_icon is None: if app_icon is None:
app_icon = "_none_" app_icon = "_none_"
print 'menu "'+applications+'" '+app_icon+' {' print('menu "'+applications+'" '+app_icon+' {')
else: else:
print 'menu "'+applications+'" _none_ {' print('menu "'+applications+'" _none_ {')
else: else:
spacing = '' spacing = ''
for i in menu(): for i in menu():
@ -405,24 +407,24 @@ def icewmmenu():
cat_icon = category_icon(category) cat_icon = category_icon(category)
cat_icon = icon_full_path(cat_icon) cat_icon = icon_full_path(cat_icon)
if seticon and cat_icon is not None: if seticon and cat_icon is not None:
print spacing+'menu "'+category+'" '+cat_icon+' {' print(spacing+'menu "'+category+'" '+cat_icon+' {')
else: else:
print spacing+'menu "'+category+'" _none_ {' print(spacing+'menu "'+category+'" _none_ {')
for j in i[1]: for j in i[1]:
name = j[0] name = j[0]
icon = j[1] icon = j[1]
command = j[2] command = j[2]
if seticon and icon is not None: if seticon and icon is not None:
print spacing+' prog "'+name+'" '+icon+' '+command print(spacing+' prog "'+name+'" '+icon+' '+command)
else: else:
print spacing+' prog "'+name+'" _none_ '+command print(spacing+' prog "'+name+'" _none_ '+command)
print spacing+'}' print(spacing+'}')
if submenu: if submenu:
print '}' print('}')
def pekwmmenu(): def pekwmmenu():
if pekwmdynamic: if pekwmdynamic:
print "Dynamic {" print("Dynamic {")
dspacing = ' ' dspacing = ' '
else: else:
dspacing = '' dspacing = ''
@ -430,9 +432,9 @@ def pekwmmenu():
spacing = ' ' spacing = ' '
if seticon: if seticon:
app_icon = icon_full_path(applications_icon) app_icon = icon_full_path(applications_icon)
print dspacing+'Submenu = "'+applications+'" { Icon = "'+app_icon+'"' print(dspacing+'Submenu = "'+applications+'" { Icon = "'+app_icon+'"')
else: else:
print dspacing+'Submenu = "'+applications+'" {' print(dspacing+'Submenu = "'+applications+'" {')
else: else:
spacing = '' spacing = ''
for i in menu(): for i in menu():
@ -440,9 +442,9 @@ def pekwmmenu():
cat_icon = category_icon(category) cat_icon = category_icon(category)
cat_icon = icon_full_path(cat_icon) cat_icon = icon_full_path(cat_icon)
if seticon and cat_icon is not None: if seticon and cat_icon is not None:
print dspacing+spacing+'Submenu = "'+category+'" { Icon = "'+cat_icon+'"' print(dspacing+spacing+'Submenu = "'+category+'" { Icon = "'+cat_icon+'"')
else: else:
print dspacing+spacing+'Submenu = "'+category+'" {' print(dspacing+spacing+'Submenu = "'+category+'" {')
for j in i[1]: for j in i[1]:
name = j[0] name = j[0]
icon = j[1] icon = j[1]
@ -458,28 +460,28 @@ def pekwmmenu():
# path does not exist # path does not exist
command = 'cd '+path+' && '+command+' || '+command command = 'cd '+path+' && '+command+' || '+command
if seticon and icon is not None: if seticon and icon is not None:
print dspacing+spacing+' Entry = "'+name+'" { Icon = "'+icon+'"; Actions = "Exec '+command+' &" }' print(dspacing+spacing+' Entry = "'+name+'" { Icon = "'+icon+'"; Actions = "Exec '+command+' &" }')
else: else:
print dspacing+spacing+' Entry = "'+name+'" { Actions = "Exec '+command+' &" }' print(dspacing+spacing+' Entry = "'+name+'" { Actions = "Exec '+command+' &" }')
print dspacing+spacing+'}' print(dspacing+spacing+'}')
if submenu: if submenu:
print dspacing+'}' print(dspacing+'}')
if pekwmdynamic: if pekwmdynamic:
print "}" print("}")
def jwmmenu(): def jwmmenu():
print '<?xml version="1.0"?>' print('<?xml version="1.0"?>')
print '<JWM>' print('<JWM>')
if submenu: if submenu:
spacing = ' ' spacing = ' '
if seticon: if seticon:
app_icon = icon_full_path(applications_icon) app_icon = icon_full_path(applications_icon)
if app_icon is None: if app_icon is None:
print '<Menu label="'+applications+'">' print('<Menu label="'+applications+'">')
else: else:
print '<Menu icon="'+app_icon+'" label="'+applications+'">' print('<Menu icon="'+app_icon+'" label="'+applications+'">')
else: else:
print '<Menu label="'+applications+'">' print('<Menu label="'+applications+'">')
else: else:
spacing = '' spacing = ''
for i in menu(): for i in menu():
@ -487,9 +489,9 @@ def jwmmenu():
cat_icon = category_icon(category) cat_icon = category_icon(category)
cat_icon = icon_full_path(cat_icon) cat_icon = icon_full_path(cat_icon)
if seticon and cat_icon is not None: if seticon and cat_icon is not None:
print spacing+'<Menu icon="'+cat_icon+'" label="'+category+'">' print(spacing+'<Menu icon="'+cat_icon+'" label="'+category+'">')
else: else:
print spacing+'<Menu label="'+category+'">' print(spacing+'<Menu label="'+category+'">')
for j in i[1]: for j in i[1]:
name = j[0] name = j[0]
icon = j[1] icon = j[1]
@ -498,13 +500,13 @@ def jwmmenu():
if path is not None: if path is not None:
command = 'cd '+path+' ; '+command command = 'cd '+path+' ; '+command
if seticon and icon is not None: if seticon and icon is not None:
print spacing+' <Program icon="'+icon+'" label="'+name+'">'+command+'</Program>' print(spacing+' <Program icon="'+icon+'" label="'+name+'">'+command+'</Program>')
else: else:
print spacing+' <Program label="'+name+'">'+command+'</Program>' print(spacing+' <Program label="'+name+'">'+command+'</Program>')
print spacing+'</Menu>' print(spacing+'</Menu>')
if submenu: if submenu:
print '</Menu>' print('</Menu>')
print '</JWM>' print('</JWM>')
if __name__ == "__main__": if __name__ == "__main__":
main(sys.argv[1:]) main(sys.argv[1:])

Loading…
Cancel
Save