reorder autolib

This commit is contained in:
gwen 2012-05-24 15:07:06 +02:00
parent 269e5d5b35
commit 7f4385bfeb
5 changed files with 64 additions and 29 deletions

View File

@ -17,7 +17,34 @@
# 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):

View File

@ -19,6 +19,7 @@
# 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
# ____________________________________________________________
from error import (HiddenOptionError, ConfigError, NotFoundError,
AmbigousOptionError, ConflictConfigError, NoMatchingOptionFound,
SpecialOwnersError, MandatoryError, MethodCallError,
@ -26,29 +27,7 @@ from error import (HiddenOptionError, ConfigError, NotFoundError,
from option import (OptionDescription, Option, SymLinkOption, group_types,
apply_requires, modes)
import autolib
# ____________________________________________________________
# 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
def auto_factory(name, callback, config):
try:
return getattr(autolib, callback)(name, config)
except AttributeError:
raise SpecialOwnersError("callback: {0} not found for "
"option: {1}".format(callback, name))
from autolib import special_owners, special_owner_factory
# ____________________________________________________________
class Config(object):
_cfgimpl_hidden = True

View File

@ -1,10 +1,19 @@
tiramisu tiramisu-module.html
tiramisu.__package__ tiramisu-module.html#__package__
tiramisu.autolib tiramisu.autolib-module.html
tiramisu.autolib.identical tiramisu.autolib-module.html#identical
tiramisu.autolib.g tiramisu.autolib-module.html#g
tiramisu.autolib.special_owners tiramisu.autolib-module.html#special_owners
tiramisu.autolib.__package__ tiramisu.autolib-module.html#__package__
tiramisu.autolib.special_owner_factory tiramisu.autolib-module.html#special_owner_factory
tiramisu.autolib.auto_factory tiramisu.autolib-module.html#auto_factory
tiramisu.config tiramisu.config-module.html
tiramisu.config.__package__ tiramisu.config-module.html#__package__
tiramisu.config.auto_factory tiramisu.config-module.html#auto_factory
tiramisu.config.special_owner_factory tiramisu.config-module.html#special_owner_factory
tiramisu.config.special_owner_factory tiramisu.autolib-module.html#special_owner_factory
tiramisu.config.make_dict tiramisu.config-module.html#make_dict
tiramisu.config.special_owners tiramisu.config-module.html#special_owners
tiramisu.config.apply_requires tiramisu.option-module.html#apply_requires
tiramisu.error tiramisu.error-module.html
tiramisu.error.__package__ tiramisu.error-module.html#__package__
tiramisu.option tiramisu.option-module.html
tiramisu.option.__package__ tiramisu.option-module.html#__package__
tiramisu.option.reverse_actions tiramisu.option-module.html#reverse_actions
@ -12,6 +21,10 @@ tiramisu.option.group_types tiramisu.option-module.html#group_types
tiramisu.option.modes tiramisu.option-module.html#modes
tiramisu.option.apply_requires tiramisu.option-module.html#apply_requires
tiramisu.option.available_actions tiramisu.option-module.html#available_actions
tiramisu.tool tiramisu.tool-module.html
tiramisu.tool.apply_requires tiramisu.option-module.html#apply_requires
tiramisu.tool.__package__ tiramisu.tool-module.html#__package__
tiramisu.tool.reverse_from_paths tiramisu.tool-module.html#reverse_from_paths
tiramisu.config.Config tiramisu.config.Config-class.html
tiramisu.config.Config.set tiramisu.config.Config-class.html#set
tiramisu.config.Config.unwrap_from_name tiramisu.config.Config-class.html#unwrap_from_name
@ -58,6 +71,18 @@ tiramisu.config.Config.add_warning tiramisu.config.Config-class.html#add_warning
tiramisu.config.Config.cfgimpl_enable tiramisu.config.Config-class.html#cfgimpl_enable
tiramisu.config.Config.cfgimpl_freeze tiramisu.config.Config-class.html#cfgimpl_freeze
tiramisu.config.Config.cfgimpl_read_only tiramisu.config.Config-class.html#cfgimpl_read_only
tiramisu.error.AmbigousOptionError tiramisu.error.AmbigousOptionError-class.html
tiramisu.error.ConfigError tiramisu.error.ConfigError-class.html
tiramisu.error.ConflictConfigError tiramisu.error.ConflictConfigError-class.html
tiramisu.error.DisabledOptionError tiramisu.error.DisabledOptionError-class.html
tiramisu.error.HiddenOptionError tiramisu.error.HiddenOptionError-class.html
tiramisu.error.MandatoryError tiramisu.error.MandatoryError-class.html
tiramisu.error.MethodCallError tiramisu.error.MethodCallError-class.html
tiramisu.error.ModeOptionError tiramisu.error.ModeOptionError-class.html
tiramisu.error.NoMatchingOptionFound tiramisu.error.NoMatchingOptionFound-class.html
tiramisu.error.NotFoundError tiramisu.error.NotFoundError-class.html
tiramisu.error.RequiresError tiramisu.error.RequiresError-class.html
tiramisu.error.SpecialOwnersError tiramisu.error.SpecialOwnersError-class.html
tiramisu.option.ArbitraryOption tiramisu.option.ArbitraryOption-class.html
tiramisu.option.HiddenBaseType.show tiramisu.option.HiddenBaseType-class.html#show
tiramisu.option.Option.getkey tiramisu.option.Option-class.html#getkey
@ -330,3 +355,5 @@ tiramisu.option.SymLinkOption tiramisu.option.SymLinkOption-class.html
tiramisu.option.SymLinkOption.setoption tiramisu.option.SymLinkOption-class.html#setoption
tiramisu.option.SymLinkOption.opt_type tiramisu.option.SymLinkOption-class.html#opt_type
tiramisu.option.SymLinkOption.__init__ tiramisu.option.SymLinkOption-class.html#__init__
tiramisu.tool.extend tiramisu.tool.extend-class.html
tiramisu.tool.extend.extend tiramisu.tool.extend-class.html#extend

View File

@ -1,3 +1,3 @@
epydoc --css grayscale -o ./build/pydoc ../config.py ../option.py
epydoc --css grayscale -o ./build/pydoc ../*.py #config.py ../option.py
#apirst2html.py --stylesheet=docutils.css --external-api=epydoc --external-api-root=epydoc:./api/ --external-api-file=epydoc:./api/api-objects.txt doc.txt > doc.htm

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"pretty small and local configuration management tool"
"option types and option description for the configuration management"
# Copyright (C) 2012 Team tiramisu (see README for all contributors)
#
# This program is free software; you can redistribute it and/or modify
@ -19,6 +19,8 @@
# 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
# ____________________________________________________________
from autolib import special_owners
from error import (ConfigError, ConflictConfigError, NotFoundError,
RequiresError)
available_actions = ['hide', 'show', 'enable', 'disable']
@ -95,7 +97,7 @@ class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
name = self._name
if self._frozen:
raise TypeError("trying to change a frozen option's owner: %s" % name)
if who in ['auto', 'fill']: # XXX special_owners to be imported from config
if who in special_owners:
if self.callback == None:
raise SpecialOwnersError("no callback specified for"
"option {0}".format(name))