[X2Go-Commits] [x2goclient] 10/94: * intermediate check-in on the way of proper session profile handling
git-admin at x2go.org
git-admin at x2go.org
Fri Dec 15 21:04:30 CET 2023
This is an automated email from the git hooks/post-receive script.
x2go pushed a commit to annotated tag 0.1.4.0
in repository x2goclient.
commit 4e17df006c8eb36d7247ad56abcfc60dda233501
Author: mike <mike at cdb5e8f1-f799-4276-8919-bce57fd91830>
Date: Fri Nov 5 23:50:49 2010 +0000
* intermediate check-in on the way of proper session profile handling
git-svn-id: https://svn.das-netzwerkteam.de/x2go/pyhoca-cli/trunk@28 cdb5e8f1-f799-4276-8919-bce57fd91830
---
pyhoca-cli | 67 ++++++++++++++++++++++++++++----------------------
pyhoca/cli/frontend.py | 55 ++++++++++++++++++++++-------------------
2 files changed, 67 insertions(+), 55 deletions(-)
diff --git a/pyhoca-cli b/pyhoca-cli
index 97bb404e..974f7856 100755
--- a/pyhoca-cli
+++ b/pyhoca-cli
@@ -76,7 +76,7 @@ action_options = [
{'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', },
- # NOT IMPLEMENTED {'args':['-I','--import-session'], 'default': False, 'action': 'store_true', 'help': 'import a session from an x2goclient config file and run it', },
+ {'args':['-P','--session-profile'], 'default': None, 'help': 'load x2goclient session profiles and use the session profile SESSION_PROFILE', },
]
# debug options...
debug_options = [
@@ -177,20 +177,6 @@ Possible values for the --pack NX option are:
if a.version:
version()
- # the --server options is required for most operations
- if not a.server:
- runtime_error ("argument --server is required", parser=p, exitcode=1)
-
- # 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.suspend) + bool(a.terminate) + bool(a.list_sessions) > 1:
- runtime_error ("modes --new, --resume, --suspend, --terminate and --list-sessions are mutually exclusive", parser=p, exitcode=2)
- if bool(a.new) + bool(a.resume) + bool(a.suspend) + bool(a.terminate) + bool(a.list_sessions) == 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)
-
# if no username is given we use the uid under which this programme is run
if a.username is None:
a.username = current_user
@@ -201,6 +187,22 @@ Possible values for the --pack NX option are:
except ValueError:
runtime_error("--time_to_wait value needs to be an integer value", parser=p, exitcode=80)
+ if not a.session_profile:
+
+ # the --server options is required for most operations
+ if not a.server:
+ runtime_error ("argument --server is required", parser=p, exitcode=1)
+
+ # 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.suspend) + bool(a.terminate) + bool(a.list_sessions) > 1:
+ runtime_error ("modes --new, --resume, --suspend, --terminate and --list-sessions are mutually exclusive", parser=p, exitcode=2)
+ if bool(a.new) + bool(a.resume) + bool(a.suspend) + bool(a.terminate) + bool(a.list_sessions) == 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)
+
# X2go printing
if ((a.pdfview_cmd and a.printer) or
(a.pdfview_cmd and a.save_to_folder) or
@@ -257,21 +259,26 @@ Possible values for the --pack NX option are:
if a.share_local_folders is not None:
a.share_local_folders = a.share_local_folders.split(',')
- ###
- ### initialize SSH context
- ###
- # 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()
+
+ if a.server:
+
+ ##### TODO: ssh_config to be moved into Python X2go!!!!
+ ###
+ ### initialize SSH context
+ ###
+ # 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)
diff --git a/pyhoca/cli/frontend.py b/pyhoca/cli/frontend.py
index 6df99468..11ff709a 100644
--- a/pyhoca/cli/frontend.py
+++ b/pyhoca/cli/frontend.py
@@ -176,24 +176,36 @@ class PyHocaCLI(x2go.X2goClient):
self.logger('preparing requested X2go session', x2go.loglevel_NOTICE, )
x2go.X2goClient.__init__(self, logger=liblogger)
- self.x2go_session_hash = self.register_session(args.server, port=int(self.args.remote_ssh_port),
- username=self.args.username,
- password=self.args.password,
- key_filename=self.args.ssh_privkey,
- add_to_known_hosts=self.args.add_to_known_hosts,
- profile_name = 'Pyhoca-Client_Session',
- session_type=self.args.session_type,
- link=self.args.link,
- geometry=self.args.geometry,
- pack=self.args.pack,
- cache_type='unix-kde',
- kblayout=self.args.kbd_layout,
- kbtype=self.args.kbd_type,
- snd_system=self.args.sound,
- printing=self.args.printing,
- print_action=self.args.print_action,
- print_action_args=self.args.print_action_args,
- cmd=self.args.command)
+ _profile_id = None
+ if self.args.session_profile:
+ self.load_session_profiles()
+ _profile_id = self.get_profile_id(self.args.session_profile)
+
+ if not _profile_id:
+
+ self.x2go_session_hash = self.register_session(args.server, port=int(self.args.remote_ssh_port),
+ username=self.args.username,
+ password=self.args.password,
+ key_filename=self.args.ssh_privkey,
+ add_to_known_hosts=self.args.add_to_known_hosts,
+ custom_profile_name = 'Pyhoca-Client_Session',
+ session_type=self.args.session_type,
+ link=self.args.link,
+ geometry=self.args.geometry,
+ pack=self.args.pack,
+ cache_type='unix-kde',
+ kblayout=self.args.kbd_layout,
+ kbtype=self.args.kbd_type,
+ snd_system=self.args.sound,
+ printing=self.args.printing,
+ print_action=self.args.print_action,
+ print_action_args=self.args.print_action_args,
+ share_local_folders=self.args.share_local_folders,
+ cmd=self.args.command)
+ else:
+
+ self.x2go_session_hash = self.register_session(profile_id = _profile_id)
+
self.with_session(self.x2go_session_hash).load_host_keys(ssh_known_hosts_filename)
@@ -245,7 +257,6 @@ class PyHocaCLI(x2go.X2goClient):
# finally call the MainLoop of PyHocaCLI
if not (self.args.new or self.args.resume):
- print 'exiting'
sys.exit(0)
# give the session some time to come up...
@@ -271,12 +282,6 @@ class PyHocaCLI(x2go.X2goClient):
time.sleep(2)
session_duration +=2
- if session_duration > 2 and not mounted and self.args.share_local_folders is not None:
- if self.with_session(self.x2go_session_hash).get_transport().reverse_tunnels['sshfs'][1] is not None:
- for _folder in self.args.share_local_folders:
- self.share_local_folder(self.x2go_session_hash, _folder)
- mounted = True
-
# wait a little longer before telling the user what had happened
time.sleep(2)
--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goclient.git
More information about the x2go-commits
mailing list