source: trunk/coopr/opt/base/results.py @ 1768

Last change on this file since 1768 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.1 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__ = [ 'IReaderRegistration', 'ReaderRegistration',
12            'IResultsReader', 'AbstractResultsReader',
13            'ReaderFactory' ]
14
15from pyutilib.plugin.core import *
16from pyutilib.plugin.config import *
17
18
19class IReaderRegistration(Interface):
20    """An interface for accessing"""
21
22    def create(self, name=None):
23        """Create a reader, optionally specifying the name"""
24
25    def type(self):
26        """The type of reader supported by this service"""
27
28
29def ReaderFactory(name=None, reader_name=None):
30    ep = ExtensionPoint(IReaderRegistration)
31    if name is None:
32        return map(lambda x:x.name, ep())
33    service = ep.service(name)
34    if service is None:
35        return None
36    return service.create(reader_name)
37
38
39class ReaderRegistration(Plugin):
40
41    implements(IReaderRegistration)
42
43    def __init__(self, type, cls):
44        self.name = type
45        self._type = type
46        self._cls = cls
47
48    def type(self):
49        return self._type
50
51    def create(self, name=None):
52        if name is None:
53            return self._cls()
54        return self._cls(name=name)
55
56
57class IResultsReader(Interface):
58    """Interface for classes that can read optimization results."""
59
60
61class AbstractResultsReader(ManagedPlugin):
62    """Base class that can read optimization results."""
63
64    implements(IResultsReader)
65
66    def __init__(self, results_format):
67        ManagedPlugin.__init__(self)
68        self.format=results_format
69
70    def __call__(self, filename, res=None): #pragma:nocover
71        raise TypeError, "Method __call__ undefined in reader for format "+str(self.format)
72
Note: See TracBrowser for help on using the repository browser.