diff options
author | Ulrich Sibiller <uli42@gmx.de> | 2019-02-28 20:17:39 +0100 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2019-03-01 12:48:32 +0100 |
commit | acffe15b58c352914a63499d29a12f72671afc5b (patch) | |
tree | 206578b9d3724dd8683d7f44b1a5eae42b92c5a2 /nxdialog | |
parent | 57700cd6b2c6285c27a78758b741247faf9cf6b0 (diff) | |
download | nx-libs-acffe15b58c352914a63499d29a12f72671afc5b.tar.gz nx-libs-acffe15b58c352914a63499d29a12f72671afc5b.tar.bz2 nx-libs-acffe15b58c352914a63499d29a12f72671afc5b.zip |
nxdialog: make code compatible to python2 _and_ python3
Diffstat (limited to 'nxdialog')
-rwxr-xr-x | nxdialog/nxdialog | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/nxdialog/nxdialog b/nxdialog/nxdialog index ff453e22f..58e773ca8 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@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") |