[X2go-Commits] pyhoca-cli.git - build-main (branch) updated: 0.1.4.2

X2go dev team git-admin at x2go.org
Wed Sep 7 20:21:03 CEST 2011


The branch, build-main has been updated
       via  6225f29139d86cb730453772e5a0a07c1e7da9c8 (commit)
       via  473364d57429435b36b1f546e1442cd882cc624e (commit)
       via  d5c1ff7f2e31a150aa241acd7317fabb940e5439 (commit)
       via  1d7da12b3de5787b7ada39333601bccbe50f4c5c (commit)
       via  37ba4e6f7dfa24bf27cab76c6588344da5a6b4a4 (commit)
       via  3e307a9bfbb2f945dcb8c887b122cd8bb9087b4b (commit)
       via  cde819a720c1ae037c56e2b2f81d0c19a86ca244 (commit)
       via  efdb5891fcc0086c3f512d95a5fea9ab17c64da2 (commit)
       via  ba599ba09b3b6a0a6de151e1ad0dc2d5631d1e40 (commit)
      from  47aa48ba7d8fb6f6b36034e0f7ca8f52bd690df7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
-----------------------------------------------------------------------

Summary of changes:
 .build_man2html/html/man1/pyhoca-cli.1.html |  213 ---------------------------
 Makefile.docupload                          |   20 +++
 debian/changelog                            |   15 ++
 man/man1/pyhoca-cli.1                       |   34 +++--
 pyhoca-cli                                  |   11 +-
 pyhoca/cli/__init__.py                      |    2 +-
 pyhoca/cli/frontend.py                      |  108 ++++++++++++--
 7 files changed, 162 insertions(+), 241 deletions(-)
 delete mode 100644 .build_man2html/html/man1/pyhoca-cli.1.html
 create mode 100644 Makefile.docupload

The diff of changes is:
diff --git a/.build_man2html/html/man1/pyhoca-cli.1.html b/.build_man2html/html/man1/pyhoca-cli.1.html
deleted file mode 100644
index c2ae09c..0000000
--- a/.build_man2html/html/man1/pyhoca-cli.1.html
+++ /dev/null
@@ -1,213 +0,0 @@
-Content-type: text/html
-
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-<HTML><HEAD><TITLE>Man page of pyhoca-cli</TITLE>
-</HEAD><BODY>
-<H1>pyhoca-cli</H1>
-Section: X2go Application (1)<BR>Updated: 26 May 2011<BR><A HREF="#index">Index</A>
-<A HREF="../index.html">Return to Main Contents</A><HR>
-
-<A NAME="lbAB"> </A>
-<H2>NAME</H2>
-
-pyhoca-cli - X2go command line client written in Python
-<A NAME="lbAC"> </A>
-<H2>SYNOPSIS</H2>
-
-
-
-
-<B>pyhoca-cli</B> 
-
-
-[
-<I>options</I>
-]
-
-
-
-<A NAME="lbAD"> </A>
-<H2>DESCRIPTION</H2>
-
-<B>pyhoca-cli</B> aims to be a cross-platform (Windows, Mac OS X, Linux) X2go command line client written 
-in Python.
-<P>
-
-You can use it 
-for scripting remote X2go sessions or simply starting, resuming or shadowing X2go sessions from
-the command line in a terminal. 
-<P>
-
-It supports versatile
-command line options as well as parsing <B>x2goclient</B> configuration
-files.
-<P>
-
-See the included README and TODO for further information on <B>pyhoca-cli</B>.
-<A NAME="lbAE"> </A>
-<H2>COMMON OPTIONS</H2>
-
-<B>pyhoca-cli</B> accepts the following common options:
-<DL COMPACT>
-<DT><B>-h, --help</B> <DD>
-Display a help with all available command line options and exit.
-<DT><B>-V, --version</B> <DD>
-Output version information and exit.
-<DT><B>-d, --debug</B> <DD>
-Enable debugging output.
-<DT><B>--libdebug</B> <DD>
-Enable debugging code of the unterlying Python X2go module.
-<DT><B>--libdebug-sftpxfer</B> <DD>
-Enable debugging code of Python X2go's sFTP server code (very verbose, and it may even reveal promiscuous data).
-</DL>
-<A NAME="lbAF"> </A>
-<H2>SERVER</H2>
-
-<DL COMPACT>
-<DT><B>--server</B> <I><HOSTNAME_or_IP></I> <DD>
-If not in LDAP mode you always have to name the remote X2go server's hostname or IP address.
-</DL>
-<A NAME="lbAG"> </A>
-<H2>ACTIONS</H2>
-
-<B>pyhoca-cli</B> accepts exclusively one of the listed actions:
-<DL COMPACT>
-<DT><B>-N, --new</B> <DD>
-Start a new X2go session on server (default mode if no mode is explicitly specified).
-<DT><B>-R, --resume</B> <I><SESSION_NAME></I> <DD>
-Resume existing X2go session <SESSION_NAME> on server.
-<DT><B>-S, --suspend</B> <I><SESSION_NAME></I> <DD>
-Suspend running X2go session <SESSION_NAME>.
-<DT><B>-T, --terminate</B> <I><SESSION_NAME></I> <DD>
-Terminate running X2go session <SESSION_NAME> .
-<DT><B>-L, --list-sessions</B> <DD>
-List user's X2go sessions on server.
-</DL>
-<A NAME="lbAH"> </A>
-<H2>X2GO OPTIONS</H2>
-
-<DL COMPACT>
-<DT><B>-P, --session-profile</B><DD>
-The name of the session profile to be used to make the connection.B
-<DT><B>-c, --command</B> <I><CMD></I> <DD>
-Command to run with <B>--new</B> mode on server (default: xterm).
-<DT><B>-u, --username</B> <I><USERNAME></I> <DD>
-Username for the session (default: currently logged in user).
-<DT><B>--password</B> <I><PASSWORD></I> <DD>
-User password for this session. If a matching private SSH key is available this one will be preferred for
-authentication. The cleartext password that has been specified at the command line will be masqueraded in
-the systems process list (Linux, MacOS). On Windows systems the usage of the --password option is forbidden.
-<DT><B>-p, --remote-ssh-port</B> <I><R_PORT></I> <DD>
-Remote X2go server's SSH port (default: 22).
-<DT><B>-k, --ssh-privkey</B> <I><SSH_PRIVKEY></I> <DD>
-Use file <SSH_PRIVKEY> as private key for SSH connections (default: ~/.ssh/id_rsa).
-<DT><B>--add-to-known-hosts</B> <DD>
-Add RSA/DSA host key to ~/.ssh/known_hosts if authenticity of server can't be established (default: not set).
-<DT><B>--sound</B> <I>{pulse|esd|none}</I> <DD>
-X2go server's sound system (default: 'pulse').
-<DT><B>-F, --share-local-folders</B> <I><folder1>[,<folder2>[,...]]</I> <DD>
-A comma separated list of local folders that shall be made available in the remote X2go session.
-<DT><B>--printing</B> <DD>
-Use X2go printing (default: disabled).
-<DT><B>--clean-sessions</B> <DD>
-Clean all of the user's suspended/running sessions before starting a new one on the named X2go server.
-<DT><B>--time-to-wait</B> <DD>
-Time to wait for session startup/resume (default: 8s). There should be no need to touch this, unless on very slow network connections.
-</DL>
-<A NAME="lbAI"> </A>
-<H2>LDAP OPTIONS</H2>
-
-LDAP support is planned to be added into <B>pyhoca-cli</B> in the near future. So stay tuned...
-<P>
-
-<A NAME="lbAJ"> </A>
-<H2>NX OPTIONS (Version 3) </H2>
-
-<DL COMPACT>
-<DT><B>-g, --geometry</B> <I>{<WIDTH>x<HEIGHT>|fullscreen}</I> <DD>
-Screen geometry (default: '800x600').
-<DT><B>-q, --link</B> <I>{modem|isdn|adsl|wan|lan}</I> <DD>
-link quality (default: 'adsl')
-<DT><B>-t, --session-type</B> <I>{desktop|application}</I> <DD>
-Session type (default: 'application'). Note: there are also some auto-detection 
-feature for the session type built into the code. 
-It might not always happen what you expect from setting this option.
-<DT><B>-p, --pack</B> <I><PACK_METHOD></I><DD>
-Compression method (see below for possible values).
-<DT><B>--kbd-layout</B> <I>{us|de|fr|...}</I><DD>
-Use keyboard layout (default: 'us').
-<DT><B>--kbd-type</B> <I>{pc105/us|pc105/de|...}</I><DD>
-Set Keyboard type (default 'pc105/us').
-</DL>
-<A NAME="lbAK"> </A>
-<H2>COMPATIBILITY OPTIONS</H2>
-
-<B>pyhoca-cli</B> aims at being fully compatible with all command line options and session config files of the X2go project's X2go command
-line client <B>x2goclient-cli</B> as well as the <B>x2goclient</B> GUI. This is still work in progress. 
-To achieve this, some compatibility options have already
-been added:
-<DL COMPACT>
-<DT><B>--port</B> <I><R_PORT></I><DD>
-Compatibility option, synonymous to <B>--remote-ssh-port</B> <I><R_PORT></I>.
-<DT><B>--ssh-key</B> <I><SSH_PRIVKEY></I><DD>
-Compatibility option, synonymous to <B>--ssh-privkey</B> <I>SSH_KEY</I>.
-<DT><B>--use-sound</B> <I>{yes|no}</I><DD>
-Compatibility option, synonymous to <B>--sound</B> <I>{pulse|none}</I>.
-<DT><B>--client-ssh-port</B> <I><PORT></I> <DD>
-Compatibility option for the x2goclient GUI. PyHoca-Cli (resp. Python X2go) brings its own internal sFTP server. Thus, this option will be ignored.
-</DL>
-<A NAME="lbAL"> </A>
-<H2>NX COMPRESSION METHODS</H2>
-
-As NX compression methods (<B>--pack</B> option) the following values are possible. The % character must be replaced by a digit 0-9.
-<P>
-
-nopack, 8, 64, 256, 512, 4k, 32k, 64k, 256k, 2m, 16m
-256-rdp, 256-rdp-compressed, 32k-rdp, 32k-rdp-compressed, 64k-rdp
-64k-rdp-compressed, 16m-rdp, 16m-rdp-compressed
-rfb-hextile, rfb-tight, rfb-tight-compressed
-8-tight, 64-tight, 256-tight, 512-tight, 4k-tight, 32k-tight
-64k-tight, 256k-tight, 2m-tight, 16m-tight
-8-jpeg-%, 64-jpeg, 256-jpeg, 512-jpeg, 4k-jpeg, 32k-jpeg
-64k-jpeg, 256k-jpeg, 2m-jpeg, 16m-jpeg-%
-8-png-jpeg-%, 64-png-jpeg, 256-png-jpeg, 512-png-jpeg, 4k-png-jpeg
-32k-png-jpeg, 64k-png-jpeg, 256k-png-jpeg, 2m-png-jpeg, 16m-png-jpeg-%
-8-png-%, 64-png, 256-png, 512-png, 4k-png
-32k-png, 64k-png, 256k-png, 2m-png, 16m-png-%
-16m-rgb-%, 16m-rle-%
-<A NAME="lbAM"> </A>
-<H2>SEE ALSO</H2>
-
-<B>/usr/share/doc/python-x2go</B>
-<A NAME="lbAN"> </A>
-<H2>AUTHOR</H2>
-
-This manual has been written by for the X2go project (<A HREF="http://www.x2go.org)">http://www.x2go.org)</A> by
-<P>
-Mike Gabriel <<A HREF="mailto:mike.gabriel at das-netzwerkteam.de">mike.gabriel at das-netzwerkteam.de</A>> 
-<P>
-
-<HR>
-<A NAME="index"> </A><H2>Index</H2>
-<DL>
-<DT><A HREF="#lbAB">NAME</A><DD>
-<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
-<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
-<DT><A HREF="#lbAE">COMMON OPTIONS</A><DD>
-<DT><A HREF="#lbAF">SERVER</A><DD>
-<DT><A HREF="#lbAG">ACTIONS</A><DD>
-<DT><A HREF="#lbAH">X2GO OPTIONS</A><DD>
-<DT><A HREF="#lbAI">LDAP OPTIONS</A><DD>
-<DT><A HREF="#lbAJ">NX OPTIONS (Version 3) </A><DD>
-<DT><A HREF="#lbAK">COMPATIBILITY OPTIONS</A><DD>
-<DT><A HREF="#lbAL">NX COMPRESSION METHODS</A><DD>
-<DT><A HREF="#lbAM">SEE ALSO</A><DD>
-<DT><A HREF="#lbAN">AUTHOR</A><DD>
-</DL>
-<HR>
-This document was created by
-<A HREF="/cgi-bin/man/man2html">man2html</A>,
-using the manual pages.<BR>
-Time: 09:14:04 GMT, May 30, 2011
-</BODY>
-</HTML>
diff --git a/Makefile.docupload b/Makefile.docupload
new file mode 100644
index 0000000..1a6c71d
--- /dev/null
+++ b/Makefile.docupload
@@ -0,0 +1,20 @@
+#!/usr/bin/make -f
+# Makefile.docupload file - for pyhoca-cli
+# Copyright 2010-2011 by Mike Gabriel <mike.gabriel at das-netzwerkteam.de>, GPLv3 applies to this file
+
+VERSION=`head -n1 debian/changelog | sed 's,.*(\(.*\)).*,\1,' | cut -d"-" -f1`
+DOC_HOST=code.x2go.org
+DOC_PATH=/srv/sites/x2go.org/packages/doc/pyhoca-cli/man/
+DOC_USER=x2go-admin
+
+doc: docbuild docupload
+
+docbuild:
+	make -f Makefile.man2html build_man2html
+
+docupload:
+	
+	ssh -l${DOC_USER} ${DOC_HOST} "{ mkdir -p ${DOC_PATH}; rm -Rfv ${DOC_PATH}/*; }"
+	scp -r .build_man2html/html/* ${DOC_USER}@${DOC_HOST}:${DOC_PATH}/
+
+
diff --git a/debian/changelog b/debian/changelog
index 7a7217c..0ff89d5 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,18 @@
+pyhoca-cli (0.1.4.2-0~x2go1) unstable; urgency=low
+
+  * New upstream version (0.1.4.2):
+    - Translate cmd line options into python-x2go options
+    - Allow ,,ALL'' as session name when suspending -> will suspend
+      all sessions of the connecting user.
+    - Allow ,,ALL'' as session name when terminating -> will terminate
+      all sessions of the connecting user.
+    - Allow ,,NEWEST'' and ,,OLDEST'' as session name when resuming (closes
+      upstream issue #86).
+    - Add cmd line option --terminate-on-ctrl-c.
+    - Add cmd line option --auth-attempts.
+
+ -- Mike Gabriel <mike.gabriel at das-netzwerkteam.de>  Wed, 07 Sep 2011 20:19:16 +0200
+
 pyhoca-cli (0.1.4.1-0~x2go1) unstable; urgency=low
 
   * New upstream version (0.1.4.1):
diff --git a/man/man1/pyhoca-cli.1 b/man/man1/pyhoca-cli.1
index 7fa18a0..b16cbee 100644
--- a/man/man1/pyhoca-cli.1
+++ b/man/man1/pyhoca-cli.1
@@ -54,10 +54,16 @@ Enable debugging code of the unterlying Python X2go module.
 .TP 
 \*(T<\fB\-\-libdebug-sftpxfer\fR\*(T> 
 Enable debugging code of Python X2go's sFTP server code (very verbose, and it may even reveal promiscuous data).
-.SH SERVER
+.SH SERVER / SESSION PROFILE
+You either have to specify a server name or a pre-configured X2goClient session profile to tell \fBpyhoca-cli\fR to
+what X2go server to connect. \fBpyhoca-cli\fR will not start
+if neither of these two options has been given on the command line.
 .TP
 \*(T<\fB\-\-server\fR \fI<HOSTNAME_or_IP>\fR\*(T> 
 If not in LDAP mode you always have to name the remote X2go server's hostname or IP address.
+.TP 
+\*(T<\fB\-P, \-\-session-profile\fR \fI<SESSION_PROFILE_NAME>\fR\*(T>
+The name of the session profile to be used to make the connection.
 .SH ACTIONS
 \fBpyhoca-cli\fR accepts exclusively one of the listed actions:
 .TP
@@ -65,7 +71,8 @@ If not in LDAP mode you always have to name the remote X2go server's hostname or
 Start a new X2go session on server (default mode if no mode is explicitly specified).
 .TP 
 \*(T<\fB\-R, \-\-resume\fR \fI<SESSION_NAME>\fR\*(T> 
-Resume existing X2go session <SESSION_NAME> on server.
+Resume existing X2go session <SESSION_NAME> on server. Special values for <SESSION_NAME> are ,,NEWEST'' (will resume youngest session)
+or ,,OLDEST'' (resume session with oldest timestamp).
 .TP 
 \*(T<\fB\-D, \-\-share-desktop\fR \fI<USER>@<DISPLAY>\fR\*(T>
 Share an X2go session on the remote server specified by <USER>@<DISPLAY>,
@@ -73,18 +80,23 @@ whereas <USER> can be the same user that is starting the share mode session or a
 other user that grants X2go desktop sharing for the current user.
 .TP 
 \*(T<\fB\-S, \-\-suspend\fR \fI<SESSION_NAME>\fR\*(T> 
-Suspend running X2go session <SESSION_NAME>.
+Suspend running X2go session <SESSION_NAME>. A special value for <SESSION_NAME> is ,,ALL'' (will suspend all sessions of the connected user).
 .TP 
 \*(T<\fB\-T, \-\-terminate\fR \fI<SESSION_NAME>\fR\*(T> 
-Terminate running X2go session <SESSION_NAME> .
+Terminate running X2go session <SESSION_NAME>. A special value for <SESSION_NAME> is ,,ALL'' (will terminate all sessions of the connected user).
 .TP 
 \*(T<\fB\-L, \-\-list-sessions\fR\*(T> 
 List user's X2go sessions on server.
+.SH ACTION OPTIONS
+\fBpyhoca-cli\fR actions can be tweaked by these options:
+.TP
+\*(T<\fB\-\-clean-sessions\fR\*(T> 
+Clean all of the user's suspended/running sessions before starting a new one on the named X2go server.
+.TP
+\*(T<\fB\-\-terminate-on-ctrl-c\fR\*(T> 
+Terminate the connected session when pressing CTRL+C (instead of suspending the session).
 .SH X2GO OPTIONS
 .TP 
-\*(T<\fB\-P, \-\-session-profile\fR\*(T>
-The name of the session profile to be used to make the connection.B
-.TP 
 \*(T<\fB\-c, \-\-command\fR \fI<CMD>\fR\*(T> 
 Command to run with \fB\-\-new\fR mode on server (default: xterm).
 .TP 
@@ -117,11 +129,13 @@ Use X2go printing (default: disabled).
 \*(T<\fB\-\-share-mode\fR \fI{0|1}\fR\*(T> 
 Share mode for X2go desktop sharing (0: view-only, 1: full access).
 .TP
-\*(T<\fB\-\-clean-sessions\fR\*(T> 
-Clean all of the user's suspended/running sessions before starting a new one on the named X2go server.
-.TP 
 \*(T<\fB\-\-time-to-wait\fR\*(T> 
 Time to wait for session startup/resume (default: 8s). There should be no need to touch this, unless on very slow network connections.
+.TP
+\*(T<\fB\-\-auth-attempts\fR \fI{0,1,2,3,...}\fR\*(T> 
+Number of interactive authentication attempts in case authentication with the server fails (wrong password?). A value that equals 0
+disables interactive authentication completely and requires that a private SSH key has been given on the command line or in the
+session profile or that the --password command line option is used.
 .SH LDAP OPTIONS
 LDAP support is planned to be added into \fBpyhoca-cli\fR in the near future. So stay tuned...
 .PP
diff --git a/pyhoca-cli b/pyhoca-cli
index 34fb297..c6752d9 100755
--- a/pyhoca-cli
+++ b/pyhoca-cli
@@ -122,7 +122,9 @@ x2go_options =   [
                    {'args':['--share-mode'], 'default': 0, 'help': 'share mode for X2go desktop sharing (0: view-only, 1: full access)', },
                    {'args':['-F', '--share-local-folders'], 'metavar': '<folder1>[,<folder2[,...]]', 'default': None, 'help': 'a comma separated list of local folder names to mount in the X2go session', },
                    {'args':['--clean-sessions'], 'default': False, 'action': 'store_true', 'help': 'clean all suspended sessions before starting a new one', },
+                   {'args':['--terminate-on-ctrl-c'], 'default': False, 'action': 'store_true', 'help': 'terminate the connected session when pressing CTRL+C (instead of suspending the session)', },
                    {'args':['--time-to-wait'], 'default': '8', 'help': 'time to wait for session startup/resume (default: 8s)', },
+                   {'args':['--auth-attempts'], 'default': 3, 'help': 'number of authentication attempts before authentication fails (default: 3)', },
                  ]
 print_options =  [ 
                    {'args':['--print-action'], 'default': 'PDFVIEW', 'choices': PRINT_ACTIONS, 'help': 'action to be performed for incoming X2go print jobs (default: \'PDFVIEW\')', },
@@ -220,9 +222,9 @@ Possible values for the --pack NX option are:
 
     if not (a.session_profile or a.list_profiles):
 
-        # the --server options is required for most operations
+        # the --server (or --session-profile) option is required for most operations
         if not a.server:
-            runtime_error ("argument --server is required", parser=p, exitcode=1)
+            runtime_error ("argument --server (or --session-profile) 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.share_desktop) + bool(a.suspend) + bool(a.terminate) + bool(a.list_sessions) + bool(a.list_desktops) + bool(a.list_profiles)> 1:
@@ -294,6 +296,11 @@ 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(',')
 
+    try:
+        _dummy = 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:
 
         ##### TODO: ssh_config to be moved into Python X2go!!!!
diff --git a/pyhoca/cli/__init__.py b/pyhoca/cli/__init__.py
index 9ce6174..294b0ad 100644
--- a/pyhoca/cli/__init__.py
+++ b/pyhoca/cli/__init__.py
@@ -20,6 +20,6 @@
 """\
 STILL UNDOCUMENTED
 """
-__VERSION__ = "0.1.4.1"
+__VERSION__ = "0.1.4.2"
 
 from frontend import *
diff --git a/pyhoca/cli/frontend.py b/pyhoca/cli/frontend.py
index 8931e3d..363d9e9 100644
--- a/pyhoca/cli/frontend.py
+++ b/pyhoca/cli/frontend.py
@@ -166,6 +166,24 @@ class PyHocaCLI(x2go.X2goClient):
             self.logger('command from session profile to run is: %s' % self.session_registry(self.x2go_session_hash).get_session_cmd(), loglevel=x2go.loglevel_DEBUG, )
         self._X2goClient__start_session(s_hash)
 
+    def _auto_resume_newest(self, s_hash):
+        session_infos = self._X2goClient__list_sessions(s_hash)
+        if session_infos:
+            newest_session_name = x2go.utils.session_names_by_timestamp(session_infos)[-1]
+            self._pyhoca_logger("Resuming newest X2go session %s..." % newest_session_name, loglevel=x2go.loglevel_NOTICE, )
+            self._X2goClient__resume_session(s_hash, newest_session_name)
+            return True
+        return False
+
+    def _auto_resume_oldest(self, s_hash):
+        session_infos = self._X2goClient__list_sessions(s_hash)
+        if session_infos:
+            oldest_session_name = x2go.utils.session_names_by_timestamp(session_infos)[0]
+            self._pyhoca_logger("Resuming oldest X2go session %s..." % oldest_session_name, loglevel=x2go.loglevel_NOTICE, )
+            self._X2goClient__resume_session(s_hash, oldest_session_name)
+            return True
+        return False
+
     def resume_session(self, s_hash):
         """\
         STILL UNDOCUMENTED
@@ -173,7 +191,11 @@ class PyHocaCLI(x2go.X2goClient):
         # resume a running session
         self.logger('resuming X2go session: %s' % self.args.resume, loglevel=x2go.loglevel_INFO, )
         available_sessions = self._X2goClient__list_sessions(s_hash)
-        if self.args.resume in available_sessions.keys():
+        if available_sessions and self.args.resume == 'OLDEST':
+            self._auto_resume_oldest(s_hash)
+        elif available_sessions and self.args.resume == 'NEWEST':
+            self._auto_resume_newest(s_hash)
+        elif self.args.resume in available_sessions.keys():
             self._X2goClient__resume_session(s_hash, self.args.resume)
         else:
             self._runtime_error('requested session not available on X2go server [%s]:%s' % (self.args.server, self.args.remote_ssh_port), exitcode=20)
@@ -199,26 +221,54 @@ class PyHocaCLI(x2go.X2goClient):
         # send a suspend request to a session
         self.logger('requesting X2go session suspend of session: %s' % self.args.suspend, loglevel=x2go.loglevel_INFO, )
         available_sessions = self._X2goClient__list_sessions(s_hash)
-        if self.args.suspend in available_sessions.keys():
-            self._X2goClient__suspend_session(s_hash, self.args.suspend)
+
+        if self.args.suspend == "ALL":
+            _session_names = available_sessions
         else:
-            self._runtime_error('requested session not available on X2go server [%s]:%s' % (self.args.server, self.args.remote_ssh_port), exitcode=21)
+            _session_names = [ self.args.suspend ]
+
+        for _session_name in _session_names:
+            if _session_name in available_sessions.keys():
+                self._X2goClient__suspend_session(s_hash, _session_name)
+                self._pyhoca_logger("X2go session %s has been suspended" % _session_name, loglevel=x2go.loglevel_NOTICE, )
+            else:
+                _server = self.args.server
+                _remote_ssh_port = self.args.remote_ssh_port
+                if not self.args.server and self.args.session_profile:
+                    _server = self.session_profiles.get_value(self.session_profiles.to_profile_id(self.args.session_profile), 'host')
+                    _remote_ssh_port = self.session_profiles.get_value(self.session_profiles.to_profile_id(self.args.session_profile), 'sshport')
+                self._runtime_error('session %s not available on X2go server [%s]:%s' % (_session_name, _server, _remote_ssh_port), exitcode=21)
 
     def terminate_session(self, s_hash):
         """\
         STILL UNDOCUMENTED
+
         """
         # send a terminate request to a session
         self.logger('requesting X2go session terminate of session: %s' % self.args.terminate, loglevel=x2go.loglevel_INFO, )
         available_sessions = self._X2goClient__list_sessions(s_hash)
-        if self.args.terminate in available_sessions.keys():
-            self._X2goClient__terminate_session(s_hash, self.args.terminate)
+
+        if self.args.terminate == "ALL":
+            _session_names = available_sessions
         else:
-            self._runtime_error('requested session not available on X2go server [%s]:%s' % (self.args.server, self.args.remote_ssh_port), exitcode=22)
+            _session_names = [ self.args.terminate ]
+
+        for _session_name in _session_names:
+            if _session_name in available_sessions.keys():
+                self._X2goClient__terminate_session(s_hash, _session_name)
+                self._pyhoca_logger("X2go session %s has been terminated" % _session_name, loglevel=x2go.loglevel_NOTICE, )
+            else:
+                _server = self.args.server
+                _remote_ssh_port = self.args.remote_ssh_port
+                if not self.args.server and self.args.session_profile:
+                    _server = self.session_profiles.get_value(self.session_profiles.to_profile_id(self.args.session_profile), 'host')
+                    _remote_ssh_port = self.session_profiles.get_value(self.session_profiles.to_profile_id(self.args.session_profile), 'sshport')
+                self._runtime_error('session %s not available on X2go server [%s]:%s' % (_session_name, _server, _remote_ssh_port), exitcode=22)
 
     def __init__(self, args, logger=None, liblogger=None):
         """\
         STILL UNDOCUMENTED
+
         """
         self.args = args
         if logger is None:
@@ -236,14 +286,29 @@ class PyHocaCLI(x2go.X2goClient):
         if self.args.session_profile and not _profiles.has_profile(self.args.session_profile):
             self._runtime_error('no such session profile of name: %s' % (self.args.session_profile), exitcode=31)
 
+        self.auth_attempts = int(self.args.auth_attempts)
+
         if self.args.session_profile:
 
+            _cmdlineopt_to_sessionopt = {
+                'command': 'cmd',
+                'kb_layout': 'kblayout',
+                'kb_type': 'kbtype',
+                'sound': 'snd_system',
+                'ssh_privkey': 'key_filename',
+                'server': 'hostname',
+                'remote_ssh_port': 'port',
+            }
+
             # override session profile options by option values from the arg parser
             kwargs={}
             if hasattr(self.args, 'parser'):
                 for a, v in self.args._get_kwargs():
                     if v != self.args.parser.get_default(a):
-                        kwargs[a] = v
+                        try:
+                            kwargs[_cmdlineopt_to_sessionopt[a]] = v
+                        except KeyError:
+                            kwargs[a] = v
 
             # setup up the session profile based X2go session
             self.x2go_session_hash = self._X2goClient__register_session(profile_name=self.args.session_profile,
@@ -284,7 +349,7 @@ class PyHocaCLI(x2go.X2goClient):
         _username = self.args.username or self._X2goClient__get_session_username(self.x2go_session_hash)
         try:
 
-            _auth_count = 4
+            _auth_count = self.auth_attempts +1
             while not connected and _auth_count:
                 try:
                     self._X2goClient__connect_session(self.x2go_session_hash, username=_username, password=self.args.password, force_password_auth=force_password_auth)
@@ -312,8 +377,13 @@ class PyHocaCLI(x2go.X2goClient):
 
                 _auth_count -= 1
 
-                if not _auth_count:
-                    self._runtime_error('Authentication failed, too many failures during interactive login', exitcode=-201)
+                if not connected and not _auth_count:
+                    if self.auth_attempts >= 2:
+                        self._runtime_error('authentication failed, too many failures during interactive login', exitcode=-201)
+                    elif self.auth_attempts == 1:
+                        self._runtime_error('interactive authentication failed', exitcode=-202)
+                    else:
+                        self._runtime_error('non-interactive authentication failed', exitcode=-203)
 
         except socket.error, e:
             self._runtime_error('a socket error occured while establishing the connection: %s' % str(e), exitcode=-245)
@@ -359,14 +429,13 @@ class PyHocaCLI(x2go.X2goClient):
             elif self.args.new:
                 self.new_session(self.x2go_session_hash)
 
-            # finally call the MainLoop of PyHocaCLI
             if not (self.args.new or self.args.resume or self.args.share_desktop or self.args.session_profile):
                 sys.exit(0)
 
-            # give the session some time to come up...
-            # no CTRL-C is allowed during this phase...
+            if self.args.resume or self.args.new:
+                self._pyhoca_logger("give the X2go session some time to come up...", loglevel=x2go.loglevel_NOTICE, )
+
             i=0
-            self._pyhoca_logger("give the X2go session some time to come up...", loglevel=x2go.loglevel_NOTICE, )
             while i < self.args.time_to_wait:
                 time.sleep(1)
                 i+=1
@@ -379,8 +448,11 @@ class PyHocaCLI(x2go.X2goClient):
                 self._pyhoca_logger("X2go session name is: %s" % session_name, loglevel=x2go.loglevel_INFO, )
                 if self.args.share_desktop:
                     self._pyhoca_logger("Press CTRL+C to end desktop sharing for this session...", loglevel=x2go.loglevel_NOTICE, )
+                elif self.args.terminate_on_ctrl_c:
+                    self._pyhoca_logger("Press CTRL+C to terminate the running session...", loglevel=x2go.loglevel_NOTICE, )
                 else:
                     self._pyhoca_logger("Press CTRL+C to suspend the running session...", loglevel=x2go.loglevel_NOTICE, )
+
                 try:
 
                     session_duration = 0
@@ -406,6 +478,12 @@ class PyHocaCLI(x2go.X2goClient):
                         self._X2goClient__terminate_session(self.x2go_session_hash)
                         time.sleep(2)
                         self._pyhoca_logger("X2go session %s has been terminated" % session_name, loglevel=x2go.loglevel_NOTICE, )
+                    elif self.args.terminate_on_ctrl_c:
+                        self._pyhoca_logger("Terminating X2go session %s" % session_name, loglevel=x2go.loglevel_INFO, )
+                        self._X2goClient__terminate_session(self.x2go_session_hash)
+                        # giving nxproxy's SSH tunnel some time to settle
+                        time.sleep(2)
+                        self._pyhoca_logger("X2go session %s has been terminated" % session_name, loglevel=x2go.loglevel_NOTICE, )
                     else:
                         self._pyhoca_logger("Suspending X2go session %s" % session_name, loglevel=x2go.loglevel_INFO, )
                         self._X2goClient__suspend_session(self.x2go_session_hash)


hooks/post-receive
-- 
pyhoca-cli.git (Python X2go Client (command line client))

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "pyhoca-cli.git" (Python X2go Client (command line client)).




More information about the x2go-commits mailing list