Commit 57700cd6 authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

nxdialog: convert from optparse to argparse

parent 3a097e6e
...@@ -31,13 +31,14 @@ ...@@ -31,13 +31,14 @@
# - pylint improvements # - pylint improvements
# - removed neatx entry from the pulldoww menu # - removed neatx entry from the pulldoww menu
# - use PyGObject instead of PyGtk and thus Gtk3 # - use PyGObject instead of PyGtk and thus Gtk3
# - replace optparse by argparse
"""nxdialog program for handling dialog display.""" """nxdialog program for handling dialog display."""
# If an "NX_CLIENT" environment variable is not provided to nxagent # If an "NX_CLIENT" environment variable is not provided to nxagent
# nxcomp library assumes this script is located in /usr/NX/bin/nxclient # nxcomp library assumes this script is located in /usr/NX/bin/nxclient
import optparse import argparse
import os import os
import signal import signal
import sys import sys
...@@ -265,7 +266,7 @@ class NxDialogProgram(object): ...@@ -265,7 +266,7 @@ class NxDialogProgram(object):
def main(self): def main(self):
""" let's do something """ """ let's do something """
try: try:
(self.options, self.args) = self.parse_args() self.options = self.parse_args()
self.run() self.run()
...@@ -278,45 +279,40 @@ class NxDialogProgram(object): ...@@ -278,45 +279,40 @@ class NxDialogProgram(object):
def parse_args(self): def parse_args(self):
""" init parser """ """ init parser """
parser = optparse.OptionParser(option_list=self.build_options(),
formatter=optparse.TitledHelpFormatter())
return parser.parse_args()
@staticmethod parser = argparse.ArgumentParser(description="Helper for nxagent to display dialogs")
def build_options():
""" build options for the parser """ # nxagent 3.5.99.18 only uses yesno, ok, pulldown and yesnosuspend
return [ # yesno dialogs will always kill the session if "yes" is selected
# nxagent 3.5.99.18 only uses yesno, ok, pulldown and yesnosuspend parser.add_argument("--dialog", dest="dialog_type",
# yesno dialogs will always kill the session if "yes" is selected help='type of dialog to show, one of "yesno", \
optparse.make_option("--dialog", type="string", dest="dialog_type", "ok", "error", "panic", "quit", "pulldown", \
help='type of dialog to show, one of "yesno", \ "yesnosuspend"')
"ok", "error", "panic", "quit", "pulldown", \ parser.add_argument("--message", dest="text",
"yesnosuspend"'), help="message text to display in the dialog")
optparse.make_option("--message", type="string", dest="text", parser.add_argument("--caption", dest="caption",
help="message text to display in the dialog"), help="window title of the dialog")
optparse.make_option("--caption", type="string", dest="caption", parser.add_argument("--display", dest="display",
help="window title of the dialog"), help="X11 display where the dialog should be \
optparse.make_option("--display", type="string", dest="display", shown")
help="X11 display where the dialog should be \ parser.add_argument("--parent", type=int, dest="agentpid",
shown"), help="pid of the nxagent")
optparse.make_option("--parent", type="int", dest="agentpid", parser.add_argument("--window", type=int, dest="window",
help="pid of the nxagent"), help="id of window where to embed the \
optparse.make_option("--window", type="int", dest="window", pulldown dialog type")
help="id of window where to embed the \ # -class, -local, -allowmultiple are unused in nxlibs 3.5.99.18
pulldown dialog type"), parser.add_argument("--class", dest="dlgclass", default="info",
# -class, -local, -allowmultiple are unused in nxlibs 3.5.99.18 help="class of the message (info, warning, error) \
optparse.make_option("--class", type="string", dest="dlgclass", default: info) [currently unimplemented]")
default="info", parser.add_argument("--local", action="store_true", dest="local",
help="class of the message (info, warning, error) \ help="specify that proxy mode is used \
default: info) [currently unimplemented]"), [currently unimplemented]")
optparse.make_option("--local", action="store_true", dest="local", parser.add_argument("--allowmultiple", action="store_true",
help="specify that proxy mode is used \ dest="allowmultiple",
[currently unimplemented]"), help="allow launching more than one dialog with \
optparse.make_option("--allowmultiple", action="store_true", the same message [currently unimplemented]")
dest="allowmultiple",
help="allow launching more than one dialog with \ return parser.parse_args()
the same message [currently unimplemented]"),
]
def run(self): def run(self):
""" Disconnect/terminate NX session upon user's request. """ """ Disconnect/terminate NX session upon user's request. """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment