tiramisu/autolib.py

54 lines
2.2 KiB
Python

# Copyright (C) 2012 Team tiramisu (see README for all contributors)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# The original `Config` design model is unproudly borrowed from
# the rough gus of pypy: pypy: http://codespeak.net/svn/pypy/dist/pypy/config/
# the whole pypy projet is under MIT licence
# ____________________________________________________________
"enables us to carry out a calculation and return an option's value"
# ____________________________________________________________
# automatic Option object
special_owners = ['auto', 'fill']
def special_owner_factory(name, owner, default=None,
callback=None, config=None):
# auto behavior: carries out a calculation
if owner == 'auto':
return auto_factory(name, callback, config)
# fill behavior: carries out a calculation only if a default value isn't set
if owner == 'fill':
if default == None:
return auto_factory(name, callback, config)
else:
return default
g = globals()
def auto_factory(name, callback, config):
try:
#return getattr(autolib, callback)(name, config)
return g[callback](name, config)
except AttributeError:
raise SpecialOwnersError("callback: {0} not found for "
"option: {1}".format(callback, name))
# ____________________________________________________________
# FIXME: import eosfunc here
def identical(name, config, *args):
return "identical" + name