[X2Go-Commits] [nx-libs] 42/54: nxdialog: make code compatible to python2 _and_ python3

git-admin at x2go.org git-admin at x2go.org
Sun Mar 24 10:05:05 CET 2019


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository nx-libs.

commit acffe15b58c352914a63499d29a12f72671afc5b
Author: Ulrich Sibiller <uli42 at gmx.de>
Date:   Thu Feb 28 20:17:39 2019 +0100

    nxdialog: make code compatible to python2 _and_ python3
---
 nxdialog/nxdialog | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/nxdialog/nxdialog b/nxdialog/nxdialog
index ff453e2..58e773c 100755
--- a/nxdialog/nxdialog
+++ b/nxdialog/nxdialog
@@ -1,5 +1,11 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python
 #
+# ^^^ This is working with python2 and python3 so we choose a shebang
+#     that will find either version.
+#     Citing PEP394: "One exception to this is scripts that are
+#     deliberately written to be source compatible with both Python
+#     2.x and 3.x. Such scripts may continue to use python on their
+#     shebang line.
 
 # Copyright (C) 2008 Google Inc.
 # Copyright (C) 2019 Ulrich Sibiller <uli42 at gmx.de>
@@ -32,12 +38,15 @@
 # - removed neatx entry from the pulldoww menu
 # - use PyGObject instead of PyGtk and thus Gtk3
 # - replace optparse by argparse
+# - make code compatible to python2 and python3. 
 
 """nxdialog program for handling dialog display."""
 
 # If an "NX_CLIENT" environment variable is not provided to nxagent
 # nxcomp library assumes this script is located in /usr/NX/bin/nxclient
 
+from __future__ import print_function
+
 import argparse
 import os
 import signal
@@ -155,7 +164,7 @@ class PullDownMenu(object):
         menu_width = menu.get_allocated_width()
 
         # Calculate center
-        center_x = win_x + ((win_width - menu_width) / 2)
+        center_x = int(win_x + ((win_width - menu_width) / 2))
 
         return (center_x, win_y, True)
 
@@ -224,11 +233,11 @@ def handle_session_action(agentpid, action):
     """
 
     if action == DISCONNECT:
-        print "Disconnecting from session, sending SIGHUP to %s" % (agentpid)
+        print("Disconnecting from session, sending SIGHUP to %s" % (agentpid))
         os.kill(agentpid, signal.SIGHUP)
 
     elif action == TERMINATE:
-        print "Terminating session, sending SIGTERM to process %s" % (agentpid)
+        print("Terminating session, sending SIGTERM to process %s" % (agentpid))
         os.kill(agentpid, signal.SIGTERM)
 
     elif action is None:
@@ -273,11 +282,12 @@ class NxDialogProgram(object):
         except (SystemExit, KeyboardInterrupt):
             raise
 
-        except Exception, expt:
+        except Exception as expt:
             sys.stderr.write("Caught exception: %s\n" % (expt))
             sys.exit(EXIT_FAILURE)
 
-    def parse_args(self):
+    @staticmethod
+    def parse_args():
         """ init parser """
 
         parser = argparse.ArgumentParser(description="Helper for nxagent to display dialogs")

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/nx-libs.git


More information about the x2go-commits mailing list