/usr/share/pyshared/x2go/mimeboxactions.py is in python-x2go 0.1.1.8-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2011 by Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
#
# Python X2go is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Python X2go is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
"""\
For MIME box jobs there are currently three handling actions available:
L{X2goMIMEboxActionOPEN}, L{X2goMIMEboxActionOPENWITH} and L{X2goMIMEboxActionSAVEAS}.
"""
__NAME__ = 'x2gomimeboxactions-pylib'
# modules
import os
import sys
import shutil
import copy
import types
import threading
import time
from defaults import X2GOCLIENT_OS as _X2GOCLIENT_OS
if _X2GOCLIENT_OS in ("Windows"):
import subprocess
import win32api
else:
import gevent_subprocess as subprocess
# Python X2go modules
import log
import defaults
# we hide the default values from epydoc (that's why we transform them to _UNDERSCORE variables)
import utils
import x2go_exceptions
_MIMEBOX_ENV = os.environ.copy()
class X2goMIMEboxAction(object):
__name__ = 'NAME'
__description__ = 'DESCRIPTION'
def __init__(self, client_instance=None, logger=None, loglevel=log.loglevel_DEFAULT):
"""\
This is a meta class and has no functionality as such. It is used as parent
class by »real« X2go MIME box actions.
@param client_instance: the underlying L{X2goClient} instance
@type client_instance: C{instance}
@param logger: you can pass an L{X2goLogger} object to the
L{X2goMIMEboxAction} constructor
@type logger: C{instance}
@param loglevel: if no L{X2goLogger} object has been supplied a new one will be
constructed with the given loglevel
@type loglevel: C{int}
"""
if logger is None:
self.logger = log.X2goLogger(loglevel=loglevel)
else:
self.logger = copy.deepcopy(logger)
self.logger.tag = __NAME__
# these get set from within the X2goMIMEboxQueue class
self.profile_name = 'UNKNOWN'
self.session_name = 'UNKNOWN'
self.client_instance = client_instance
@property
def name():
"""\
Return the X2go MIME box action's name.
"""
return self.__name__
@property
def description():
"""\
Return the X2go MIME box action's description text.
"""
return self.__description__
def do_process(self, mimebox_file, mimebox_dir, ):
"""\
Perform the defined MIME box action (doing nothing in L{X2goMIMEboxAction} parent class).
@param mimebox_file: file name as placed in to the X2go MIME box directory
@type mimebox_file: C{str}
@param mimebox_dir: location of the X2go sessions's MIME box directory
@type mimebox_dir: C{str}
"""
pass
class X2goMIMEboxActionOPEN(X2goMIMEboxAction):
"""\
MIME box action that opens incoming files in the system's default application.
"""
__name__= 'OPEN'
__decription__= 'Open incoming file with local system\'s default application.'
def __init__(self, client_instance=None, logger=None, loglevel=log.loglevel_DEFAULT):
"""\
@param client_instance: the underlying L{X2goClient} instance
@type client_instance: C{instance}
@param logger: you can pass an L{X2goLogger} object to the
L{X2goMIMEboxActionOPEN} constructor
@type logger: C{instance}
@param loglevel: if no L{X2goLogger} object has been supplied a new one will be
constructed with the given loglevel
@type loglevel: C{int}
"""
self.client_instance = client_instance
X2goMIMEboxAction.__init__(self, logger=logger, loglevel=loglevel)
def do_process(self, mimebox_file, mimebox_dir, ):
"""\
Open an incoming MIME box file in the system's default application.
@param mimebox_file: file name as placed in to the MIME box directory
@type mimebox_file: C{str}
@param mimebox_dir: location of the X2go session's MIME box directory
@type mimebox_dir: C{str}
"""
if _X2GOCLIENT_OS == "Windows":
self.logger('opening incoming MIME box file with Python\'s os.startfile() command: %s' % mimebox_file, loglevel=log.loglevel_DEBUG)
try:
os.startfile(os.path.join(mimebox_dir, mimebox_file))
except WindowsError, win_err:
if self.client_instance:
self.client_instance.HOOK_mimeboxaction_error(mimebox_file,
profile_name=self.profile_name,
session_name=self.session_name,
err_msg=str(win_err)
)
else:
self.logger('Encountered WindowsError: %s' % str(win_err), loglevel=log.loglevel_ERROR)
time.sleep(20)
else:
cmd_line = [ 'xdg-open', os.path.join(mimebox_dir, mimebox_file), ]
self.logger('opening MIME box file with command: %s' % ' '.join(cmd_line), loglevel=log.loglevel_DEBUG)
p = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=_MIMEBOX_ENV)
time.sleep(20)
class X2goMIMEboxActionOPENWITH(X2goMIMEboxAction):
"""\
MIME box action that calls the system's ,,Open with...'' dialog on incoming files. Currently only
properly implementable on Windows platforms.
"""
__name__= 'OPENWITH'
__decription__= 'Evoke ,,Open with...\'\' dialog on incoming MIME box files.'
def __init__(self, client_instance=None, logger=None, loglevel=log.loglevel_DEFAULT):
"""\
@param client_instance: the underlying L{X2goClient} instance
@type client_instance: C{instance}
@param logger: you can pass an L{X2goLogger} object to the
L{X2goMIMEboxActionOPENWITH} constructor
@type logger: C{instance}
@param loglevel: if no L{X2goLogger} object has been supplied a new one will be
constructed with the given loglevel
@type loglevel: C{int}
"""
self.client_instance = client_instance
X2goMIMEboxAction.__init__(self, logger=logger, loglevel=loglevel)
def do_process(self, mimebox_file, mimebox_dir, ):
"""\
Open an incoming MIME box file in the system's default application.
@param mimebox_file: file name as placed in to the MIME box directory
@type mimebox_file: C{str}
@param mimebox_dir: location of the X2go session's MIME box directory
@type mimebox_dir: C{str}
"""
if _X2GOCLIENT_OS == "Windows":
self.logger('evoking Open-with dialog on incoming MIME box file: %s' % mimebox_file, loglevel=log.loglevel_DEBUG)
win32api.ShellExecute (
0,
"open",
"rundll32.exe",
"shell32.dll,OpenAs_RunDLL %s" % os.path.join(mimebox_dir, mimebox_file),
None,
0,
)
time.sleep(20)
else:
self.logger('the evocation of the Open-with dialog box is currently not available on Linux, falling back to MIME box action OPEN', loglevel=log.loglevel_WARN)
cmd_line = [ 'xdg-open', os.path.join(mimebox_dir, mimebox_file), ]
self.logger('opening MIME box file with command: %s' % ' '.join(cmd_line), loglevel=log.loglevel_DEBUG)
p = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=_MIMEBOX_ENV)
time.sleep(20)
class X2goMIMEboxActionSAVEAS(X2goMIMEboxAction):
"""\
MIME box action that allows saving incoming MIME box files to a local folder. What this
MIME box actually does is calling a hook method in the L{X2goClient} instance that
can be hi-jacked by one of your application's methods which then can handle the ,,Save as...''
request.
"""
__name__ = 'SAVEAS'
__decription__= 'Save incoming file as...'
def __init__(self, client_instance=None, logger=None, loglevel=log.loglevel_DEFAULT):
"""\
@param client_instance: an L{X2goClient} instance, within your customized L{X2goClient} make sure
you have a C{HOOK_open_mimebox_saveas_dialog(filename=<str>)} method defined that will actually
handle the incoming mimebox file.
@type client_instance: C{instance}
@param logger: you can pass an L{X2goLogger} object to the
L{X2goMIMEboxActionSAVEAS} constructor
@type logger: C{instance}
@param loglevel: if no L{X2goLogger} object has been supplied a new one will be
constructed with the given loglevel
@type loglevel: C{int}
"""
if client_instance is None:
raise x2go_exceptions.X2goMIMEboxActionException('the SAVEAS MIME box action needs to know the X2goClient instance (client=<instance>)')
X2goMIMEboxAction.__init__(self, client_instance=client_instance, logger=logger, loglevel=loglevel)
def do_process(self, mimebox_file, mimebox_dir):
"""\
Call an L{X2goClient} hook method (C{HOOK_open_mimebox_saveas_dialog}) that
can handle the MIME box's SAVEAS action.
@param mimebox_file: file name as placed in to the MIME box directory
@type mimebox_file: C{str}
@param mimebox_dir: location of the X2go session's MIME box directory
@type mimebox_dir: C{str}
@param mimebox_file: PDF file name as placed in to the X2go spool directory
"""
self.logger('Session %s (%s) is calling X2goClient class hook method <client_instance>.HOOK_open_mimebox_saveas_dialog(%s)' % (self.session_name, self.profile_name, mimebox_file), loglevel=log.loglevel_NOTICE)
self.client_instance.HOOK_open_mimebox_saveas_dialog(os.path.join(mimebox_dir, mimebox_file), profile_name=self.profile_name, session_name=self.session_name)
time.sleep(60)
|