[X2Go-Commits] python-x2go.git - release/0.4.0.x (branch) updated: 0.1.1.4-32-gae89c0f
X2Go dev team
git-admin at x2go.org
Tue Jan 7 16:17:25 CET 2014
The branch, release/0.4.0.x has been updated
via ae89c0fd7e4cb18b42c25503627048c1ee5d149c (commit)
from 019e478b242d2879de567cbcf35d04b0b7a88799 (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:
debian/changelog | 2 +-
x2go/backends/terminal/_stdout.py | 84 +++++++++++++++++++++++-------
x2go/client.py | 102 +++++++++++++++++++++++++++++++++++--
x2go/session.py | 83 +++++++++++++++++++++++++++---
4 files changed, 242 insertions(+), 29 deletions(-)
The diff of changes is:
diff --git a/debian/changelog b/debian/changelog
index c5c9f26..8350ba2 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -7,7 +7,7 @@ python-x2go (0.1.2.0-0~x2go1) UNRELEASED; urgency=low
python-x2go (0.1.1.7-0-x2go1) UNRELEASED; urgency=low
* New upstream version (0.1.1.6), bugfix release for 0.1.1.x series:
- - continue development...
+ - Add support for x2goumount-session calls.
-- Mike Gabriel <mike.gabriel at das-netzwerkteam.de> Wed, 14 Sep 2011 21:35:54 +0200
diff --git a/x2go/backends/terminal/_stdout.py b/x2go/backends/terminal/_stdout.py
index 8f00822..17a152e 100644
--- a/x2go/backends/terminal/_stdout.py
+++ b/x2go/backends/terminal/_stdout.py
@@ -499,7 +499,7 @@ class X2goTerminalSessionSTDOUT(object):
spool_dir = os.path.join(self.session_info.local_container, 'spool')
if not os.path.exists(spool_dir):
os.mkdir(spool_dir)
- self.share_local_folder(folder_name=spool_dir, folder_type='spool')
+ self.share_local_folder(local_path=spool_dir, folder_type='spool')
self.print_queue = printqueue.X2goPrintQueue(profile_name=self.profile_name,
session_name=self.session_info.name,
spool_dir=spool_dir,
@@ -542,7 +542,7 @@ class X2goTerminalSessionSTDOUT(object):
mimebox_dir = os.path.join(self.session_info.local_container, 'mimebox')
if not os.path.exists(mimebox_dir):
os.mkdir(mimebox_dir)
- self.share_local_folder(folder_name=mimebox_dir, folder_type='mimebox')
+ self.share_local_folder(local_path=mimebox_dir, folder_type='mimebox')
self.mimebox_queue = mimebox.X2goMIMEboxQueue(profile_name=self.profile_name,
session_name=self.session_info.name,
mimebox_dir=mimebox_dir,
@@ -576,13 +576,13 @@ class X2goTerminalSessionSTDOUT(object):
"""
return '%s/%s' % (self.session_info.remote_container, 'mimebox')
- def share_local_folder(self, folder_name=None, folder_type='disk'):
+ def share_local_folder(self, local_path=None, folder_type='disk'):
"""\
Share a local folder with the X2go session.
- @param folder_name: the full path to an existing folder on the local
+ @param local_path: the full path to an existing folder on the local
file system
- @type folder_name: str
+ @type local_path: str
@param folder_type: one of 'disk' (a folder on your local hard drive), 'rm' (removeable device),
'cdrom' (CD/DVD Rom) or 'spool' (for X2go print spooling)
@type folder_type: str
@@ -594,20 +594,20 @@ class X2goTerminalSessionSTDOUT(object):
if self.session_info.username not in self.control_session._x2go_remote_group('fuse'):
raise x2go_exceptions.X2goUserException('remote user %s is not member of X2go server group fuse' % self.session_info.username)
- if folder_name is None:
+ if local_path is None:
self.logger('no folder name given...', log.loglevel_WARN)
return False
- if type(folder_name) not in (types.StringType, types.UnicodeType):
+ if type(local_path) not in (types.StringType, types.UnicodeType):
self.logger('folder name needs to be of type StringType...', log.loglevel_WARN)
return False
- if not os.path.exists(folder_name):
- self.logger('local folder does not exist: %s' % folder_name, log.loglevel_WARN)
+ if not os.path.exists(local_path):
+ self.logger('local folder does not exist: %s' % local_path, log.loglevel_WARN)
return False
- folder_name = os.path.normpath(folder_name)
- self.logger('sharing local folder: %s' % folder_name, log.loglevel_INFO)
+ local_path = os.path.normpath(local_path)
+ self.logger('sharing local folder: %s' % local_path, log.loglevel_INFO)
_auth_rsakey = self.control_session._x2go_session_auth_rsakey
_host_rsakey = defaults.RSAHostKey
@@ -628,9 +628,9 @@ class X2goTerminalSessionSTDOUT(object):
_server_encoding = self.params.server_encoding
if _X2GOCLIENT_OS == 'Windows':
- folder_name = folder_name.replace('\\', '/')
- folder_name = folder_name.replace(':', '')
- folder_name = '/windrive/%s' % folder_name
+ local_path = local_path.replace('\\', '/')
+ local_path = local_path.replace(':', '')
+ local_path = '/windrive/%s' % local_path
_convert_encoding = True
_client_encoding = 'WINDOWS-1252'
@@ -647,7 +647,7 @@ class X2goTerminalSessionSTDOUT(object):
str(self.session_info.name),
'"%s"' % _CURRENT_LOCAL_USER,
_x2go_key_fname,
- '%s__REVERSESSH_PORT__%s; ' % (folder_name, self.session_info.sshfs_port),
+ '%s__REVERSESSH_PORT__%s; ' % (local_path, self.session_info.sshfs_port),
'rm -f %s %s.ident' % (_x2go_key_fname, _x2go_key_fname),
]
@@ -659,7 +659,7 @@ class X2goTerminalSessionSTDOUT(object):
str(self.session_info.name),
'"%s"' % _CURRENT_LOCAL_USER,
_x2go_key_fname,
- '%s__PRINT_SPOOL___REVERSESSH_PORT__%s; ' % (folder_name, self.session_info.sshfs_port),
+ '%s__PRINT_SPOOL___REVERSESSH_PORT__%s; ' % (local_path, self.session_info.sshfs_port),
'rm -f %s %s.ident' % (_x2go_key_fname, _x2go_key_fname),
]
@@ -671,12 +671,60 @@ class X2goTerminalSessionSTDOUT(object):
str(self.session_info.name),
'"%s"' % _CURRENT_LOCAL_USER,
_x2go_key_fname,
- '%s__MIMEBOX_SPOOL___REVERSESSH_PORT__%s; ' % (folder_name, self.session_info.sshfs_port),
+ '%s__MIMEBOX_SPOOL___REVERSESSH_PORT__%s; ' % (local_path, self.session_info.sshfs_port),
'rm -f %s %s.ident' % (_x2go_key_fname, _x2go_key_fname),
]
(stdin, stdout, stderr) = self.control_session._x2go_exec_command(cmd_line)
- self.logger('x2gomountdirs output is : %s' % stdout.read().split('\n'), log.loglevel_NOTICE)
+ _stdout = stdout.read().split('\n')
+ self.logger('x2gomountdirs output is : %s' % _stdout, log.loglevel_NOTICE)
+ if _stdout[5].endswith('ok'):
+ print True
+ return True
+ return False
+
+ def unshare_all_local_folders(self):
+ """\
+ Unshare all local folders mount in the X2go session.
+
+ @return: returns C{True} if all local folders could be successfully unmounted from the X2go server session
+ @rtype: bool
+
+ """
+ self.logger('unsharing all local folders from session %s' % self.session_info, log.loglevel_INFO)
+
+ cmd_line = [ 'export HOSTNAME &&',
+ 'x2goumount-session',
+ self.session_info.name,
+ ]
+
+ (stdin, stdout, stderr) = self.control_session._x2go_exec_command(cmd_line)
+ if not stderr.read():
+ self.logger('x2goumount-session (all mounts) for session %s has been successful' % self.session_info, log.loglevel_NOTICE)
+ else:
+ self.logger('x2goumount-session (all mounts) for session %s failed' % self.session_info, log.loglevel_ERROR)
+
+ def unshare_local_folder(self, local_path):
+ """\
+ Unshare local folder given as <local_path> from X2go session.
+
+ @return: returns C{True} if the local folder <local_path> could be successfully unmounted from the X2go server session
+ @rtype: bool
+
+ """
+ self.logger('unsharing local folder from session %s' % self.session_info, log.loglevel_INFO)
+
+ cmd_line = [ 'export HOSTNAME &&',
+ 'x2goumount-session',
+ self.session_info.name,
+ local_path,
+ ]
+
+ (stdin, stdout, stderr) = self.control_session._x2go_exec_command(cmd_line)
+ if not stderr.read():
+ self.logger('x2goumount-session (%s) for session %s has been successful' % (local_path, self.session_info, ), log.loglevel_NOTICE)
+ else:
+ self.logger('x2goumount-session (%s) for session %s failed' % (local_path, self.session_info, ), log.loglevel_ERROR)
def color_depth(self):
"""\
diff --git a/x2go/client.py b/x2go/client.py
index e589f5a..1d58e82 100644
--- a/x2go/client.py
+++ b/x2go/client.py
@@ -1470,7 +1470,7 @@ class X2goClient(object):
return session_name not in [ s for s in self.server_running_sessions(session_uuid) + self.server_suspended_sessions(session_uuid) ]
__has_session_terminated = has_session_terminated
- def share_local_folder_with_session(self, session_uuid=None, folder_name=_LOCAL_HOME, profile_name=None):
+ def share_local_folder_with_session(self, session_uuid=None, local_path=None, profile_name=None, folder_name=None):
"""\
Share a local folder with the X2go session registered as C{session_uuid}.
@@ -1480,8 +1480,10 @@ class X2goClient(object):
@param session_uuid: the X2go session's UUID registry hash
@type session_uuid: C{str}
- @param folder_name: the full path to an existing folder on the local (client-side)
+ @param local_path: the full path to an existing folder on the local (client-side)
file system
+ @type local_path: C{str}
+ @param folder_name: synonymous to C{local_path}
@type folder_name: C{str}
@param profile_name: alternatively, the profile name can be used to share local folders
@type profile_name: C{str}
@@ -1490,17 +1492,111 @@ class X2goClient(object):
@rtype: C{bool}
"""
+ # compat for Python-X2go (<=0.1.1.6)
+ if folder_name: local_path = folder_name
+
if session_uuid is None and profile_name:
_associated = self._X2goClient__client_associated_sessions_of_profile_name(profile_name, return_objects=False)
if len(_associated) > 0:
session_uuid = _associated[0]
if session_uuid:
- return self.session_registry(session_uuid).share_local_folder(folder_name=folder_name)
+ return self.session_registry(session_uuid).share_local_folder(local_path=local_path)
else:
self.logger('Cannot find a terminal session for profile ,,%s\'\' to share a local folder with' % profile_name, loglevel=log.loglevel_WARN)
return False
__share_local_folder_with_session = share_local_folder_with_session
+ def unshare_all_local_folders(self, session_uuid=None, profile_name=None):
+ """\
+ Unshare all local folders mounted in X2go session registered as
+ C{session_uuid}.
+
+ When calling this method all client-side mounted folders on the X2go
+ server (via sshfs) for session with ID <session_uuid> will get
+ unmounted.
+
+ @param session_uuid: the X2go session's UUID registry hash
+ @type session_uuid: C{str}
+ @param profile_name: alternatively, the profile name can be used to unshare
+ mounted folders
+ @type profile_name: C{str}
+
+ @return: returns C{True} if all local folders could be successfully unmounted
+ @rtype: C{bool}
+
+ """
+ if session_uuid is None and profile_name:
+ _associated = self._X2goClient__client_associated_sessions_of_profile_name(profile_name, return_objects=False)
+ if len(_associated) > 0:
+ session_uuid = _associated[0]
+ if session_uuid:
+ return self.session_registry(session_uuid).unshare_all_local_folders()
+ else:
+ self.logger('Cannot find a terminal session for profile ,,%s\'\' from which to unmount local folders' % profile_name, loglevel=log.loglevel_WARN)
+ return False
+ unshare_all_local_folders_from_session = unshare_all_local_folders
+ unshare_all_local_folders_from_profile = unshare_all_local_folders
+ __unshare_all_local_folders_from_session = unshare_all_local_folders
+ __unshare_all_local_folders_from_profile = unshare_all_local_folders
+
+ def unshare_local_folder(self, session_uuid=None, profile_name=None, local_path=None):
+ """\
+ Unshare local folder that is mounted in the X2go session registered as
+ C{session_uuid}.
+
+ When calling this method the given client-side mounted folder on the X2go
+ server (via sshfs) for session with ID <session_uuid> will get
+ unmounted.
+
+ @param session_uuid: the X2go session's UUID registry hash
+ @type session_uuid: C{str}
+ @param profile_name: alternatively, the profile name can be used to unshare
+ mounted folders
+ @type profile_name: C{str}
+ @param local_path: the full path of a local folder that is mounted within X2go
+ session with session ID <session_uuid> (or recognized via profile name) and that
+ shall be unmounted from that session.
+ @type local_path: C{str}
+
+ @return: returns C{True} if all local folders could be successfully unmounted
+ @rtype: C{bool}
+
+ """
+ if session_uuid is None and profile_name:
+ _associated = self._X2goClient__client_associated_sessions_of_profile_name(profile_name, return_objects=False)
+ if len(_associated) > 0:
+ session_uuid = _associated[0]
+ if session_uuid:
+ return self.session_registry(session_uuid).unshare_local_folder(local_path=local_path)
+ else:
+ self.logger('Cannot find a terminal session for profile ,,%s\'\' from which to unmount local folders' % profile_name, loglevel=log.loglevel_WARN)
+ return False
+ unshare_local_folder_from_session = unshare_local_folder
+ unshare_local_folder_from_profile = unshare_local_folder
+ __unshare_local_folder_from_session = unshare_local_folder
+ __unshare_local_folder_from_profile = unshare_local_folder
+
+ def get_shared_folders(self, session_uuid=None, profile_name=None):
+ """\
+ Get a list of local folders mounted within X2go session with session hash <session_uuid>
+ from this client.
+
+ @return: returns a C{list} of those local folder names that are mounted within X2go session <session_uuid>.
+ @rtype: C{list}
+
+ """
+ if session_uuid is None and profile_name:
+ _associated = self._X2goClient__client_associated_sessions_of_profile_name(profile_name, return_objects=False)
+ if len(_associated) > 0:
+ session_uuid = _associated[0]
+ print session_uuid
+ if session_uuid:
+ return self.session_registry(session_uuid).get_shared_folders()
+ session_get_shared_folders = get_shared_folders
+ profile_get_shared_folders = get_shared_folders
+ __session_get_shared_folders = get_shared_folders
+ __profile_get_shared_folders = get_shared_folders
+
###
### Provide access to the X2goClient's session registry
###
diff --git a/x2go/session.py b/x2go/session.py
index 53b5dd5..a50ef2d 100644
--- a/x2go/session.py
+++ b/x2go/session.py
@@ -236,6 +236,7 @@ class X2goSession(object):
self.terminal_params = {}
self.sshproxy_params = {}
self.update_params(params)
+ self.shared_folders = []
self.session_environment = {}
@@ -1057,14 +1058,13 @@ class X2goSession(object):
if self._SUPPORTED_MIMEBOX and self.allow_mimebox:
self.terminal_session and not self.faulty and self.terminal_session.start_mimebox(mimebox_extensions=self.mimebox_extensions, mimebox_action=self.mimebox_action)
- self.session_environment.update({'X2GO_MIMEBOX': self.terminal_session.get_mimebox_spooldir(), })
+ self.terminal_session and self.session_environment.update({'X2GO_MIMEBOX': self.terminal_session.get_mimebox_spooldir(), })
- if self._SUPPORTED_FOLDERSHARING and self.share_local_folders:
+ if self._SUPPORTED_FOLDERSHARING and self.share_local_folders and self.terminal_session and not self.faulty:
if _control.get_transport().reverse_tunnels[self.terminal_session.get_session_name()]['sshfs'][1] is not None:
for _folder in self.share_local_folders:
self.share_local_folder(_folder)
-
self.virgin = False
self.suspended = False
self.running = True
@@ -1179,6 +1179,10 @@ class X2goSession(object):
"""
if self.is_alive():
if self.has_terminal_session():
+
+ # unshare mounted folders
+ self.unshare_all_local_folders()
+
if self.terminal_session.suspend():
self.running = False
@@ -1217,8 +1221,11 @@ class X2goSession(object):
"""
if self.is_alive():
if self.has_terminal_session():
- if self.terminal_session.terminate():
+ # unmount shared folders
+ self.unshare_all_local_folders()
+
+ if self.terminal_session.terminate():
self.running = False
self.suspended = False
self.terminated = True
@@ -1381,12 +1388,14 @@ class X2goSession(object):
return self.terminated
__has_terminated = has_terminated
- def share_local_folder(self, folder_name):
+ def share_local_folder(self, local_path=None, folder_name=None):
"""\
Share a local folder with this registered X2go session.
- @param folder_name: the full path to an existing folder on the local
+ @param local_path: the full path to an existing folder on the local
file system
+ @type local_path: C{str}
+ @param folder_name: synonymous to C{local_path}
@type folder_name: C{str}
@return: returns C{True} if the local folder has been successfully mounted within
@@ -1394,15 +1403,75 @@ class X2goSession(object):
@rtype: C{bool}
"""
+ # compat for Python-X2go (<=0.1.1.6)
+ if folder_name: local_path=folder_name
+
if self.has_terminal_session():
if self.allow_share_local_folders:
- return self.terminal_session.share_local_folder(folder_name=folder_name)
+ if self.terminal_session.share_local_folder(local_path=local_path):
+ self.shared_folders.append(local_path)
+ return True
+ return False
else:
self.logger('local folder sharing is disabled for this session profile', loglevel=log.loglevel_WARN)
else:
raise X2goSessionException('this X2goSession object does not have any associated terminal')
__share_local_folder = share_local_folder
+ def unshare_all_local_folders(self):
+ """\
+ Unshare all local folders mounted within this X2go session.
+
+ @return: returns C{True} if all local folders could be successfully unmounted
+ inside this X2go session
+ @rtype: C{bool}
+
+ """
+ if self.has_terminal_session():
+ if self.allow_share_local_folders:
+ self.shared_folders = []
+ return self.terminal_session.unshare_all_local_folders()
+ else:
+ self.logger('local folder sharing is disabled for this session profile', loglevel=log.loglevel_WARN)
+ else:
+ raise X2goSessionException('this X2goSession object does not have any associated terminal')
+ return False
+ __unshare_all_local_folders = unshare_all_local_folders
+
+ def unshare_local_folder(self, local_path=None):
+ """\
+ Unshare a local folder that is mounted within this X2go session.
+
+ @param local_path: the full path to an existing folder on the local
+ file system that is mounted in this X2go session and shall be
+ unmounted
+ @type local_path: C{str}
+ @return: returns C{True} if all local folders could be successfully unmounted
+ inside this X2go session
+ @rtype: C{bool}
+
+ """
+ if self.has_terminal_session():
+ if self.allow_share_local_folders and local_path in self.shared_folders:
+ self.shared_folders.remove(local_path)
+ return self.terminal_session.unshare_local_folder(local_path=local_path)
+ else:
+ self.logger('local folder sharing is disabled for this session profile', loglevel=log.loglevel_WARN)
+ else:
+ raise X2goSessionException('this X2goSession object does not have any associated terminal')
+ __unshare_local_folder = unshare_local_folder
+
+ def get_shared_folders(self):
+ """\
+ Get a list of local folders mounted within this X2go session from this client.
+
+ @return: returns a C{list} of those folder names that are mounted with this X2go session.
+ @rtype: C{list}
+
+ """
+ return self.shared_folders
+ __get_shared_folders = get_shared_folders
+
def is_locked(self):
"""\
Query session if it is locked by some command being processed.
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