Example #1
0
def main():
    from xpra.platform import init as platform_init, clean as platform_clean
    from xpra.platform.gui import ready as gui_ready
    try:
        platform_init("Start-New-Command", "Start New Command")

        #logging init:
        if "-v" in sys.argv:
            enable_debug_for("util")

        from xpra.os_util import SIGNAMES
        from xpra.gtk_common.quit import gtk_main_quit_on_fatal_exceptions_enable
        gtk_main_quit_on_fatal_exceptions_enable()

        app = StartNewCommand()
        app.close = app.quit
        def app_signal(signum, frame):
            print("")
            log.info("got signal %s", SIGNAMES.get(signum, signum))
            app.quit()
        signal.signal(signal.SIGINT, app_signal)
        signal.signal(signal.SIGTERM, app_signal)
        try:
            gui_ready()
            app.show()
            app.run()
        except KeyboardInterrupt:
            pass
        return 0
    finally:
        platform_clean()
Example #2
0
def main():
    from xpra.platform.gui import init as gui_init
    from xpra.platform import init as platform_init,clean
    try:
        platform_init("XSettings")
        gui_init()
        verbose = "-v" in sys.argv or "--verbose" in sys.argv
        if verbose:
            from xpra.log import get_all_loggers
            for x in get_all_loggers():
                x.enable_debug()

        #naughty, but how else can I hook this up?
        import os
        if os.name!="posix":
            print("xsettings require a posix OS")
            return 1

        from xpra.x11.bindings import posix_display_source  #@UnresolvedImport - takes care of hooking up the display
        assert posix_display_source
        from xpra.x11.bindings.window_bindings import X11WindowBindings #@UnresolvedImport
        window_bindings = X11WindowBindings()
        selection = "_XSETTINGS_S0"
        owner = window_bindings.XGetSelectionOwner(selection)
        print("owner(%s)=%#x" % (selection, owner))
        XSETTINGS = "_XSETTINGS_SETTINGS"
        data = window_bindings.XGetWindowProperty(owner, XSETTINGS, XSETTINGS)
        serial, settings = get_settings(None, data)
        print("serial=%s" % serial)
        print("%s settings:" % len(settings))
        for s in settings:
            print(s)
        return 0
    finally:
        clean()
Example #3
0
def main():
    from xpra.platform import init as platform_init, clean
    from xpra.util import nonl
    from xpra.log import enable_color

    try:
        platform_init("GUI-Properties")
        enable_color()
        init()
        verbose = "-v" in sys.argv or "--verbose" in sys.argv
        if verbose:
            from xpra.log import get_all_loggers

            for x in get_all_loggers():
                x.enable_debug()

        # naughty, but how else can I hook this up?
        import os

        if os.name == "posix":
            try:
                from xpra.x11.bindings import posix_display_source  # @UnusedImport
            except:
                pass  # maybe running on OSX? hope for the best..
        i = get_info()
        for k in sorted(i.keys()):
            v = i[k]
            print("* %s : %s" % (k.ljust(32), nonl(v)))
    finally:
        clean()
Example #4
0
def main():
    from xpra.platform import init as platform_init
    from xpra.platform.gui import ready as gui_ready
    platform_init("Start-New-Command", "Start New Command")

    #logging init:
    if "-v" in sys.argv:
        enable_debug_for("util")

    from xpra.os_util import SIGNAMES
    from xpra.gtk_common.quit import gtk_main_quit_on_fatal_exceptions_enable
    gtk_main_quit_on_fatal_exceptions_enable()

    app = StartNewCommand()
    app.close = app.quit
    def app_signal(signum, frame):
        print("")
        log.info("got signal %s", SIGNAMES.get(signum, signum))
        app.quit()
    signal.signal(signal.SIGINT, app_signal)
    signal.signal(signal.SIGTERM, app_signal)
    try:
        gui_ready()
        app.show()
        app.run()
    except KeyboardInterrupt:
        pass
    return 0
Example #5
0
def main():
    from xpra.platform import init as platform_init, clean
    from xpra.util import nonl
    from xpra.log import enable_color
    try:
        platform_init("GUI-Properties")
        enable_color()
        init()
        verbose = "-v" in sys.argv or "--verbose" in sys.argv
        if verbose:
            from xpra.log import get_all_loggers
            for x in get_all_loggers():
                x.enable_debug()

        #naughty, but how else can I hook this up?
        import os
        if os.name == "posix":
            try:
                from xpra.x11.bindings import posix_display_source  #@UnusedImport
            except:
                pass  #maybe running on OSX? hope for the best..
        i = get_info()
        for k in sorted(i.keys()):
            v = i[k]
            print("* %s : %s" % (k.ljust(32), nonl(v)))
    finally:
        clean()
Example #6
0
def main():
    from xpra.gtk_common.quit import gtk_main_quit_on_fatal_exceptions_enable
    gtk_main_quit_on_fatal_exceptions_enable()

    from xpra.platform import init as platform_init
    from xpra.platform.gui import ready as gui_ready
    platform_init("Xpra-Launcher", "Xpra Connection Launcher")
    gui_init()

    #logging init:
    from xpra.scripts.main import parse_cmdline, fixup_debug_option
    options, args = parse_cmdline(sys.argv)
    debug = fixup_debug_option(options.debug)
    if debug:
        for x in debug.split(","):
            enable_debug_for(x)

    app = ApplicationWindow()
    def app_signal(signum, frame):
        print("")
        log("got signal %s" % SIGNAMES.get(signum, signum))
        def show_signal():
            app.show()
            app.client.cleanup()
            gobject.timeout_add(1000, app.set_info_text, "got signal %s" % SIGNAMES.get(signum, signum))
            gobject.timeout_add(1000, app.set_info_color, True)
        #call from UI thread:
        gobject.idle_add(show_signal)
    signal.signal(signal.SIGINT, app_signal)
    signal.signal(signal.SIGTERM, app_signal)
    has_file = len(args) == 1
    if has_file:
        app.update_options_from_file(args[0])
    debug = fixup_debug_option(app.config.debug)
    if debug:
        for x in debug.split(","):
            enable_debug_for(x)
   #suspend tray workaround for our window widgets:
    try:
        set_use_tray_workaround(False)
        app.create_window()
    finally:
        set_use_tray_workaround(True)
    try:
        app.update_gui_from_config()
        if app.config.autoconnect:
            #file says we should connect,
            #do that only (not showing UI unless something goes wrong):
            gobject.idle_add(app.do_connect)
        if not has_file:
            app.reset_errors()
        gui_ready()
        if not app.config.autoconnect or app.config.debug:
            app.show()
        app.run()
    except KeyboardInterrupt:
        pass
    return 0
Example #7
0
def main():
    if sys.platform.startswith("win"):
        from xpra.platform.win32 import set_log_filename
        set_log_filename("Xpra-Launcher.log")
    set_prgname("Xpra-Launcher")
    platform_init()
    gui_init()

    #logging init:
    from xpra.scripts.main import parse_cmdline
    _, options, args = parse_cmdline(sys.argv)
    import logging
    logging.basicConfig(format="%(asctime)s %(message)s")
    if options.debug:
        logging.root.setLevel(logging.DEBUG)
    else:
        logging.root.setLevel(logging.INFO)

    app = ApplicationWindow()

    def app_signal(signum, frame):
        print("")
        log("got signal %s" % SIGNAMES.get(signum, signum))

        def show_signal():
            app.show()
            app.client.cleanup()
            gobject.timeout_add(1000, app.set_info_text,
                                "got signal %s" % SIGNAMES.get(signum, signum))
            gobject.timeout_add(1000, app.set_info_color, True)

        #call from UI thread:
        gobject.idle_add(show_signal)

    signal.signal(signal.SIGINT, app_signal)
    signal.signal(signal.SIGTERM, app_signal)
    has_file = len(args) == 1
    if has_file:
        app.update_options_from_file(args[0])
    if app.config.debug:
        logging.root.setLevel(logging.DEBUG)
    app.create_window()
    try:
        app.update_gui_from_config()
        if app.config.autoconnect:
            #file says we should connect,
            #do that only (not showing UI unless something goes wrong):
            gobject.idle_add(app.do_connect)
        if not has_file:
            app.reset_errors()
        gui_ready()
        if not app.config.autoconnect or app.config.debug:
            app.show()
        app.run()
    except KeyboardInterrupt:
        pass
    return 0
Example #8
0
def main():
    #use gtk as display source:
    from xpra.x11.gtk_x11 import gdk_display_source
    assert gdk_display_source
    from xpra.util import nonl
    from xpra.platform import init as platform_init
    platform_init("GTK-Keyboard", "GTK Keyboard")

    x = GTKKeyboardHelper(None, True, "")
    x.query_xkbmap()
    for k, v in x.get_keymap_properties().items():
        print("%s=%s" % (k, nonl(v)))
Example #9
0
def main(script_file, cmdline):
    platform_init()
    try:
        import glib
        glib.set_prgname("Xpra")
    except:
        pass
    parser, options, args = parse_cmdline(cmdline)
    if not args:
        parser.error("need a mode")
    mode = args.pop(0)
    return run_mode(script_file, parser, options, args, mode)
Example #10
0
def main(script_file, cmdline):
    platform_init()
    try:
        import glib
        glib.set_prgname("Xpra")
    except:
        pass
    parser, options, args = parse_cmdline(cmdline)
    if not args:
        parser.error("need a mode")
    mode = args.pop(0)
    return run_mode(script_file, parser, options, args, mode)
Example #11
0
def main():
    #use gtk as display source:
    from xpra.x11.gtk_x11 import gdk_display_source
    assert gdk_display_source
    from xpra.util import nonl
    from xpra.platform import init as platform_init
    platform_init("GTK-Keyboard", "GTK Keyboard")

    x = GTKKeyboardHelper(None, True, "")
    x.query_xkbmap()
    for k,v in x.get_keymap_properties().items():
        print("%s=%s" % (k,nonl(v)))
Example #12
0
def main():
    if sys.platform.startswith("win"):
        from xpra.platform.win32 import set_log_filename
        set_log_filename("Xpra-Launcher.log")
    set_prgname("Xpra-Launcher")
    platform_init()
    gui_init()

    #logging init:
    from xpra.scripts.main import parse_cmdline
    _, options, args = parse_cmdline(sys.argv)
    import logging
    logging.basicConfig(format="%(asctime)s %(message)s")
    if options.debug:
        logging.root.setLevel(logging.DEBUG)
    else:
        logging.root.setLevel(logging.INFO)

    app = ApplicationWindow()
    def app_signal(signum, frame):
        print("")
        log("got signal %s" % SIGNAMES.get(signum, signum))
        def show_signal():
            app.show()
            app.client.cleanup()
            gobject.timeout_add(1000, app.set_info_text, "got signal %s" % SIGNAMES.get(signum, signum))
            gobject.timeout_add(1000, app.set_info_color, True)
        #call from UI thread:
        gobject.idle_add(show_signal)
    signal.signal(signal.SIGINT, app_signal)
    signal.signal(signal.SIGTERM, app_signal)
    has_file = len(args) == 1
    if has_file:
        app.update_options_from_file(args[0])
    if app.config.debug:
        logging.root.setLevel(logging.DEBUG)
    app.create_window()
    try:
        app.update_gui_from_config()
        if app.config.autoconnect:
            #file says we should connect,
            #do that only (not showing UI unless something goes wrong):
            gobject.idle_add(app.do_connect)
        if not has_file:
            app.reset_errors()
        gui_ready()
        if not app.config.autoconnect or app.config.debug:
            app.show()
        app.run()
    except KeyboardInterrupt:
        pass
    return 0
Example #13
0
def main():
    from xpra.platform import init as platform_init
    from xpra.platform.gui import init as gui_init, ready as gui_ready
    platform_init("Xpra-Launcher", "Xpra Connection Launcher")
    gui_init()

    #logging init:
    from xpra.scripts.main import parse_cmdline
    _, options, args = parse_cmdline(sys.argv)
    if options.debug:
        from xpra.log import enable_debug_for
        enable_debug_for("all")

    app = ApplicationWindow()
    def app_signal(signum, frame):
        print("")
        log("got signal %s" % SIGNAMES.get(signum, signum))
        def show_signal():
            app.show()
            app.client.cleanup()
            gobject.timeout_add(1000, app.set_info_text, "got signal %s" % SIGNAMES.get(signum, signum))
            gobject.timeout_add(1000, app.set_info_color, True)
        #call from UI thread:
        gobject.idle_add(show_signal)
    signal.signal(signal.SIGINT, app_signal)
    signal.signal(signal.SIGTERM, app_signal)
    has_file = len(args) == 1
    if has_file:
        app.update_options_from_file(args[0])
    if app.config.debug:
        enable_debug_for("all")
    app.create_window()
    try:
        app.update_gui_from_config()
        if app.config.autoconnect:
            #file says we should connect,
            #do that only (not showing UI unless something goes wrong):
            gobject.idle_add(app.do_connect)
        if not has_file:
            app.reset_errors()
        gui_ready()
        if not app.config.autoconnect or app.config.debug:
            app.show()
        app.run()
    except KeyboardInterrupt:
        pass
    return 0
Example #14
0
def main():
    from xpra.platform import init as platform_init
    platform_init("Xpra-Bug-Report", "Xpra Bug Report")

    from xpra.log import Logger, enable_debug_for
    log = Logger("util")
    #logging init:
    if "-v" in sys.argv:
        enable_debug_for("util")

    from xpra.gtk_common.gobject_compat import import_gobject
    gobject = import_gobject()
    gobject.threads_init()

    from xpra.os_util import SIGNAMES
    from xpra.gtk_common.quit import gtk_main_quit_on_fatal_exceptions_enable
    gtk_main_quit_on_fatal_exceptions_enable()

    from xpra.client.gtk_base.bug_report import BugReport
    app = BugReport()
    app.close = app.quit
    app.init(True)

    def app_signal(signum, frame):
        print("")
        log.info("got signal %s", SIGNAMES.get(signum, signum))
        app.quit()

    signal.signal(signal.SIGINT, app_signal)
    signal.signal(signal.SIGTERM, app_signal)
    try:
        from xpra.platform.gui import ready as gui_ready
        gui_ready()
        app.show()
        app.run()
    except KeyboardInterrupt:
        pass
    return 0
Example #15
0
def main():
    from xpra.platform import init as platform_init
    platform_init("Xpra-Bug-Report", "Xpra Bug Report")
    from xpra.log import enable_color
    enable_color()

    from xpra.log import Logger, enable_debug_for
    log = Logger("util")
    #logging init:
    if "-v" in sys.argv:
        enable_debug_for("util")

    from xpra.gtk_common.gobject_compat import import_gobject
    gobject = import_gobject()
    gobject.threads_init()

    from xpra.os_util import SIGNAMES
    from xpra.gtk_common.quit import gtk_main_quit_on_fatal_exceptions_enable
    gtk_main_quit_on_fatal_exceptions_enable()

    from xpra.client.gtk_base.bug_report import BugReport
    app = BugReport()
    app.close = app.quit
    app.init(True)
    def app_signal(signum, frame):
        print("")
        log.info("got signal %s", SIGNAMES.get(signum, signum))
        app.quit()
    signal.signal(signal.SIGINT, app_signal)
    signal.signal(signal.SIGTERM, app_signal)
    try:
        from xpra.platform.gui import ready as gui_ready
        gui_ready()
        app.show()
        app.run()
    except KeyboardInterrupt:
        pass
    return 0
# later version. See the file COPYING for details.


from tests.xpra.net.test_protocol_base import SimpleServer, init_main
import gobject
import os.path
import socket

GTK = True
PLATFORM_INIT = True
if PLATFORM_INIT:
    from xpra.platform.features import LOCAL_SERVERS_SUPPORTED, SHADOW_SUPPORTED
    from xpra.platform.options import add_client_options
    from xpra.platform.paths import get_default_socket_dir
    from xpra.platform import init as platform_init
    platform_init()
    nones = [x for x in (LOCAL_SERVERS_SUPPORTED, SHADOW_SUPPORTED, add_client_options, get_default_socket_dir) if x is None]
    assert len([])==0

PLATFORM_GUI_INIT = PLATFORM_INIT and True
if PLATFORM_GUI_INIT:
    from xpra.platform.gui import init as gui_init
    gui_init()

#from xpra.platform.shadow_server import ShadowServer
#from xpra.server.source import ServerSource
#from xpra.server.server_base import ServerBase


def main():
    init_main("Shadow Protocol Test Tool")

from xpra.platform import init
from tests.xpra.net.test_protocol_base import SimpleServer
import gobject
import os.path
import socket

GTK = True
PLATFORM_INIT = True
if PLATFORM_INIT:
    from xpra.platform.features import LOCAL_SERVERS_SUPPORTED, SHADOW_SUPPORTED
    from xpra.platform.options import add_client_options
    from xpra.platform.paths import get_default_socket_dir
    from xpra.platform import init as platform_init
    platform_init()
    nones = [x for x in (LOCAL_SERVERS_SUPPORTED, SHADOW_SUPPORTED, add_client_options, get_default_socket_dir) if x is None]
    assert len([])==0

PLATFORM_GUI_INIT = PLATFORM_INIT and True
if PLATFORM_GUI_INIT:
    from xpra.platform.gui import init as gui_init
    gui_init()

#from xpra.platform.shadow_server import ShadowServer
#from xpra.server.source import ServerSource
#from xpra.server.server_base import ServerBase


def main():
    init("Fake-Server-Test", "Xpra Fake Server Test Tool")
Example #18
0
def main(script_file, cmdline):
    platform_init()
    if os.name=="posix" and os.getuid()==0:
        warn("\nWarning: running as root")
    try:
        import glib
        glib.set_prgname("Xpra")
    except:
        pass
    #################################################################
    ## NOTE NOTE NOTE
    ##
    ## If you modify anything here, then remember to update the man page
    ## (xpra.1) as well!
    ##
    ## NOTE NOTE NOTE
    #################################################################
    supports_shadow = XPRA_SHADOW_SUPPORTED
    supports_server = XPRA_LOCAL_SERVERS_SUPPORTED
    if supports_server:
        try:
            from xpra.wait_for_x_server import wait_for_x_server    #@UnresolvedImport @UnusedImport
        except:
            supports_server = False

    command_options = [
                        "\t%prog attach [DISPLAY]\n",
                        "\t%prog detach [DISPLAY]\n",
                        "\t%prog screenshot filename [DISPLAY]\n",
                        "\t%prog info [DISPLAY]\n",
                        "\t%prog version [DISPLAY]\n"
                      ]
    if supports_server:
        command_options = ["\t%prog start DISPLAY\n",
                           "\t%prog stop [DISPLAY]\n",
                           "\t%prog list\n",
                           "\t%prog upgrade DISPLAY\n",
                           ] + command_options
    if supports_shadow:
        command_options.append("\t%prog shadow DISPLAY\n")
    if not supports_server:
        command_options.append("(This xpra installation does not support starting local servers.)")

    hidden_options = {}
    parser = OptionParser(version="xpra v%s" % xpra.__version__,
                          usage="\n" + "".join(command_options))
    defaults = make_defaults_struct()
    if supports_server or supports_shadow:
        group = OptionGroup(parser, "Server Options",
                    "These options are only relevant on the server when using the 'start', 'upgrade' or 'shadow' mode.")
        parser.add_option_group(group)
    if supports_server:
        group.add_option("--start-child", action="append",
                          dest="start_child", metavar="CMD", default=defaults.start_child,
                          help="program to spawn in new server (may be repeated) (default: %default)")
        group.add_option("--exit-with-children", action="store_true",
                          dest="exit_with_children", default=defaults.exit_with_children,
                          help="Terminate server when --start-child command(s) exit")
    else:
        hidden_options["start_child"] = None
        hidden_options["exit_with_children"] = False
    if supports_server or supports_shadow:
        group.add_option("--no-daemon", action="store_false",
                          dest="daemon", default=True,
                          help="Don't daemonize when running as a server")
        group.add_option("--log-file", action="store",
                      dest="log_file", default=defaults.log_file,
                      help="When daemonizing, this is where the log messages will go (default: %s)."
                      + " If a relative filename is specified the it is relative to --socket-dir,"
                      + " the value of '$DISPLAY' will be substituted with the actual display used"
                      )
    else:
        hidden_options["daemon"] = False
        hidden_options["log_file"] = defaults.log_file
    if supports_server:
        group.add_option("--use-display", action="store_true",
                          dest="use_display", default=defaults.use_display,
                          help="Use an existing display rather than starting one with xvfb")
        group.add_option("--xvfb", action="store",
                          dest="xvfb",
                          default=defaults.xvfb,
                          metavar="CMD",
                          help="How to run the headless X server (default: '%default')")
    else:
        hidden_options["use_display"] = False
        hidden_options["xvfb"] = ''
    if supports_server or supports_shadow:
        group.add_option("--bind-tcp", action="append",
                          dest="bind_tcp", default=defaults.bind_tcp,
                          metavar="[HOST]:PORT",
                          help="Listen for connections over TCP (use --password-file to secure it)."
                            + " You may specify this option multiple times with different host and port combinations")
    else:
        hidden_options["bind_tcp"] = []
    if supports_server:
        group.add_option("--no-pulseaudio", action="store_false",
                      dest="pulseaudio", default=defaults.pulseaudio,
                      help="Disable starting of a pulseaudio server for the session")
        group.add_option("--pulseaudio-command", action="store",
                      dest="pulseaudio_command", default=defaults.pulseaudio_command,
                      help="The command used to start the pulseaudio server (default: '%default')")
    else:
        hidden_options["pulseaudio"] = False
        hidden_options["pulseaudio_command"] = ""

    group = OptionGroup(parser, "Server Controlled Features",
                "These options can be used to turn certain features on or off, "
                "they can be specified on the client or on the server, "
                "but the client cannot enable them if they are disabled on the server.")
    parser.add_option_group(group)
    group.add_option("--no-clipboard", action="store_false",
                      dest="clipboard", default=defaults.clipboard,
                      help="Disable clipboard support")
    group.add_option("--no-notifications", action="store_false",
                      dest="notifications", default=defaults.notifications,
                      help="Disable forwarding of system notifications")
    group.add_option("--no-system-tray", action="store_false",
                      dest="system_tray", default=defaults.system_tray,
                      help="Disable forwarding of system tray icons")
    group.add_option("--no-cursors", action="store_false",
                      dest="cursors", default=defaults.cursors,
                      help="Disable forwarding of custom application mouse cursors")
    group.add_option("--no-bell", action="store_false",
                      dest="bell", default=defaults.bell,
                      help="Disable forwarding of the system bell")
    group.add_option("--no-mmap", action="store_false",
                      dest="mmap", default=defaults.mmap,
                      help="Disable memory mapped transfers for local connections")
    group.add_option("--readonly", action="store_true",
                      dest="readonly", default=defaults.readonly,
                      help="Ignore all keyboard input and mouse events from the clients")
    group.add_option("--enable-sharing", action="store_true",
                      dest="sharing", default=defaults.sharing,
                      help="Allow more than one client to connect to the same session")
    group.add_option("--no-speaker", action="store_false",
                      dest="speaker", default=defaults.speaker,
                      help="Disable forwarding of sound output to the client(s)")
    group.add_option("--speaker-codec", action="append",
                      dest="speaker_codec", default=defaults.speaker_codec,
                      help="The audio codec to use for forwarding the speaker sound output "
                      "(you may specify more than one to define the preferred order, use 'help' to get a list of options, "
                      "when unspecified all available codecs are allowed and the first one is used)")
    group.add_option("--no-microphone", action="store_false",
                      dest="microphone", default=defaults.microphone,
                      help="Disable forwarding of sound input to the server")
    group.add_option("--microphone-codec", action="append",
                      dest="microphone_codec", default=defaults.microphone_codec,
                      help="The audio codec to use for forwaring the microphone sound input "
                      "(you may specify more than one to define the preferred order, use 'help' to get a list of options, "
                      "when unspecified all available codecs are allowed and the first one is used)")

    group = OptionGroup(parser, "Client Picture Encoding and Compression Options",
                "These options are used by the client to specify the desired picture and network data compression."
                "They may also be specified on the server as default values for those clients that do not set them.")
    parser.add_option_group(group)
    group.add_option("--encoding", action="store",
                      metavar="ENCODING", default=defaults.encoding,
                      dest="encoding", type="str",
                      help="What image compression algorithm to use: %s." % (", ".join(ENCODINGS)) +
                            " Default: %default."
                      )
    if "jpeg" in ENCODINGS:
        group.add_option("-b", "--max-bandwidth", action="store",
                          dest="max_bandwidth", type="float", default=defaults.max_bandwidth, metavar="BANDWIDTH (kB/s)",
                          help="Specify the link's maximal receive speed to auto-adjust JPEG quality, 0.0 disables. (default: %default)")
    else:
        hidden_options["max_bandwidth"] = 0
    if len(set(("jpeg", "webp", "x264")).intersection(set(ENCODINGS)))>0:
        group.add_option("--min-quality", action="store",
                          metavar="MIN-LEVEL",
                          dest="min_quality", type="int", default=defaults.min_quality,
                          help="Sets the minimum x264 encoding quality allowed in automatic quality setting (from 1 to 100, 0 to leave unset). Default: %default.")
        group.add_option("--quality", action="store",
                          metavar="LEVEL",
                          dest="quality", type="int", default=defaults.quality,
                          help="Use a fixed image compression quality - only relevant to lossy encodings (1-100, 0 to use automatic setting). Default: %default.")
    else:
        hidden_options["min_quality"] = defaults.min_quality
        hidden_options["quality"] = defaults.quality
    if "x264" in ENCODINGS:
        group.add_option("--min-speed", action="store",
                          metavar="SPEED",
                          dest="min_speed", type="int", default=defaults.min_speed,
                          help="Sets the minimum x264 encoding speed allowed in automatic speed setting (1-100, 0 to leave unset). Default: %default.")
        group.add_option("--speed", action="store",
                          metavar="SPEED",
                          dest="speed", type="int", default=defaults.speed,
                          help="Use x264 image compression with the given encoding speed (1-100, 0 to use automatic setting). Default: %default.")
    else:
        hidden_options["min_speed"] = defaults.min_speed
        hidden_options["speed"] = defaults.speed
    group.add_option("--auto-refresh-delay", action="store",
                      dest="auto_refresh_delay", type="float", default=defaults.auto_refresh_delay,
                      metavar="DELAY",
                      help="Idle delay in seconds before doing an automatic lossless refresh."
                      + " 0.0 to disable."
                      + " Default: %default.")
    group.add_option("-z", "--compress", action="store",
                      dest="compression_level", type="int", default=defaults.compression_level,
                      metavar="LEVEL",
                      help="How hard to work on compressing data."
                      + " You generally do not need to use this option,"
                      + " the default value should be adequate,"
                      + " picture data is compressed separately (see --encoding)."
                      + " 0 to disable compression,"
                      + " 9 for maximal (slowest) compression. Default: %default.")

    group = OptionGroup(parser, "Client Features Options",
                "These options control client features that affect the appearance or the keyboard.")
    parser.add_option_group(group)
    group.add_option("--opengl", action="store",
                      dest="opengl", default=defaults.opengl,
                      help="Use OpenGL accelerated rendering, options: yes,no,auto. Default: %default.")
    group.add_option("--no-windows", action="store_false",
                      dest="windows", default=defaults.windows,
                      help="Tells the server not to send any window data, only notifications and bell events will be forwarded (if enabled).")
    group.add_option("--session-name", action="store",
                      dest="session_name", default=defaults.session_name,
                      help="The name of this session, which may be used in notifications, menus, etc. Default: Xpra")
    group.add_option("--title", action="store",
                      dest="title", default=defaults.title,
                      help="Text which is shown as window title, may use remote metadata variables (default: '%default')")
    group.add_option("--window-icon", action="store",
                          dest="window_icon", default=defaults.window_icon,
                          help="Path to the default image which will be used for all windows (the application may override this)")
    # let the platform specific code add its own options:
    # adds "--no-tray" for platforms that support it
    add_client_options(group)
    group.add_option("--tray-icon", action="store",
                          dest="tray_icon", default=defaults.tray_icon,
                          help="Path to the image which will be used as icon for the system-tray or dock")
    group.add_option("--key-shortcut", action="append",
                      dest="key_shortcut", type="str", default=defaults.key_shortcut,
                      help="Define key shortcuts that will trigger specific actions."
                      + " Defaults to 'Meta+Shift+F4:quit' if no shortcuts are defined.")
    group.add_option("--no-keyboard-sync", action="store_false",
                      dest="keyboard_sync", default=defaults.keyboard_sync,
                      help="Disable keyboard state synchronization, prevents keys from repeating on high latency links but also may disrupt applications which access the keyboard directly")
    parser.add_option_group(group)

    group = OptionGroup(parser, "Advanced Options",
                "These options apply to both client and server. Please refer to the man page for details.")
    parser.add_option_group(group)
    group.add_option("--password-file", action="store",
                      dest="password_file", default=defaults.password_file,
                      help="The file containing the password required to connect (useful to secure TCP mode)")
    group.add_option("--dpi", action="store",
                      dest="dpi", default=defaults.dpi,
                      help="The 'dots per inch' value that client applications should try to honour (default: %default)")
    default_socket_dir_str = defaults.socket_dir or "$XPRA_SOCKET_DIR or '~/.xpra'"
    group.add_option("--socket-dir", action="store",
                      dest="socket_dir", default=defaults.socket_dir,
                      help="Directory to place/look for the socket files in (default: %s)" % default_socket_dir_str)
    debug_default = ""
    if defaults.debug:
        debug_default = "all"
    group.add_option("-d", "--debug", action="store",
                      dest="debug", default=debug_default, metavar="FILTER1,FILTER2,...",
                      help="List of categories to enable debugging for (or \"all\")")
    group.add_option("--ssh", action="store",
                      dest="ssh", default=defaults.ssh, metavar="CMD",
                      help="How to run ssh (default: '%default')")
    group.add_option("--mmap-group", action="store_true",
                      dest="mmap_group", default=defaults.mmap_group,
                      help="When creating the mmap file with the client, set the group permission on the mmap file to the same value as the owner of the server socket file we connect to (default: '%default')")
    group.add_option("--enable-pings", action="store_true",
                      dest="pings", default=defaults.pings,
                      help="Send ping packets every second to gather latency statistics")
    group.add_option("--clipboard-filter-file", action="store",
                      dest="clipboard_filter_file", default=defaults.clipboard_filter_file,
                      help="Name of a file containing regular expressions of clipboard contents that must be filtered out")
    group.add_option("--remote-xpra", action="store",
                      dest="remote_xpra", default=defaults.remote_xpra,
                      metavar="CMD",
                      help="How to run xpra on the remote host (default: '%default')")
    if len(ENCRYPTION_CIPHERS)>0:
        group.add_option("--encryption", action="store",
                          dest="encryption", default=defaults.encryption,
                          metavar="ALGO",
                          help="Specifies the encryption cipher to use, only %s is currently supported. (default: None)" % (", ".join(ENCRYPTION_CIPHERS)))
    else:
        hidden_options["encryption"] = ''

    options, args = parser.parse_args(cmdline[1:])
    if not args:
        parser.error("need a mode")

    #ensure all the option fields are set even though
    #some options are not shown to the user:
    for k,v in hidden_options.items():
        setattr(options, k, v)
    try:
        int(options.dpi)
    except Exception, e:
        parser.error("invalid dpi: %s" % e)
Example #19
0
def main(script_file, cmdline):
    platform_init()
    if os.name == "posix" and os.getuid() == 0:
        warn("\nWarning: running as root")
    try:
        import glib
        glib.set_prgname("Xpra")
    except:
        pass
    #################################################################
    ## NOTE NOTE NOTE
    ##
    ## If you modify anything here, then remember to update the man page
    ## (xpra.1) as well!
    ##
    ## NOTE NOTE NOTE
    #################################################################
    supports_shadow = XPRA_SHADOW_SUPPORTED
    supports_server = XPRA_LOCAL_SERVERS_SUPPORTED
    if supports_server:
        try:
            from xpra.wait_for_x_server import wait_for_x_server  #@UnresolvedImport @UnusedImport
        except:
            supports_server = False

    command_options = [
        "\t%prog attach [DISPLAY]\n", "\t%prog detach [DISPLAY]\n",
        "\t%prog screenshot filename [DISPLAY]\n", "\t%prog info [DISPLAY]\n",
        "\t%prog version [DISPLAY]\n"
    ]
    if supports_server:
        command_options = [
            "\t%prog start DISPLAY\n",
            "\t%prog stop [DISPLAY]\n",
            "\t%prog list\n",
            "\t%prog upgrade DISPLAY\n",
        ] + command_options
    if supports_shadow:
        command_options.append("\t%prog shadow DISPLAY\n")
    if not supports_server:
        command_options.append(
            "(This xpra installation does not support starting local servers.)"
        )

    hidden_options = {}
    parser = OptionParser(version="xpra v%s" % xpra.__version__,
                          usage="\n" + "".join(command_options))
    defaults = make_defaults_struct()
    if supports_server or supports_shadow:
        group = OptionGroup(
            parser, "Server Options",
            "These options are only relevant on the server when using the 'start', 'upgrade' or 'shadow' mode."
        )
        parser.add_option_group(group)
    if supports_server:
        group.add_option(
            "--start-child",
            action="append",
            dest="start_child",
            metavar="CMD",
            default=defaults.start_child,
            help=
            "program to spawn in new server (may be repeated) (default: %default)"
        )
        group.add_option(
            "--exit-with-children",
            action="store_true",
            dest="exit_with_children",
            default=defaults.exit_with_children,
            help="Terminate server when --start-child command(s) exit")
    else:
        hidden_options["start_child"] = None
        hidden_options["exit_with_children"] = False
    if supports_server or supports_shadow:
        group.add_option("--no-daemon",
                         action="store_false",
                         dest="daemon",
                         default=True,
                         help="Don't daemonize when running as a server")
        group.add_option(
            "--log-file",
            action="store",
            dest="log_file",
            default=defaults.log_file,
            help=
            "When daemonizing, this is where the log messages will go (default: %s)."
            +
            " If a relative filename is specified the it is relative to --socket-dir,"
            +
            " the value of '$DISPLAY' will be substituted with the actual display used"
        )
    else:
        hidden_options["daemon"] = False
        hidden_options["log_file"] = defaults.log_file
    if supports_server:
        group.add_option(
            "--use-display",
            action="store_true",
            dest="use_display",
            default=defaults.use_display,
            help="Use an existing display rather than starting one with xvfb")
        group.add_option(
            "--xvfb",
            action="store",
            dest="xvfb",
            default=defaults.xvfb,
            metavar="CMD",
            help="How to run the headless X server (default: '%default')")
    else:
        hidden_options["use_display"] = False
        hidden_options["xvfb"] = ''
    if supports_server or supports_shadow:
        group.add_option(
            "--bind-tcp",
            action="append",
            dest="bind_tcp",
            default=defaults.bind_tcp,
            metavar="[HOST]:PORT",
            help=
            "Listen for connections over TCP (use --password-file to secure it)."
            +
            " You may specify this option multiple times with different host and port combinations"
        )
    else:
        hidden_options["bind_tcp"] = []
    if supports_server:
        group.add_option(
            "--no-pulseaudio",
            action="store_false",
            dest="pulseaudio",
            default=defaults.pulseaudio,
            help="Disable starting of a pulseaudio server for the session")
        group.add_option(
            "--pulseaudio-command",
            action="store",
            dest="pulseaudio_command",
            default=defaults.pulseaudio_command,
            help=
            "The command used to start the pulseaudio server (default: '%default')"
        )
    else:
        hidden_options["pulseaudio"] = False
        hidden_options["pulseaudio_command"] = ""

    group = OptionGroup(
        parser, "Server Controlled Features",
        "These options can be used to turn certain features on or off, "
        "they can be specified on the client or on the server, "
        "but the client cannot enable them if they are disabled on the server."
    )
    parser.add_option_group(group)
    group.add_option("--no-clipboard",
                     action="store_false",
                     dest="clipboard",
                     default=defaults.clipboard,
                     help="Disable clipboard support")
    group.add_option("--no-notifications",
                     action="store_false",
                     dest="notifications",
                     default=defaults.notifications,
                     help="Disable forwarding of system notifications")
    group.add_option("--no-system-tray",
                     action="store_false",
                     dest="system_tray",
                     default=defaults.system_tray,
                     help="Disable forwarding of system tray icons")
    group.add_option(
        "--no-cursors",
        action="store_false",
        dest="cursors",
        default=defaults.cursors,
        help="Disable forwarding of custom application mouse cursors")
    group.add_option("--no-bell",
                     action="store_false",
                     dest="bell",
                     default=defaults.bell,
                     help="Disable forwarding of the system bell")
    group.add_option(
        "--no-mmap",
        action="store_false",
        dest="mmap",
        default=defaults.mmap,
        help="Disable memory mapped transfers for local connections")
    group.add_option(
        "--readonly",
        action="store_true",
        dest="readonly",
        default=defaults.readonly,
        help="Ignore all keyboard input and mouse events from the clients")
    group.add_option(
        "--enable-sharing",
        action="store_true",
        dest="sharing",
        default=defaults.sharing,
        help="Allow more than one client to connect to the same session")
    group.add_option(
        "--no-speaker",
        action="store_false",
        dest="speaker",
        default=defaults.speaker,
        help="Disable forwarding of sound output to the client(s)")
    group.add_option(
        "--speaker-codec",
        action="append",
        dest="speaker_codec",
        default=defaults.speaker_codec,
        help="The audio codec to use for forwarding the speaker sound output "
        "(you may specify more than one to define the preferred order, use 'help' to get a list of options, "
        "when unspecified all available codecs are allowed and the first one is used)"
    )
    group.add_option("--no-microphone",
                     action="store_false",
                     dest="microphone",
                     default=defaults.microphone,
                     help="Disable forwarding of sound input to the server")
    group.add_option(
        "--microphone-codec",
        action="append",
        dest="microphone_codec",
        default=defaults.microphone_codec,
        help="The audio codec to use for forwaring the microphone sound input "
        "(you may specify more than one to define the preferred order, use 'help' to get a list of options, "
        "when unspecified all available codecs are allowed and the first one is used)"
    )

    group = OptionGroup(
        parser, "Client Picture Encoding and Compression Options",
        "These options are used by the client to specify the desired picture and network data compression."
        "They may also be specified on the server as default values for those clients that do not set them."
    )
    parser.add_option_group(group)
    group.add_option("--encoding",
                     action="store",
                     metavar="ENCODING",
                     default=defaults.encoding,
                     dest="encoding",
                     type="str",
                     help="What image compression algorithm to use: %s." %
                     (", ".join(ENCODINGS)) + " Default: %default.")
    if "jpeg" in ENCODINGS:
        group.add_option(
            "-b",
            "--max-bandwidth",
            action="store",
            dest="max_bandwidth",
            type="float",
            default=defaults.max_bandwidth,
            metavar="BANDWIDTH (kB/s)",
            help=
            "Specify the link's maximal receive speed to auto-adjust JPEG quality, 0.0 disables. (default: %default)"
        )
    else:
        hidden_options["max_bandwidth"] = 0
    if len(set(("jpeg", "webp", "x264")).intersection(set(ENCODINGS))) > 0:
        group.add_option(
            "--min-quality",
            action="store",
            metavar="MIN-LEVEL",
            dest="min_quality",
            type="int",
            default=defaults.min_quality,
            help=
            "Sets the minimum x264 encoding quality allowed in automatic quality setting (from 1 to 100, 0 to leave unset). Default: %default."
        )
        group.add_option(
            "--quality",
            action="store",
            metavar="LEVEL",
            dest="quality",
            type="int",
            default=defaults.quality,
            help=
            "Use a fixed image compression quality - only relevant to lossy encodings (1-100, 0 to use automatic setting). Default: %default."
        )
    else:
        hidden_options["min_quality"] = defaults.min_quality
        hidden_options["quality"] = defaults.quality
    if "x264" in ENCODINGS:
        group.add_option(
            "--min-speed",
            action="store",
            metavar="SPEED",
            dest="min_speed",
            type="int",
            default=defaults.min_speed,
            help=
            "Sets the minimum x264 encoding speed allowed in automatic speed setting (1-100, 0 to leave unset). Default: %default."
        )
        group.add_option(
            "--speed",
            action="store",
            metavar="SPEED",
            dest="speed",
            type="int",
            default=defaults.speed,
            help=
            "Use x264 image compression with the given encoding speed (1-100, 0 to use automatic setting). Default: %default."
        )
    else:
        hidden_options["min_speed"] = defaults.min_speed
        hidden_options["speed"] = defaults.speed
    group.add_option(
        "--auto-refresh-delay",
        action="store",
        dest="auto_refresh_delay",
        type="float",
        default=defaults.auto_refresh_delay,
        metavar="DELAY",
        help="Idle delay in seconds before doing an automatic lossless refresh."
        + " 0.0 to disable." + " Default: %default.")
    group.add_option(
        "-z",
        "--compress",
        action="store",
        dest="compression_level",
        type="int",
        default=defaults.compression_level,
        metavar="LEVEL",
        help="How hard to work on compressing data." +
        " You generally do not need to use this option," +
        " the default value should be adequate," +
        " picture data is compressed separately (see --encoding)." +
        " 0 to disable compression," +
        " 9 for maximal (slowest) compression. Default: %default.")

    group = OptionGroup(
        parser, "Client Features Options",
        "These options control client features that affect the appearance or the keyboard."
    )
    parser.add_option_group(group)
    group.add_option(
        "--opengl",
        action="store",
        dest="opengl",
        default=defaults.opengl,
        help=
        "Use OpenGL accelerated rendering, options: yes,no,auto. Default: %default."
    )
    group.add_option(
        "--no-windows",
        action="store_false",
        dest="windows",
        default=defaults.windows,
        help=
        "Tells the server not to send any window data, only notifications and bell events will be forwarded (if enabled)."
    )
    group.add_option(
        "--session-name",
        action="store",
        dest="session_name",
        default=defaults.session_name,
        help=
        "The name of this session, which may be used in notifications, menus, etc. Default: Xpra"
    )
    group.add_option(
        "--title",
        action="store",
        dest="title",
        default=defaults.title,
        help=
        "Text which is shown as window title, may use remote metadata variables (default: '%default')"
    )
    group.add_option(
        "--window-icon",
        action="store",
        dest="window_icon",
        default=defaults.window_icon,
        help=
        "Path to the default image which will be used for all windows (the application may override this)"
    )
    # let the platform specific code add its own options:
    # adds "--no-tray" for platforms that support it
    add_client_options(group)
    group.add_option(
        "--tray-icon",
        action="store",
        dest="tray_icon",
        default=defaults.tray_icon,
        help=
        "Path to the image which will be used as icon for the system-tray or dock"
    )
    group.add_option(
        "--key-shortcut",
        action="append",
        dest="key_shortcut",
        type="str",
        default=defaults.key_shortcut,
        help="Define key shortcuts that will trigger specific actions." +
        " Defaults to 'Meta+Shift+F4:quit' if no shortcuts are defined.")
    group.add_option(
        "--no-keyboard-sync",
        action="store_false",
        dest="keyboard_sync",
        default=defaults.keyboard_sync,
        help=
        "Disable keyboard state synchronization, prevents keys from repeating on high latency links but also may disrupt applications which access the keyboard directly"
    )
    parser.add_option_group(group)

    group = OptionGroup(
        parser, "Advanced Options",
        "These options apply to both client and server. Please refer to the man page for details."
    )
    parser.add_option_group(group)
    group.add_option(
        "--password-file",
        action="store",
        dest="password_file",
        default=defaults.password_file,
        help=
        "The file containing the password required to connect (useful to secure TCP mode)"
    )
    group.add_option(
        "--dpi",
        action="store",
        dest="dpi",
        default=defaults.dpi,
        help=
        "The 'dots per inch' value that client applications should try to honour (default: %default)"
    )
    default_socket_dir_str = defaults.socket_dir or "$XPRA_SOCKET_DIR or '~/.xpra'"
    group.add_option(
        "--socket-dir",
        action="store",
        dest="socket_dir",
        default=defaults.socket_dir,
        help="Directory to place/look for the socket files in (default: %s)" %
        default_socket_dir_str)
    debug_default = ""
    if defaults.debug:
        debug_default = "all"
    group.add_option(
        "-d",
        "--debug",
        action="store",
        dest="debug",
        default=debug_default,
        metavar="FILTER1,FILTER2,...",
        help="List of categories to enable debugging for (or \"all\")")
    group.add_option("--ssh",
                     action="store",
                     dest="ssh",
                     default=defaults.ssh,
                     metavar="CMD",
                     help="How to run ssh (default: '%default')")
    group.add_option(
        "--mmap-group",
        action="store_true",
        dest="mmap_group",
        default=defaults.mmap_group,
        help=
        "When creating the mmap file with the client, set the group permission on the mmap file to the same value as the owner of the server socket file we connect to (default: '%default')"
    )
    group.add_option(
        "--enable-pings",
        action="store_true",
        dest="pings",
        default=defaults.pings,
        help="Send ping packets every second to gather latency statistics")
    group.add_option(
        "--clipboard-filter-file",
        action="store",
        dest="clipboard_filter_file",
        default=defaults.clipboard_filter_file,
        help=
        "Name of a file containing regular expressions of clipboard contents that must be filtered out"
    )
    group.add_option(
        "--remote-xpra",
        action="store",
        dest="remote_xpra",
        default=defaults.remote_xpra,
        metavar="CMD",
        help="How to run xpra on the remote host (default: '%default')")
    if len(ENCRYPTION_CIPHERS) > 0:
        group.add_option(
            "--encryption",
            action="store",
            dest="encryption",
            default=defaults.encryption,
            metavar="ALGO",
            help=
            "Specifies the encryption cipher to use, only %s is currently supported. (default: None)"
            % (", ".join(ENCRYPTION_CIPHERS)))
    else:
        hidden_options["encryption"] = ''

    options, args = parser.parse_args(cmdline[1:])
    if not args:
        parser.error("need a mode")

    #ensure all the option fields are set even though
    #some options are not shown to the user:
    for k, v in hidden_options.items():
        setattr(options, k, v)
    try:
        int(options.dpi)
    except Exception, e:
        parser.error("invalid dpi: %s" % e)
Example #20
0
def main():
    from xpra.os_util import SIGNAMES
    from xpra.gtk_common.quit import gtk_main_quit_on_fatal_exceptions_enable
    gtk_main_quit_on_fatal_exceptions_enable()

    from xpra.platform import init as platform_init, clean as platform_clean
    from xpra.platform.gui import ready as gui_ready
    from xpra.log import enable_color
    try:
        platform_init("Xpra-Launcher", "Xpra Connection Launcher")
        enable_color()
        gui_init()
        try:
            from xpra.scripts.main import parse_cmdline, fixup_debug_option
            options, args = parse_cmdline(sys.argv)
            debug = fixup_debug_option(options.debug)
            if debug:
                for x in debug.split(","):
                    enable_debug_for(x)
        except Exception:
            exception_dialog("Error parsing command line")
            return 1

        try:
            app = ApplicationWindow()
            def app_signal(signum, frame):
                print("")
                log("got signal %s" % SIGNAMES.get(signum, signum))
                def show_signal():
                    app.show()
                    app.client.cleanup()
                    glib.timeout_add(1000, app.set_info_text, "got signal %s" % SIGNAMES.get(signum, signum))
                    glib.timeout_add(1000, app.set_info_color, True)
                #call from UI thread:
                glib.idle_add(show_signal)
            if sys.version_info[0]<3:
                #breaks GTK3..
                signal.signal(signal.SIGINT, app_signal)
            signal.signal(signal.SIGTERM, app_signal)
            has_file = len(args) == 1
            if has_file:
                app.update_options_from_file(args[0])
                #the compressors and packet encoders cannot be changed from the UI
                #so apply them now:
                configure_network(app.config)
            debug = fixup_debug_option(app.config.debug)
            if debug:
                for x in debug.split(","):
                    enable_debug_for(x)
            #suspend tray workaround for our window widgets:
            try:
                set_use_tray_workaround(False)
                app.create_window()
            finally:
                set_use_tray_workaround(True)
            app.update_gui_from_config()
        except Exception:
            exception_dialog("Error creating launcher form")
            return 1
        try:
            if app.config.autoconnect:
                #file says we should connect,
                #do that only (not showing UI unless something goes wrong):
                glib.idle_add(app.do_connect)
            if not has_file:
                app.reset_errors()
            gui_ready()
            if not app.config.autoconnect or app.config.debug:
                app.show()
            app.run()
        except KeyboardInterrupt:
            pass
        return 0
    finally:
        platform_clean()
Example #21
0
def main(script_file, cmdline):
    platform_init()
    if os.name == "posix" and os.getuid() == 0:
        warn("\nWarning: running as root")
    try:
        import glib
        glib.set_prgname("Xpra")
    except:
        pass
    #################################################################
    ## NOTE NOTE NOTE
    ##
    ## If you modify anything here, then remember to update the man page
    ## (xpra.1) as well!
    ##
    ## NOTE NOTE NOTE
    #################################################################
    supports_shadow = SHADOW_SUPPORTED
    supports_server = LOCAL_SERVERS_SUPPORTED
    if supports_server:
        try:
            from xpra.x11.bindings.wait_for_x_server import wait_for_x_server  #@UnresolvedImport @UnusedImport
        except:
            supports_server = False

    command_options = [
        "\t%prog attach [DISPLAY]\n", "\t%prog detach [DISPLAY]\n",
        "\t%prog screenshot filename [DISPLAY]\n", "\t%prog info [DISPLAY]\n",
        "\t%prog version [DISPLAY]\n"
    ]
    server_modes = []
    if supports_server:
        server_modes.append("start")
        server_modes.append("upgrade")
        command_options = [
            "\t%prog start DISPLAY\n",
            "\t%prog stop [DISPLAY]\n",
            "\t%prog list\n",
            "\t%prog upgrade DISPLAY\n",
        ] + command_options
    if supports_shadow:
        server_modes.append("shadow")
        command_options.append("\t%prog shadow DISPLAY\n")
    if not supports_server:
        command_options.append(
            "(This xpra installation does not support starting local servers.)"
        )

    hidden_options = {}
    parser = OptionParser(version="xpra v%s" % XPRA_VERSION,
                          usage="\n" + "".join(command_options))
    defaults = make_defaults_struct()
    if len(server_modes):
        group = OptionGroup(
            parser, "Server Options",
            "These options are only relevant on the server when using the %s mode."
            % "or".join(["'%s'" % x for x in server_modes]))
        parser.add_option_group(group)
    if supports_server:
        group.add_option(
            "--start-child",
            action="append",
            dest="start_child",
            metavar="CMD",
            default=defaults.start_child,
            help=
            "program to spawn in new server (may be repeated) (default: %default)"
        )
        group.add_option(
            "--exit-with-children",
            action="store_true",
            dest="exit_with_children",
            default=defaults.exit_with_children,
            help="Terminate server when --start-child command(s) exit")
    else:
        hidden_options["start_child"] = None
        hidden_options["exit_with_children"] = False
    if (supports_server or supports_shadow) and CAN_DAEMONIZE:
        group.add_option("--no-daemon",
                         action="store_false",
                         dest="daemon",
                         default=True,
                         help="Don't daemonize when running as a server")
        group.add_option(
            "--log-file",
            action="store",
            dest="log_file",
            default=defaults.log_file,
            help=
            "When daemonizing, this is where the log messages will go (default: %s)."
            +
            " If a relative filename is specified the it is relative to --socket-dir,"
            +
            " the value of '$DISPLAY' will be substituted with the actual display used"
        )
    else:
        hidden_options["daemon"] = False
        hidden_options["log_file"] = defaults.log_file
    if supports_server:
        group.add_option(
            "--use-display",
            action="store_true",
            dest="use_display",
            default=defaults.use_display,
            help="Use an existing display rather than starting one with xvfb")
        group.add_option(
            "--xvfb",
            action="store",
            dest="xvfb",
            default=defaults.xvfb,
            metavar="CMD",
            help="How to run the headless X server (default: '%default')")
    else:
        hidden_options["use_display"] = False
        hidden_options["xvfb"] = ''
    if supports_server or supports_shadow:
        group.add_option(
            "--bind-tcp",
            action="append",
            dest="bind_tcp",
            default=defaults.bind_tcp,
            metavar="[HOST]:PORT",
            help=
            "Listen for connections over TCP (use --password-file to secure it)."
            +
            " You may specify this option multiple times with different host and port combinations"
        )
    else:
        hidden_options["bind_tcp"] = []
    if supports_server:
        group.add_option(
            "--no-pulseaudio",
            action="store_false",
            dest="pulseaudio",
            default=defaults.pulseaudio,
            help="Disable starting of a pulseaudio server for the session")
        group.add_option(
            "--pulseaudio-command",
            action="store",
            dest="pulseaudio_command",
            default=defaults.pulseaudio_command,
            help=
            "The command used to start the pulseaudio server (default: '%default')"
        )
    else:
        hidden_options["pulseaudio"] = False
        hidden_options["pulseaudio_command"] = ""

    group = OptionGroup(
        parser, "Server Controlled Features",
        "These options can be used to turn certain features on or off, "
        "they can be specified on the client or on the server, "
        "but the client cannot enable them if they are disabled on the server."
    )
    parser.add_option_group(group)
    group.add_option("--no-clipboard",
                     action="store_false",
                     dest="clipboard",
                     default=defaults.clipboard,
                     help="Disable clipboard support")
    group.add_option("--no-notifications",
                     action="store_false",
                     dest="notifications",
                     default=defaults.notifications,
                     help="Disable forwarding of system notifications")
    group.add_option("--no-system-tray",
                     action="store_false",
                     dest="system_tray",
                     default=defaults.system_tray,
                     help="Disable forwarding of system tray icons")
    group.add_option(
        "--no-cursors",
        action="store_false",
        dest="cursors",
        default=defaults.cursors,
        help="Disable forwarding of custom application mouse cursors")
    group.add_option("--no-bell",
                     action="store_false",
                     dest="bell",
                     default=defaults.bell,
                     help="Disable forwarding of the system bell")
    group.add_option(
        "--no-mmap",
        action="store_false",
        dest="mmap",
        default=defaults.mmap,
        help="Disable memory mapped transfers for local connections")
    group.add_option(
        "--readonly",
        action="store_true",
        dest="readonly",
        default=defaults.readonly,
        help="Ignore all keyboard input and mouse events from the clients")
    group.add_option(
        "--enable-sharing",
        action="store_true",
        dest="sharing",
        default=defaults.sharing,
        help="Allow more than one client to connect to the same session")
    group.add_option(
        "--no-speaker",
        action="store_false",
        dest="speaker",
        default=defaults.speaker,
        help="Disable forwarding of sound output to the client(s)")
    CODEC_HELP = """Specify the codec(s) to use for forwarding the %s sound output.
This parameter can be specified multiple times and the order in which the codecs
are specified defines the preferred codec order.
Use the special value 'help' to get a list of options.
When unspecified, all the available codecs are allowed and the first one is used."""
    group.add_option("--speaker-codec",
                     action="append",
                     dest="speaker_codec",
                     default=defaults.speaker_codec,
                     help=CODEC_HELP % "speaker")
    group.add_option("--no-microphone",
                     action="store_false",
                     dest="microphone",
                     default=defaults.microphone,
                     help="Disable forwarding of sound input to the server")
    group.add_option("--microphone-codec",
                     action="append",
                     dest="microphone_codec",
                     default=defaults.microphone_codec,
                     help=CODEC_HELP % "microphone")

    group = OptionGroup(
        parser, "Client Picture Encoding and Compression Options",
        "These options are used by the client to specify the desired picture and network data compression."
        "They may also be specified on the server as default values for those clients that do not set them."
    )
    parser.add_option_group(group)
    group.add_option(
        "--encoding",
        action="store",
        metavar="ENCODING",
        default=defaults.encoding,
        dest="encoding",
        type="str",
        help=
        "What image compression algorithm to use, specify 'help' to get a list of options."
        " Default: %default.")
    group.add_option(
        "--min-quality",
        action="store",
        metavar="MIN-LEVEL",
        dest="min_quality",
        type="int",
        default=defaults.min_quality,
        help=
        "Sets the minimum encoding quality allowed in automatic quality setting (from 1 to 100, 0 to leave unset). Default: %default."
    )
    group.add_option(
        "--quality",
        action="store",
        metavar="LEVEL",
        dest="quality",
        type="int",
        default=defaults.quality,
        help=
        "Use a fixed image compression quality - only relevant to lossy encodings (1-100, 0 to use automatic setting). Default: %default."
    )
    group.add_option(
        "--min-speed",
        action="store",
        metavar="SPEED",
        dest="min_speed",
        type="int",
        default=defaults.min_speed,
        help=
        "Sets the minimum encoding speed allowed in automatic speed setting (1-100, 0 to leave unset). Default: %default."
    )
    group.add_option(
        "--speed",
        action="store",
        metavar="SPEED",
        dest="speed",
        type="int",
        default=defaults.speed,
        help=
        "Use image compression with the given encoding speed (1-100, 0 to use automatic setting). Default: %default."
    )
    group.add_option(
        "--auto-refresh-delay",
        action="store",
        dest="auto_refresh_delay",
        type="float",
        default=defaults.auto_refresh_delay,
        metavar="DELAY",
        help="Idle delay in seconds before doing an automatic lossless refresh."
        + " 0.0 to disable." + " Default: %default.")
    group.add_option(
        "-z",
        "--compress",
        action="store",
        dest="compression_level",
        type="int",
        default=defaults.compression_level,
        metavar="LEVEL",
        help="How hard to work on compressing data." +
        " You generally do not need to use this option," +
        " the default value should be adequate," +
        " picture data is compressed separately (see --encoding)." +
        " 0 to disable compression," +
        " 9 for maximal (slowest) compression. Default: %default.")

    group = OptionGroup(
        parser, "Client Features Options",
        "These options control client features that affect the appearance or the keyboard."
    )
    parser.add_option_group(group)
    group.add_option(
        "--opengl",
        action="store",
        dest="opengl",
        default=defaults.opengl,
        help=
        "Use OpenGL accelerated rendering, options: yes,no,auto. Default: %s."
        % print_bool("opengl", defaults.opengl))
    group.add_option(
        "--no-windows",
        action="store_false",
        dest="windows",
        default=defaults.windows,
        help=
        "Tells the server not to send any window data, only notifications and bell events will be forwarded (if enabled)."
    )
    group.add_option(
        "--session-name",
        action="store",
        dest="session_name",
        default=defaults.session_name,
        help=
        "The name of this session, which may be used in notifications, menus, etc. Default: Xpra"
    )
    group.add_option(
        "--client-toolkit",
        action="store",
        dest="client_toolkit",
        default=defaults.client_toolkit,
        help=
        "The type of client toolkit. Use the value 'help' to get a list of options. Default: %s"
    )
    group.add_option(
        "--window-layout",
        action="store",
        dest="window_layout",
        default=defaults.window_layout,
        help=
        "The type of window layout to use, each client toolkit may provide different layouts."
        "use the value 'help' to get a list of possible layouts. Default: %s")
    group.add_option(
        "--title",
        action="store",
        dest="title",
        default=defaults.title,
        help=
        "Text which is shown as window title, may use remote metadata variables (default: '%default')"
    )
    group.add_option(
        "--window-icon",
        action="store",
        dest="window_icon",
        default=defaults.window_icon,
        help=
        "Path to the default image which will be used for all windows (the application may override this)"
    )
    # let the platform specific code add its own options:
    # adds "--no-tray" for platforms that support it
    add_client_options(group)
    hidden_options["no_tray"] = False
    hidden_options["delay_tray"] = False
    group.add_option(
        "--tray-icon",
        action="store",
        dest="tray_icon",
        default=defaults.tray_icon,
        help=
        "Path to the image which will be used as icon for the system-tray or dock"
    )
    group.add_option(
        "--key-shortcut",
        action="append",
        dest="key_shortcut",
        type="str",
        default=defaults.key_shortcut,
        help="Define key shortcuts that will trigger specific actions." +
        "If no shortcuts are defined, it defaults to '%s'" %
        (",".join(defaults.key_shortcut or [])))
    group.add_option(
        "--no-keyboard-sync",
        action="store_false",
        dest="keyboard_sync",
        default=defaults.keyboard_sync,
        help=
        "Disable keyboard state synchronization, prevents keys from repeating on high latency links but also may disrupt applications which access the keyboard directly"
    )

    group = OptionGroup(
        parser, "Advanced Options",
        "These options apply to both client and server. Please refer to the man page for details."
    )
    parser.add_option_group(group)
    group.add_option(
        "--password-file",
        action="store",
        dest="password_file",
        default=defaults.password_file,
        help=
        "The file containing the password required to connect (useful to secure TCP mode)"
    )
    group.add_option(
        "--dpi",
        action="store",
        dest="dpi",
        default=defaults.dpi,
        help=
        "The 'dots per inch' value that client applications should try to honour (default: %default)"
    )
    default_socket_dir_str = defaults.socket_dir or "$XPRA_SOCKET_DIR or '~/.xpra'"
    group.add_option(
        "--socket-dir",
        action="store",
        dest="socket_dir",
        default=defaults.socket_dir,
        help="Directory to place/look for the socket files in (default: %s)" %
        default_socket_dir_str)
    debug_default = ""
    if defaults.debug:
        debug_default = "all"
    group.add_option(
        "-d",
        "--debug",
        action="store",
        dest="debug",
        default=debug_default,
        metavar="FILTER1,FILTER2,...",
        help="List of categories to enable debugging for (or \"all\")")
    group.add_option("--ssh",
                     action="store",
                     dest="ssh",
                     default=defaults.ssh,
                     metavar="CMD",
                     help="How to run ssh (default: '%default')")
    group.add_option(
        "--mmap-group",
        action="store_true",
        dest="mmap_group",
        default=defaults.mmap_group,
        help=
        "When creating the mmap file with the client, set the group permission on the mmap file to the same value as the owner of the server socket file we connect to (default: '%default')"
    )
    group.add_option(
        "--enable-pings",
        action="store_true",
        dest="pings",
        default=defaults.pings,
        help="Send ping packets every second to gather latency statistics")
    group.add_option(
        "--clipboard-filter-file",
        action="store",
        dest="clipboard_filter_file",
        default=defaults.clipboard_filter_file,
        help=
        "Name of a file containing regular expressions of clipboard contents that must be filtered out"
    )
    group.add_option(
        "--remote-xpra",
        action="store",
        dest="remote_xpra",
        default=defaults.remote_xpra,
        metavar="CMD",
        help="How to run xpra on the remote host (default: '%default')")
    if len(ENCRYPTION_CIPHERS) > 0:
        group.add_option(
            "--encryption",
            action="store",
            dest="encryption",
            default=defaults.encryption,
            metavar="ALGO",
            help=
            "Specifies the encryption cipher to use, only %s is currently supported. (default: None)"
            % (", ".join(ENCRYPTION_CIPHERS)))
    else:
        hidden_options["encryption"] = ''

    options, args = parser.parse_args(cmdline[1:])
    if not args:
        parser.error("need a mode")

    #ensure all the option fields are set even though
    #some options are not shown to the user:
    for k, v in hidden_options.items():
        if not hasattr(options, k):
            setattr(options, k, v)

    #forward compatibility for correct encoding names:
    if options.encoding == "h264":
        options.encoding = "x264"
    elif options.encoding == "vp8":
        options.encoding = "vpx"
    elif options.encoding == "webp":
        #warn that webp should not be used:
        print("Warning: webp encoding may leak memory!")

    #special handling for URL mode:
    #xpra attach xpra://[mode:]host:port/?param1=value1&param2=value2
    if len(args) == 2 and args[0] == "attach" and args[1].startswith(
            "xpra://"):
        url = args[1]
        from urlparse import urlparse, parse_qs
        up = urlparse(url)
        address = up.netloc
        qpos = url.find("?")
        if qpos > 0:
            params_str = url[qpos + 1:]
            params = parse_qs(params_str, keep_blank_values=True)
            f_params = {}
            #print("params=%s" % str(params))
            for k, v in params.items():
                t = OPTION_TYPES.get(k)
                if t is not None and t != list:
                    v = v[0]
                f_params[k] = v
            v_params = validate_config(f_params)
            for k, v in v_params.items():
                setattr(options, k, v)
        al = address.lower()
        if not al.startswith(":") and not al.startswith(
                "tcp") and not al.startswith("ssh"):
            #assume tcp if not specified
            address = "tcp:%s" % address
        args[1] = address

    try:
        int(options.dpi)
    except Exception, e:
        parser.error("invalid dpi: %s" % e)