source: trunk/coopr/core/solver/ilmcmd.py @ 1605

Last change on this file since 1605 was 1605, checked in by wehart, 11 years ago

Removed reference to SubprocessMngr?.

File size: 1.9 KB
Line 
1#  _________________________________________________________________________
2#
3#  Coopr: A COmmon Optimization Python Repository
4#  Copyright (c) 2008 Sandia Corporation.
5#  This software is distributed under the BSD License.
6#  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
7#  the U.S. Government retains certain rights in this software.
8#  For more information, see the Coopr README.txt file.
9#  _________________________________________________________________________
10
11__all__ = ['ILMLicensedSystemCallSolver']
12
13import shellcmd
14import pyutilib
15import re
16import sys
17
18class ILMLicensedSystemCallSolver(shellcmd.SystemCallSolver):
19    """ A command line solver that launches executables licensed with ILM """
20
21    def __init__(self, **kwds):
22        """ Constructor """
23        shellcmd.SystemCallSolver.__init__(self, **kwds)
24
25    def available(self, exception_flag=True):
26        """ True if the solver is available """
27        if self._assert_available:
28            return True
29        if not shellcmd.SystemCallSolver.available(self, exception_flag):
30            return False
31        executable = pyutilib.registered_executable("ilmlist")
32        if not executable is None:
33            try:
34                [rc,log] = pyutilib.run_command(executable.get_path())
35            except pyutilib.WindowsError, err:
36                raise pyutilib.ApplicationError, "Could not execute the command: ilmtest\n\tError message: "+   str(err)
37            sys.stdout.flush()
38            for line in log.split("\n"):
39                tokens = re.split('[\t ]+',line.strip())
40                if len(tokens) == 3 and tokens[0] == 'available' and tokens[1] == 'tokens:':
41                    if tokens[2] == '0':
42                        return False
43                    break
44                elif len(tokens) == 6 and tokens[1] == 'server' and tokens[5] == 'DOWN.':
45                    return False
46        return True
47
48pyutilib.register_executable(name="ilmlist")
Note: See TracBrowser for help on using the repository browser.