source: trunk/coopr/opt/solver/ilmcmd.py @ 1772

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

Rework of Coopr to use the new PyUtilib? package decomposition.

NOTE: to use Coopr with this update, we need to work with a new version of coopr_install.

File size: 2.0 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.services
15import pyutilib.subprocess
16import pyutilib.common
17import re
18import sys
19
20class ILMLicensedSystemCallSolver(shellcmd.SystemCallSolver):
21    """ A command line solver that launches executables licensed with ILM """
22
23    def __init__(self, **kwds):
24        """ Constructor """
25        shellcmd.SystemCallSolver.__init__(self, **kwds)
26
27    def available(self, exception_flag=True):
28        """ True if the solver is available """
29        if self._assert_available:
30            return True
31        if not shellcmd.SystemCallSolver.available(self, exception_flag):
32            return False
33        executable = pyutilib.services.registered_executable("ilmlist")
34        if not executable is None:
35            try:
36                [rc,log] = pyutilib.subprocess.run(executable.get_path())
37            except pyutilib.common.WindowsError, err:
38                raise pyutilib.common.ApplicationError, "Could not execute the command: ilmtest\n\tError message: "+   str(err)
39            sys.stdout.flush()
40            for line in log.split("\n"):
41                tokens = re.split('[\t ]+',line.strip())
42                if len(tokens) == 3 and tokens[0] == 'available' and tokens[1] == 'tokens:':
43                    if tokens[2] == '0':
44                        return False
45                    break
46                elif len(tokens) == 6 and tokens[1] == 'server' and tokens[5] == 'DOWN.':
47                    return False
48        return True
49
50pyutilib.services.register_executable(name="ilmlist")
Note: See TracBrowser for help on using the repository browser.