switch packaged python scripts to python3

epel9
Miroslav Lichvar 7 years ago
parent 570af1dcf7
commit aa3375fc38

@ -0,0 +1,113 @@
diff -up openbox-3.6.1/data/autostart/openbox-xdg-autostart.python3 openbox-3.6.1/data/autostart/openbox-xdg-autostart
--- openbox-3.6.1/data/autostart/openbox-xdg-autostart.python3 2013-04-17 14:27:27.000000000 +0200
+++ openbox-3.6.1/data/autostart/openbox-xdg-autostart 2018-04-17 15:52:23.849765020 +0200
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
# openbox-xdg-autostart runs things based on the XDG autostart specification
# Copyright (C) 2008 Dana Jansens
@@ -28,9 +28,9 @@ try:
from xdg.DesktopEntry import DesktopEntry
from xdg.Exceptions import ParsingError
except ImportError:
- print
- print >>sys.stderr, "ERROR:", ME, "requires PyXDG to be installed"
- print
+ print()
+ print("ERROR:", ME, "requires PyXDG to be installed", file=sys.stderr)
+ print()
sys.exit(1)
def main(argv=sys.argv):
@@ -51,7 +51,7 @@ def main(argv=sys.argv):
try:
autofile = AutostartFile(path)
except ParsingError:
- print "Invalid .desktop file: " + path
+ print("Invalid .desktop file: " + path)
else:
if not autofile in files:
files.append(autofile)
@@ -99,9 +99,9 @@ class AutostartFile:
def _alert(self, str, info=False):
if info:
- print "\t ", str
+ print("\t ", str)
else:
- print "\t*", str
+ print("\t*", str)
def _showInEnvironment(self, envs, verbose=False):
default = not self.de.getOnlyShowIn()
@@ -146,9 +146,9 @@ class AutostartFile:
def display(self, envs):
if self._shouldRun(envs):
- print "[*] " + self.de.getName()
+ print("[*] " + self.de.getName())
else:
- print "[ ] " + self.de.getName()
+ print("[ ] " + self.de.getName())
self._alert("File: " + self.path, info=True)
if self.de.getExec():
self._alert("Executes: " + self.de.getExec(), info=True)
@@ -165,33 +165,33 @@ class AutostartFile:
os.chdir(here)
def show_help():
- print "Usage:", ME, "[OPTION]... [ENVIRONMENT]..."
- print
- print "This tool will run xdg autostart .desktop files"
- print
- print "OPTIONS"
- print " --list Show a list of the files which would be run"
- print " Files which would be run are marked with an asterix"
- print " symbol [*]. For files which would not be run,"
- print " information is given for why they are excluded"
- print " --help Show this help and exit"
- print " --version Show version and copyright information"
- print
- print "ENVIRONMENT specifies a list of environments for which to run autostart"
- print "applications. If none are specified, only applications which do not "
- print "limit themselves to certain environments will be run."
- print
- print "ENVIRONMENT can be one or more of:"
- print " GNOME Gnome Desktop"
- print " KDE KDE Desktop"
- print " ROX ROX Desktop"
- print " XFCE XFCE Desktop"
- print " Old Legacy systems"
+ print("Usage:", ME, "[OPTION]... [ENVIRONMENT]...")
+ print()
+ print("This tool will run xdg autostart .desktop files")
+ print()
+ print("OPTIONS")
+ print(" --list Show a list of the files which would be run")
+ print(" Files which would be run are marked with an asterix")
+ print(" symbol [*]. For files which would not be run,")
+ print(" information is given for why they are excluded")
+ print(" --help Show this help and exit")
+ print(" --version Show version and copyright information")
+ print()
+ print("ENVIRONMENT specifies a list of environments for which to run autostart")
+ print("applications. If none are specified, only applications which do not ")
+ print("limit themselves to certain environments will be run.")
+ print
+ print("ENVIRONMENT can be one or more of:")
+ print(" GNOME Gnome Desktop")
+ print(" KDE KDE Desktop")
+ print(" ROX ROX Desktop")
+ print(" XFCE XFCE Desktop")
+ print(" Old Legacy systems")
print
def show_version():
- print ME, VERSION
- print "Copyright (c) 2008 Dana Jansens"
+ print(ME, VERSION)
+ print("Copyright (c) 2008 Dana Jansens")
print
if __name__ == "__main__":

@ -11,11 +11,14 @@ Source1: http://icculus.org/openbox/tools/setlayout.c
Source2: xdg-menu Source2: xdg-menu
Source3: menu.xml Source3: menu.xml
Source4: terminals.menu Source4: terminals.menu
Patch1: openbox-python3.patch
Requires: %{name}-libs%{?_isa} = %{version}-%{release} Requires: %{name}-libs%{?_isa} = %{version}-%{release}
# required by xdg-menu and xdg-autostart scripts # required by xdg-menu and xdg-autostart scripts
Requires: pyxdg Requires: python3-xdg
# used by xdg-menu for icon support (optional)
Suggests: python3-gobject
# as discussed in https://bugzilla.redhat.com/860997 # as discussed in https://bugzilla.redhat.com/860997
Requires: redhat-menus Requires: redhat-menus
@ -93,6 +96,7 @@ KDE session.
%prep %prep
%setup -q %setup -q
%patch1 -p1 -b .python3
%build %build

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# Copyright (C) 2008 Red Hat, Inc. # Copyright (C) 2008 Red Hat, Inc.
# #
@ -26,6 +26,8 @@ from xml.sax.saxutils import escape
icons = True icons = True
try: try:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk from gi.repository import Gtk
except ImportError: except ImportError:
icons = False icons = False
@ -54,7 +56,7 @@ def icon_attr(entry):
return '' return ''
def escape_utf8(s): def escape_utf8(s):
if isinstance(s, unicode): if sys.version_info[0] < 3 and isinstance(s, unicode):
s = s.encode('utf-8', 'xmlcharrefreplace') s = s.encode('utf-8', 'xmlcharrefreplace')
return escape(s) return escape(s)
@ -63,25 +65,25 @@ def entry_name(entry):
def walk_menu(entry): def walk_menu(entry):
if isinstance(entry, xdg.Menu.Menu) and entry.Show is True: if isinstance(entry, xdg.Menu.Menu) and entry.Show is True:
print '<menu id="%s" label="%s"%s>' \ print('<menu id="%s" label="%s"%s>' \
% (entry_name(entry), % (entry_name(entry),
entry_name(entry), entry_name(entry),
escape_utf8(icon_attr(entry))) escape_utf8(icon_attr(entry))))
map(walk_menu, entry.getEntries()) list(map(walk_menu, entry.getEntries()))
print '</menu>' print('</menu>')
elif isinstance(entry, xdg.Menu.MenuEntry) and entry.Show is True: elif isinstance(entry, xdg.Menu.MenuEntry) and entry.Show is True:
name = entry_name(entry.DesktopEntry) name = entry_name(entry.DesktopEntry)
print ' <item label="%s"%s>' % (name.replace('"', ''), print(' <item label="%s"%s>' % (name.replace('"', ''),
escape_utf8(icon_attr(entry.DesktopEntry))) escape_utf8(icon_attr(entry.DesktopEntry))))
command = re.sub(' -caption "%c"| -caption %c', command = re.sub(' -caption "%c"| -caption %c',
' -caption "%s"' % name, ' -caption "%s"' % name,
escape_utf8(entry.DesktopEntry.getExec())) escape_utf8(entry.DesktopEntry.getExec()))
command = re.sub(' [^ ]*%[fFuUdDnNickvm]', '', command) command = re.sub(' [^ ]*%[fFuUdDnNickvm]', '', command)
if entry.DesktopEntry.getTerminal(): if entry.DesktopEntry.getTerminal():
command = 'xterm -title "%s" -e %s' % (name, command) command = 'xterm -title "%s" -e %s' % (name, command)
print ' <action name="Execute">' + \ print(' <action name="Execute">' + \
'<command>%s</command></action>' % command '<command>%s</command></action>' % command)
print ' </item>' print(' </item>')
if len(sys.argv) > 1: if len(sys.argv) > 1:
menufile = sys.argv[1] + '.menu' menufile = sys.argv[1] + '.menu'
@ -100,7 +102,7 @@ if icons:
menu = xdg.Menu.parse(menufile) menu = xdg.Menu.parse(menufile)
print '<?xml version="1.0" encoding="UTF-8"?>' print('<?xml version="1.0" encoding="UTF-8"?>')
print '<openbox_pipe_menu>' print('<openbox_pipe_menu>')
map(walk_menu, menu.getEntries()) list(map(walk_menu, menu.getEntries()))
print '</openbox_pipe_menu>' print('</openbox_pipe_menu>')

Loading…
Cancel
Save