def parseargs(): global logger global liblogger p = argparse.ArgumentParser(description='X2Go pytis client.', epilog=""" Possible values for the --pack NX option are: %s """ % x2go.defaults.pack_methods_nx3_formatted, formatter_class=argparse.RawDescriptionHelpFormatter, add_help=True, argument_default=None) p_reqargs = p.add_argument_group('X2Go server name') p_reqargs.add_argument('--server', help='server hostname or IP address') p_actionopts = p.add_argument_group('client actions') p_debugopts = p.add_argument_group('debug options') p_x2goopts = p.add_argument_group('X2Go options') p_printopts = p.add_argument_group('X2Go print options') p_brokeropts = p.add_argument_group('X2Go Session Broker client options') p_nxopts = p.add_argument_group('NX options') p_backendopts = p.add_argument_group('Python X2Go backend options (for experts only)') p_compatopts = p.add_argument_group('compatibility options') option_groups = [(p_x2goopts, x2go_options), (p_printopts, print_options), (p_brokeropts, broker_options), (p_actionopts, action_options), (p_debugopts, debug_options), (p_nxopts, nx_options), (p_backendopts, backend_options), (p_compatopts, compat_options)] if on_windows(): p_pytis2goopts = p.add_argument_group('pytis2go options') option_groups.append((p_pytis2goopts, pytis2go_options)) for (p_group, opts) in option_groups: for opt in opts: args = opt['args'] del opt['args'] p_group.add_argument(*args, **opt) a = p.parse_args() if a.debug: logger.set_loglevel_debug() if a.libdebug: liblogger.set_loglevel_debug() if a.quiet: logger.set_loglevel_quiet() liblogger.set_loglevel_quiet() if a.libdebug_sftpxfer: liblogger.enable_debug_sftpxfer() if a.password and on_windows(): runtime_error("The --password option is forbidden on Windows platforms", parser=p, exitcode=222) if a.version: version() if not (a.session_profile or a.list_profiles): # check for mutual exclusiveness of -N, -R, -S, -T and -L, -N is # default if none of them is set if ((bool(a.new) + bool(a.resume) + bool(a.share_desktop) + bool(a.suspend) + bool(a.terminate) + bool(a.list_sessions) + bool(a.list_desktops) + bool(a.list_profiles)) > 1): runtime_error("modes --new, --resume, --share-desktop, --suspend, --terminate, " "--list-sessions, --list-desktops and " "--list-profiles are mutually exclusive", parser=p, exitcode=2) if ((bool(a.new) + bool(a.resume) + bool(a.share_desktop) + bool(a.suspend) + bool(a.terminate) + bool(a.list_sessions) + bool(a.list_desktops) + bool(a.list_profiles)) == 0): a.new = True # check if pack method is available if not x2go.utils.is_in_nx3packmethods(a.pack): runtime_error("unknown pack method '%s'" % args.pack, parser=p, exitcode=10) else: if not (a.resume or a.share_desktop or a.suspend or a.terminate or a.list_sessions or a.list_desktops or a.list_profiles): a.new = True # X2Go printing if (((a.pdfview_cmd and a.printer) or (a.pdfview_cmd and a.save_to_folder) or (a.pdfview_cmd and a.print_cmd) or (a.printer and a.save_to_folder) or (a.printer and a.print_cmd) or (a.print_cmd and a.save_to_folder))): runtime_error(("--pdfviewer, --save-to-folder, --printer and --print-cmd options are " "mutually exclusive"), parser=p, exitcode=81) if a.pdfview_cmd: a.print_action = 'PDFVIEW' elif a.save_to_folder: a.print_action = 'PDFSAVE' elif a.printer: a.print_action = 'PRINT' elif a.print_cmd: a.print_action = 'PRINTCMD' if a.pdfview_cmd is None and a.print_action == 'PDFVIEW': a.pdfview_cmd = x2go.defaults.DEFAULT_PDFVIEW_CMD if a.save_to_folder is None and a.print_action == 'PDFSAVE': a.save_to_folder = x2go.defaults.DEFAULT_PDFSAVE_LOCATION if a.printer is None and a.print_action == 'PRINT': # None means CUPS default printer... a.printer = None if a.print_cmd is None and a.print_action == 'PRINTCMD': a.print_cmd = x2go.defaults.DEFAULT_PRINTCMD_CMD a.print_action_args = {} if a.pdfview_cmd: a.print_action_args = {'pdfview_cmd': a.pdfview_cmd, } elif a.save_to_folder: a.print_action_args = {'save_to_folder': a.save_to_folder, } elif a.printer: a.print_action_args = {'printer': a.printer, } elif a.print_cmd: a.print_action_args = {'print_cmd': a.print_cmd, } # take care of compatibility options # option --use-sound yes as synonomyn for --sound if a.use_sound is not None: if a.use_sound == 'yes': a.sound = 'pulse' if a.use_sound == 'no': a.sound = 'none' if a.ssh_key is not None: a.ssh_privkey = a.ssh_key if a.port is not None: a.remote_ssh_port = a.port if a.share_local_folders is not None: a.share_local_folders = a.share_local_folders.split(',') try: int(a.auth_attempts) except ValueError: runtime_error("value for cmd line argument --auth-attempts has to be of type integer", parser=p, exitcode=1) if a.server: # check if SERVER is in .ssh/config file, extract information from there... ssh_config = paramiko.SSHConfig() from pyhoca.cli import ssh_config_filename ssh_config_fileobj = open(ssh_config_filename) ssh_config.parse(ssh_config_fileobj) ssh_host = ssh_config.lookup(a.server) if ssh_host: if 'hostname' in ssh_host.keys(): a.server = ssh_host['hostname'] if 'port' in ssh_host.keys(): a.remote_ssh_port = ssh_host['port'] ssh_config_fileobj.close() # check if ssh priv key exists if a.ssh_privkey and not os.path.isfile(a.ssh_privkey): runtime_error("SSH private key %s file does not exist." % a.ssh_privkey, parser=p, exitcode=30) # lightdm remote login magic takes place here if not on_windows() and a.from_stdin: lightdm_remote_login_buffer = sys.stdin.readline() (a.username, a.server, a.command) = lightdm_remote_login_buffer.split()[0:3] a.password = "******".join(lightdm_remote_login_buffer.split()[3:]) if ":" in a.server: a.remote_ssh_port = a.server.split(':')[-1] a.server = ':'.join(a.server.split(':')[:-1]) a.command = a.command.upper() a.geometry = 'fullscreen' return p, a
{'args': ['-D', '--share-desktop'], 'default': None, 'metavar': 'USER@DISPLAY', 'help': 'share an X2Go session on server specified by USER@DISPLAY', }, {'args': ['-S', '--suspend'], 'default': None, 'metavar': 'SESSION_NAME', 'help': 'suspend running X2Go session SESSION_NAME', }, {'args': ['-T', '--terminate'], 'default': None, 'metavar': 'SESSION_NAME', 'help': 'terminate running X2Go session SESSION_NAME', }, {'args': ['-L', '--list-sessions'], 'default': False, 'action': 'store_true', 'help': 'list user\'s X2Go sessions on server', }, {'args': ['--list-desktops'], 'default': False, 'action': 'store_true', 'help': 'list X2Go desktop sessions that are available for sharing', }, {'args': ['-l', '--list-profiles'], 'default': False, 'action': 'store_true', 'help': 'list user\'s X2Go pre-configured session profiles', }, {'args': ['-P', '--session-profile'], 'default': None, 'help': 'load x2goclient session profiles and use the session profile SESSION_PROFILE', }, ] if not on_windows(): action_options.append( {'args': ['--from-stdin'], 'default': False, 'action': 'store_true', 'help': ('for LightDM remote login: '******'read <username> <password> <host[:port]> <desktopshell> from STDIN'), }, ) # debug options... debug_options = [ {'args': ['-d', '--debug'], 'default': False, 'action': 'store_true', 'help': 'enable application debugging code', }, {'args': ['--quiet'], 'default': False, 'action': 'store_true', 'help': 'disable any kind of log output', }, {'args': ['--libdebug'], 'default': False, 'action': 'store_true', 'help': 'enable debugging code of the underlying Python X2Go module', }, {'args': ['--libdebug-sftpxfer'], 'default': False, 'action': 'store_true',