From aa3375fc3850af904c5562eb6cee0d41d6e3d635 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 17 Apr 2018 15:31:24 +0200 Subject: [PATCH] switch packaged python scripts to python3 --- openbox-python3.patch | 113 ++++++++++++++++++++++++++++++++++++++++++ openbox.spec | 6 ++- xdg-menu | 32 ++++++------ 3 files changed, 135 insertions(+), 16 deletions(-) create mode 100644 openbox-python3.patch diff --git a/openbox-python3.patch b/openbox-python3.patch new file mode 100644 index 0000000..f17bef3 --- /dev/null +++ b/openbox-python3.patch @@ -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__": diff --git a/openbox.spec b/openbox.spec index e36015e..8ce9d73 100644 --- a/openbox.spec +++ b/openbox.spec @@ -11,11 +11,14 @@ Source1: http://icculus.org/openbox/tools/setlayout.c Source2: xdg-menu Source3: menu.xml Source4: terminals.menu +Patch1: openbox-python3.patch Requires: %{name}-libs%{?_isa} = %{version}-%{release} # 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 Requires: redhat-menus @@ -93,6 +96,7 @@ KDE session. %prep %setup -q +%patch1 -p1 -b .python3 %build diff --git a/xdg-menu b/xdg-menu index b3e5da0..ccd0efd 100644 --- a/xdg-menu +++ b/xdg-menu @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # # Copyright (C) 2008 Red Hat, Inc. # @@ -26,6 +26,8 @@ from xml.sax.saxutils import escape icons = True try: + import gi + gi.require_version('Gtk', '3.0') from gi.repository import Gtk except ImportError: icons = False @@ -54,7 +56,7 @@ def icon_attr(entry): return '' def escape_utf8(s): - if isinstance(s, unicode): + if sys.version_info[0] < 3 and isinstance(s, unicode): s = s.encode('utf-8', 'xmlcharrefreplace') return escape(s) @@ -63,25 +65,25 @@ def entry_name(entry): def walk_menu(entry): if isinstance(entry, xdg.Menu.Menu) and entry.Show is True: - print '' \ + print('' \ % (entry_name(entry), entry_name(entry), - escape_utf8(icon_attr(entry))) - map(walk_menu, entry.getEntries()) - print '' + escape_utf8(icon_attr(entry)))) + list(map(walk_menu, entry.getEntries())) + print('') elif isinstance(entry, xdg.Menu.MenuEntry) and entry.Show is True: name = entry_name(entry.DesktopEntry) - print ' ' % (name.replace('"', ''), - escape_utf8(icon_attr(entry.DesktopEntry))) + print(' ' % (name.replace('"', ''), + escape_utf8(icon_attr(entry.DesktopEntry)))) command = re.sub(' -caption "%c"| -caption %c', ' -caption "%s"' % name, escape_utf8(entry.DesktopEntry.getExec())) command = re.sub(' [^ ]*%[fFuUdDnNickvm]', '', command) if entry.DesktopEntry.getTerminal(): command = 'xterm -title "%s" -e %s' % (name, command) - print ' ' + \ - '%s' % command - print ' ' + print(' ' + \ + '%s' % command) + print(' ') if len(sys.argv) > 1: menufile = sys.argv[1] + '.menu' @@ -100,7 +102,7 @@ if icons: menu = xdg.Menu.parse(menufile) -print '' -print '' -map(walk_menu, menu.getEntries()) -print '' +print('') +print('') +list(map(walk_menu, menu.getEntries())) +print('')