#  _________________________________________________________________________
#
#  Coopr: A COmmon Optimization Python Repository
#  Copyright (c) 2008 Sandia Corporation.
#  This software is distributed under the BSD License.
#  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
#  the U.S. Government retains certain rights in this software.
#  For more information, see the Coopr README.txt file.
#  _________________________________________________________________________

from pyutilib.enum import Enum
import pyutilib.plugin.core
from plugin import *

Debug = Enum('none', 'reader', 'preprocess', 'instance', 'all', 'verbose', 'generate', 'normal', 'errors')

_debug = []

def debug(val=Debug.all):
  if val not in Debug:
     raise ValueError, "Bad debugging type: "+str(val)
  if _debug is True:
     return True
  if Debug.all in _debug:
     return True
  if type(val) is str:
     tmp = getattr(Debug,val)
  else:
     tmp=val
  return tmp is not Debug.none and tmp in _debug

def set_debugging(*args):
    global _debug
    _debug = []
    if args == ():
       args=["all"]
    for val in args:
      if type(val) is str:
         if val not in Debug:
            raise ValueError, "Unknown debugging tag: "+val
         _debug.append( getattr(Debug,val) )
      else:
         _debug.append(val)


def predefined_sets():
    import set_types
    ans = []
    for item in set_types._virtual_sets:
        ans.append( (item.name,item.doc) )
    return ans


def model_components():
    ep = pyutilib.plugin.core.ExtensionPoint(IModelComponent)
    ans = []
    for item in ep:
        ans.append( (item.name,item.doc) )
    return ans
