[X2Go-Commits] [x2goclient] 07/94: * fixed pyhoca-cli
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 5cf374abea625fe956a7db380b3e1f7a00f6b4e5
Author: mike <mike at cdb5e8f1-f799-4276-8919-bce57fd91830>
Date: Mon Nov 1 09:50:29 2010 +0000
* fixed pyhoca-cli
git-svn-id: https://svn.das-netzwerkteam.de/x2go/pyhoca-cli/trunk@20 cdb5e8f1-f799-4276-8919-bce57fd91830
---
pyhoca-cli | 5 ++--
pyhoca/cli/frontend.py | 62 ++++++++++++++++++++++++++++++++++++++------------
2 files changed, 50 insertions(+), 17 deletions(-)
diff --git a/pyhoca-cli b/pyhoca-cli
index 632c0fa9..97bb404e 100755
--- a/pyhoca-cli
+++ b/pyhoca-cli
@@ -45,7 +45,7 @@ from x2go.defaults import DEFAULT_PDFVIEW_CMD
from x2go.defaults import DEFAULT_PDFSAVE_LOCATION
from x2go.defaults import DEFAULT_PRINTCMD_CMD
-from pyhoca.cli import current_home, PyHocaCLI
+from pyhoca.cli import current_home, PyHocaCLI, runtime_error
# version information
PROG_NAME = os.path.basename(sys.argv[0])
@@ -136,8 +136,8 @@ def version():
def parseargs():
- global DEBUG
global logger
+ global liblogger
p = argparse.ArgumentParser(description='X2go command line client implemented in Python.',\
epilog="""
@@ -296,6 +296,7 @@ if __name__ == '__main__':
thisPyHocaCLI = PyHocaCLI(args, logger=logger, liblogger=liblogger)
thisPyHocaCLI.authenticate()
thisPyHocaCLI.MainLoop()
+
sys.exit(0)
except (KeyboardInterrupt, SystemExit), e:
diff --git a/pyhoca/cli/frontend.py b/pyhoca/cli/frontend.py
index 15a85d74..6706c32e 100644
--- a/pyhoca/cli/frontend.py
+++ b/pyhoca/cli/frontend.py
@@ -44,12 +44,22 @@ ssh_config_filename = os.path.join(current_home, '.ssh', 'config')
if not os.path.isfile(ssh_config_filename):
self._touch_file(ssh_config_filename)
-def _touch_file(self, filename):
+def _touch_file(filename):
if not os.path.isfile(filename):
f = open(filename, 'w')
f.close()
+# sometimes we have to fail...
+def runtime_error(m, parser=None, exitcode=-1):
+ """\
+ STILL UNDOCUMENTED
+ """
+ if parser is not None:
+ parser.print_usage()
+ sys.stderr.write ("%s: error: %s\n" % (os.path.basename(sys.argv[0]), m))
+ sys.exit(exitcode)
+
class PyHocaCLI(x2go.X2goClient):
"""\
@@ -57,13 +67,9 @@ class PyHocaCLI(x2go.X2goClient):
"""
x2go_session_hash = None
- # sometimes we have to fail...
- def runtime_error(self, m, exitcode=-1):
- """\
- STILL UNDOCUMENTED
- """
- sys.stderr.write ("%s: error: %s\n" % (sys.argv[0], m))
- sys.exit(exitcode)
+
+ def _runtime_error(self, m, exitcode=-1):
+ runtime_error(m, exitcode=exitcode)
def list_sessions(self, s_hash):
@@ -103,7 +109,7 @@ class PyHocaCLI(x2go.X2goClient):
"""
# clean all sessions from X2go server
self.logger('cleaning up all running sessions from X2go server: %s' % self.args.server, x2go.loglevel_NOTICE, )
- X2goClient.clean_sessions(self, s_hash)
+ x2go.X2goClient.clean_sessions(self, s_hash)
def new_session(self, s_hash):
@@ -113,7 +119,7 @@ class PyHocaCLI(x2go.X2goClient):
# start a new session and run a command
self.logger('starting a new X2go session', x2go.loglevel_INFO, )
self.logger('Command for new session is: %s' % self.args.command, x2go.loglevel_DEBUG, )
- self.start_session(s_hash)
+ x2go.X2goClient.start_session(self, s_hash)
def resume_session(self, s_hash):
@@ -126,7 +132,7 @@ class PyHocaCLI(x2go.X2goClient):
if self.args.resume in available_sessions.keys():
x2go.X2goClient.resume_session(self, 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)
+ self._runtime_error('requested session not available on X2go server [%s]:%s.' % (self.args.server, self.args.remote_ssh_port), exitcode=20)
def suspend_session(self, s_hash):
@@ -139,7 +145,7 @@ class PyHocaCLI(x2go.X2goClient):
if self.args.suspend in available_sessions.keys():
x2go.X2goClient.suspend_session(self, s_hash, self.args.suspend)
else:
- self.runtime_error('requested session not available on X2go server [%s]:%s.' % (self.args.server, self.args.remote_ssh_port), exitcode=21)
+ self._runtime_error('requested session not available on X2go server [%s]:%s.' % (self.args.server, self.args.remote_ssh_port), exitcode=21)
def terminate_session(self, s_hash):
@@ -152,7 +158,7 @@ class PyHocaCLI(x2go.X2goClient):
if self.args.terminate in available_sessions.keys():
x2go.X2goClient.terminate_session(self, s_hash, self.args.terminate)
else:
- self.runtime_error('requested session not available on X2go server [%s]:%s.' % (self.args.server, self.args.remote_ssh_port), exitcode=22)
+ self._runtime_error('requested session not available on X2go server [%s]:%s.' % (self.args.server, self.args.remote_ssh_port), exitcode=22)
def __init__(self, args, logger=None, liblogger=None):
@@ -164,6 +170,7 @@ class PyHocaCLI(x2go.X2goClient):
logger = x2go.X2goLogger(tag='PyHocaCLI')
else:
self.logger = logger
+ self.logger.tag = 'PyHocaCLI'
# initialize the X2goClient context and start the connection to the X2go server
self.logger('preparing requested X2go session', x2go.loglevel_NOTICE, )
@@ -206,15 +213,40 @@ class PyHocaCLI(x2go.X2goClient):
except x2go.PasswordRequiredException:
self.args.password = getpass.getpass()
except x2go.BadHostKeyException:
- self.runtime_error('SSH host key verification for remote host [%s]:%s failed' % (self.args.server, self.args.remote_ssh_port), exitcode=-254)
+ self._runtime_error('SSH host key verification for remote host [%s]:%s failed' % (self.args.server, self.args.remote_ssh_port), exitcode=-254)
except x2go.SSHException, e:
- self.runtime_error(str(e), exitcode=253)
+ self._runtime_error(str(e), exitcode=253)
def MainLoop(self):
"""\
STILL UNDOCUMENTED
"""
+ if self.args.clean_sessions:
+ self.clean_sessions(self.x2go_session_hash)
+
+ # go through the possible X2go client modes
+ if self.args.list_sessions:
+ # print a beautified session list for the user
+ self.list_sessions(self.x2go_session_hash)
+ sys.exit(0)
+
+ if self.args.resume:
+ self.resume_session(self.x2go_session_hash)
+
+ elif self.args.suspend:
+ self.suspend_session(self.x2go_session_hash)
+
+ elif self.args.terminate:
+ self.terminate_session(self.x2go_session_hash)
+
+ 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):
+ sys.exit(0)
+
# give the session some time to come up...
# no CTRL-C is allowed during this phase...
i=0
--
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