gnumed-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnumed-devel] <bug>: Ginkgo-CADx in blocking mode on Windows XP,


From: Sebastian Hilbert
Subject: Re: [Gnumed-devel] <bug>: Ginkgo-CADx in blocking mode on Windows XP,
Date: Thu, 12 Jan 2012 14:35:10 +0100
User-agent: KMail/1.13.6 (Linux/2.6.38-13-generic-pae; KDE/4.6.5; i686; ; )

On Thursday, January 12, 2012 01:50:31 PM Karsten Hilbert wrote:
> On Thu, Jan 12, 2012 at 12:57:15PM +0100, Dr.Leonard Horatio McCoy wrote:
> > Report sent via GNUmed's handler for unexpected exceptions.
> > 
> > user comment  : Ginkgo-CADx in blocking mode on Windows XP, maybe open it
> > not blocking GNUmed ?
> 
> I don't know how to do that.
> 
> This is the current code:
> 
>       #----------------------------------------------
>       def __on_dicom_viewer(self, evt):
> 
>               found, cmd = gmShellAPI.detect_external_binary(binary = 
'ginkgocadx')
>               if found:
>                       gmShellAPI.run_command_in_shell(cmd, blocking=False)
>                       return
> 
>               if os.access('/Applications/OsiriX.app/Contents/MacOS/OsiriX', 
os.X_OK):
>                       
gmShellAPI.run_command_in_shell('/Applications/OsiriX.app/Contents/MacOS
> /OsiriX', blocking=False) return
> 
>               for viewer in ['aeskulap', 'amide', 'dicomscope', 'xmedcon']:
>                       found, cmd = gmShellAPI.detect_external_binary(binary = 
> viewer)
>                       if found:
>                               gmShellAPI.run_command_in_shell(cmd, 
> blocking=False)
>                               return
> 
>               gmDispatcher.send(signal = 'statustext', msg = _('No DICOM 
> viewer
> found.'), beep = True)
> 
> def run_command_in_shell(command=None, blocking=False,
> acceptable_return_codes=None): """Runs a command in a subshell via
> standard-C system().
> 
>       <command>
>               The shell command to run including command line options.
>       <blocking>
>               This will make the code *block* until the shell command exits.
>               It will likely only work on UNIX shells where "cmd &" makes 
> sense.
>       """
>       if acceptable_return_codes is None:
>               acceptable_return_codes = [0]
> 
>       _log.debug('shell command >>>%s<<<', command)
>       _log.debug('blocking: %s', blocking)
>       _log.debug('acceptable return codes: %s', str(acceptable_return_codes))
> 
>       # FIXME: command should be checked for shell exploits
>       command = command.strip()
> 
>       # what the following hack does is this: the user indicated
>       # whether she wants non-blocking external display of files
>       # - the real way to go about this is to have a non-blocking command
>       #   in the line in the mailcap file for the relevant mime types
>       # - as non-blocking may not be desirable when *not* displaying
>       #   files from within GNUmed the really right way would be to
>       #   add a "test" clause to the non-blocking mailcap entry which
>       #   yields true if and only if GNUmed is running
>       # - however, this is cumbersome at best and not supported in
>       #   some mailcap implementations
>       # - so we allow the user to attempt some control over the process
>       #   from within GNUmed by setting a configuration option
>       # - leaving it None means to use the mailcap default or whatever
>       #   was specified in the command itself
>       # - True means: tack " &" onto the shell command if necessary
>       # - False means: remove " &" from the shell command if its there
>       # - all this, of course, only works in shells which support
>       #   detaching jobs with " &" (so, most POSIX shells)
>       if blocking is True:
>               if command[-2:] == ' &':
>                       command = command[:-2]
>       elif blocking is False:
>               if command[-2:] != ' &':
>                       command += ' &'
> 
>       _log.info('running shell command >>>%s<<<', command)
>       # FIXME: use subprocess.Popen()
>       ret_val = os.system(command.encode(sys.getfilesystemencoding()))
>       _log.debug('os.system() returned: [%s]', ret_val)
> 
>       exited_normally = False
> 
>       if not hasattr(os, 'WIFEXITED'):
>               _log.error('platform does not support exit status 
> differentiation')
>               if ret_val in acceptable_return_codes:
>                       _log.info('os.system() return value contained in 
> acceptable 
return
> codes') _log.info('continuing and hoping for the best')
>                       return True
>               return exited_normally
> 
>       _log.debug('exited via exit(): %s', os.WIFEXITED(ret_val))
>       if os.WIFEXITED(ret_val):
>               _log.debug('exit code: [%s]', os.WEXITSTATUS(ret_val))
>               exited_normally = (os.WEXITSTATUS(ret_val) in 
acceptable_return_codes)
>               _log.debug('normal exit: %s', exited_normally)
>       _log.debug('dumped core: %s', os.WCOREDUMP(ret_val))
>       _log.debug('stopped by signal: %s', os.WIFSIGNALED(ret_val))
>       if os.WIFSIGNALED(ret_val):
>               try:
>                       _log.debug('STOP signal was: [%s]', 
> os.WSTOPSIG(ret_val))
>               except AttributeError:
>                       _log.debug('platform does not support os.WSTOPSIG()')
>               try:
>                       _log.debug('TERM signal was: [%s]', 
> os.WTERMSIG(ret_val))
>               except AttributeError:
>                       _log.debug('platform does not support os.WTERMSIG()')
> 
>       return exited_normally
> #==========================================================================
> =
> 
> OK, it seems Windows uses "start" to do such things.
> 
>       
> http://stackoverflow.com/questions/893203/bat-files-nonblocking-run-launch
> 
> Let's see what we can make of that.
> 
> Please test the attached file like so:
> 
>       python gmShellAPI.py test ginkgocadx.exe
> 
> and report what happens.
> 
C:\Dokumente und Einstellungen\basti>c:\Python26\python.exe C:
\Temp\gmShellAPI.p
y test "c:\Programme\MetaEmotion\GinkgoCADx\ginkgocadx.exe"
-------------------------------------
running: c:\Programme\MetaEmotion\GinkgoCADx\ginkgocadx.exe
DEBUG:gm.shell:shell command >>>c:
\Programme\MetaEmotion\GinkgoCADx\ginkgocadx.e
xe<<<
DEBUG:gm.shell:blocking: False
DEBUG:gm.shell:acceptable return codes: [0]
INFO:gm.shell:running shell command >>>start /B c:
\Programme\MetaEmotion\GinkgoC
ADx\ginkgocadx.exe<<<
DEBUG:gm.shell:os.system() returned: [0]
ERROR:gm.shell:platform does not support exit status differentiation
INFO:gm.shell:os.system() return value contained in acceptable return codes
INFO:gm.shell:continuing and hoping for the best
-------------------------------------
success


Regards,
Sebastian



reply via email to

[Prev in Thread] Current Thread [Next in Thread]