[X2go-Commits] python-x2go.git - release/0.1.1.x (branch) updated: 0.1.1.7-9-gda6002f

X2go dev team git-admin at x2go.org
Mon Sep 26 20:32:55 CEST 2011


The branch, release/0.1.1.x has been updated
       via  da6002f82aca5764b23e1bd0cf6b55fc50fe0be7 (commit)
       via  c4c01249d7b06320e284f33b53d00038c34a20fa (commit)
       via  ac72309392b1eb54273b47dc83f6af6828dee146 (commit)
       via  38414aa7189e0043d65911aebcd7ba4303ecfadb (commit)
      from  cdeb38f6ada3cdc38b5095e76993b6773b2a340b (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 -----------------------------------------------------------------
commit da6002f82aca5764b23e1bd0cf6b55fc50fe0be7
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Mon Sep 26 20:27:05 2011 +0200

    Fix missing import of socket module in backends/control/_stdout.py.

commit c4c01249d7b06320e284f33b53d00038c34a20fa
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Sun Sep 25 23:40:02 2011 +0200

    Improve local session cache dir removal.

commit ac72309392b1eb54273b47dc83f6af6828dee146
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Sun Sep 25 23:38:56 2011 +0200

    provide better __repr__ output for debugging session infos

commit 38414aa7189e0043d65911aebcd7ba4303ecfadb
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Sun Sep 25 21:35:06 2011 +0200

    Remove local session cache folders after sessions have terminated.

-----------------------------------------------------------------------

Summary of changes:
 debian/changelog                  |    2 ++
 x2go/backends/control/_stdout.py  |   10 ++++++----
 x2go/backends/info/_stdout.py     |   11 ++++++++++-
 x2go/backends/terminal/_stdout.py |   37 ++++++++++++++++++++++++++++++++++++-
 x2go/client.py                    |    4 +++-
 x2go/session.py                   |   14 +++++++++++---
 6 files changed, 68 insertions(+), 10 deletions(-)

The diff of changes is:
diff --git a/debian/changelog b/debian/changelog
index 62718c6..3cea1fb 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,8 @@ python-x2go (0.1.1.8-0-x2go1) UNRELEASED; urgency=low
   * New upstream version (0.1.1.8), bugfix release for 0.1.1.x series:
     - Bugfix for: Test for existence of remote home directory on connect.
     - Unshare local folders during session cleanup.
+    - Remove local session cache folders after sessions have terminated.
+    - Fix missing import of socket module in backends/control/_stdout.py.
 
  -- Mike Gabriel <mike.gabriel at das-netzwerkteam.de>  Sun, 25 Sep 2011 02:08:11 +0200
 
diff --git a/x2go/backends/control/_stdout.py b/x2go/backends/control/_stdout.py
index b5313a8..25c2068 100644
--- a/x2go/backends/control/_stdout.py
+++ b/x2go/backends/control/_stdout.py
@@ -37,6 +37,8 @@ import binascii
 import string
 import random
 
+from gevent import socket
+
 # Python X2go modules
 import x2go.sshproxy as sshproxy
 import x2go.log as log
@@ -758,7 +760,7 @@ class X2goControlSessionSTDOUT(paramiko.SSHClient):
 
             return _listsessions
 
-    def clean_sessions(self):
+    def clean_sessions(self, destroy_terminals=True):
         """\
         Find X2go terminals that have previously been started by the
         connected user on the remote X2go server and terminate them.
@@ -766,7 +768,7 @@ class X2goControlSessionSTDOUT(paramiko.SSHClient):
         """
         session_list = self.list_sessions()
         for session_name in session_list.keys():
-            self.terminate(session_name=session_name)
+            self.terminate(session_name=session_name, destroy_terminals=destroy_terminals)
 
     def is_connected(self):
         """\
@@ -873,7 +875,7 @@ class X2goControlSessionSTDOUT(paramiko.SSHClient):
 
         return _ret
 
-    def terminate(self, session_name):
+    def terminate(self, session_name, destroy_terminals=True):
         """\
         Terminate either this or another available X2go session on the connected
         server.
@@ -898,7 +900,7 @@ class X2goControlSessionSTDOUT(paramiko.SSHClient):
             dummy_stdout = stdout.read()
             dummy_stderr = stderr.read()
             if self.associated_terminals.has_key(session_name):
-                if self.associated_terminals[session_name] is not None:
+                if self.associated_terminals[session_name] is not None and destroy_terminals:
                     self.associated_terminals[session_name].__del__()
                 try: del self.associated_terminals[session_name]
                 except KeyError: pass
diff --git a/x2go/backends/info/_stdout.py b/x2go/backends/info/_stdout.py
index 5cae736..c03d1b3 100644
--- a/x2go/backends/info/_stdout.py
+++ b/x2go/backends/info/_stdout.py
@@ -27,6 +27,11 @@ via server-side STDOUT.
 """
 __NAME__ = 'x2goserversessioninfo-pylib'
 
+
+# modules
+import types
+
+
 class X2goServerSessionInfoSTDOUT(object):
     """\
     L{X2goServerSessionInfo} is used to store all information
@@ -37,7 +42,11 @@ class X2goServerSessionInfoSTDOUT(object):
     def __str__(self):
         return self.name
     def __repr__(self):
-        return "<%s instance: %s>" % (self.__class__, self.name)
+        result = 'X2goServerSessionInfoSTDOUT('
+        for p in dir(self):
+            if '__' in p or not p in self.__dict__ or type(p) is types.InstanceType: continue
+            result += p + '=' + str(self.__dict__[p]) +','
+        return result.strip(',') + ')'
 
     def _parse_x2golistsessions_line(self, x2go_output):
         """\
diff --git a/x2go/backends/terminal/_stdout.py b/x2go/backends/terminal/_stdout.py
index 0a0f025..e0eb3f1 100644
--- a/x2go/backends/terminal/_stdout.py
+++ b/x2go/backends/terminal/_stdout.py
@@ -35,6 +35,7 @@ import threading
 import signal
 import cStringIO
 import copy
+import shutil
 
 # Python X2go modules
 import x2go.rforward as rforward
@@ -325,6 +326,8 @@ class X2goTerminalSessionSTDOUT(object):
         else:
             self.session_info = info_backend()
 
+        self._cleaned_up = False
+
     def __del__(self):
         self._x2go_tidy_up()
 
@@ -363,6 +366,16 @@ class X2goTerminalSessionSTDOUT(object):
             else:
                 raise OSError, e
 
+    def _rm_session_dirtree(self):
+
+        if self.session_info.name:
+            shutil.rmtree('%s/S-%s' % (self.params.rootdir, self.session_info), ignore_errors=True)
+
+    def _rm_desktop_dirtree(self):
+
+        if self.session_info.display:
+            shutil.rmtree('%s/S-%s' % (self.params.rootdir, self.session_info.display), ignore_errors=True)
+
     def get_session_name(self):
         """\
         STILL UNDOCUMENTED
@@ -1022,8 +1035,10 @@ class X2goTerminalSessionSTDOUT(object):
         @rtype: bool
 
         """
-        self.control_session.terminate(session_name=self.session_info.name)
+        self.control_session.terminate(session_name=self.session_info.name, destroy_terminals=False)
         self.release_proxy()
+        self.post_terminate_cleanup()
+        self.__del__()
 
         # TODO: check if session has really suspended
         _ret = True
@@ -1038,3 +1053,23 @@ class X2goTerminalSessionSTDOUT(object):
         if self.proxy is not None:
             self.proxy.__del__()
 
+    def post_terminate_cleanup(self):
+        """\
+        STILL UNDOCUMENTED
+
+        """
+        # this method might be called twice (directly and from update_status in the session
+        # registry instance. So we have to make sure, that this code will not fail
+        # if called twice.
+        if not self._cleaned_up and self.session_info.name:
+
+            # otherwise we wipe the session files locally
+            self.logger('cleaning up session %s after termination' % self.session_info, loglevel=log.loglevel_NOTICE)
+
+            # if we run in debug mode, we keep local session directories
+            if self.logger.get_loglevel() & log.loglevel_DEBUG != log.loglevel_DEBUG:
+
+                self._rm_session_dirtree()
+                self._rm_desktop_dirtree()
+
+            self._cleaned_up = True
diff --git a/x2go/client.py b/x2go/client.py
index 37ec3bd..8f3a4f9 100644
--- a/x2go/client.py
+++ b/x2go/client.py
@@ -319,6 +319,7 @@ class X2goClient(object):
                                                     refresh_interval=refresh_interval,
                                                     logger=self.logger
                                                    )
+        self.auto_update_sessionregistry = auto_update_sessionregistry
 
         if use_listsessions_cache:
             self.listsessions_cache = X2goListSessionsCache(self, logger=self.logger)
@@ -2010,8 +2011,9 @@ class X2goClient(object):
         @type session_uuid: C{str}
 
         """
+        _destroy_terminals = not ( self.auto_update_sessionregistry == True)
         session = self.session_registry(session_uuid)
-        session.clean_sessions()
+        session.clean_sessions(destroy_terminals=_destroy_terminals)
     __clean_sessions = clean_sessions
 
     def list_sessions(self, session_uuid=None, 
diff --git a/x2go/session.py b/x2go/session.py
index c623214..f700c03 100644
--- a/x2go/session.py
+++ b/x2go/session.py
@@ -853,13 +853,13 @@ class X2goSession(object):
         return self.connected
     __is_alive = is_alive
 
-    def clean_sessions(self):
+    def clean_sessions(self, destroy_terminals=True):
         """\
         Clean all running sessions for the authenticated user on the remote X2go server.
 
         """
         if self.is_alive():
-            self.control_session.clean_sessions()
+            self.control_session.clean_sessions(destroy_terminals=destroy_terminals)
         else:
             self._X2goSession__disconnect()
     __clean_sessions = clean_sessions
@@ -1514,9 +1514,17 @@ class X2goSession(object):
             self.terminal_session.release_proxy()
 
         # unmount shared folders
-        self.unshare_all_local_folders()
+        try:
+            self.unshare_all_local_folders()
+        except X2goSessionException:
+            pass
+
+        # remove client-side session cache
+        if self.terminated and self.has_terminal_session():
+            self.terminal_session.post_terminate_cleanup()
 
         # destroy terminal session
         if self.has_terminal_session():
             self.terminal_session.__del__()
+
         self.terminal_session = None


hooks/post-receive
-- 
python-x2go.git (Python X2go Client API)

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 "python-x2go.git" (Python X2go Client API).




More information about the x2go-commits mailing list