basetypes in another module
This commit is contained in:
parent
7f4385bfeb
commit
7e4a1358fe
3 changed files with 55 additions and 32 deletions
53
basetype.py
Normal file
53
basetype.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"base 'interface' types for option types"
|
||||
# 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
|
||||
# ____________________________________________________________
|
||||
# Option and OptionDescription modes
|
||||
modes = ['normal', 'expert']
|
||||
|
||||
class HiddenBaseType(object):
|
||||
hidden = False
|
||||
def hide(self):
|
||||
self.hidden = True
|
||||
def show(self):
|
||||
self.hidden = False
|
||||
def _is_hidden(self):
|
||||
# dangerous method: how an Option can determine its status by itself ?
|
||||
return self.hidden
|
||||
|
||||
class DisabledBaseType(object):
|
||||
disabled = False
|
||||
def disable(self):
|
||||
self.disabled = True
|
||||
def enable(self):
|
||||
self.disabled = False
|
||||
def _is_disabled(self):
|
||||
return self.disabled
|
||||
|
||||
class ModeBaseType(object):
|
||||
mode = 'normal'
|
||||
def get_mode(self):
|
||||
return self.mode
|
||||
def set_mode(self, mode):
|
||||
if mode not in modes:
|
||||
raise TypeError("Unknown mode: {0}".format(mode))
|
||||
self.mode = mode
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.9: http://docutils.sourceforge.net/" />
|
||||
<meta name="generator" content="Docutils 0.8.1: http://docutils.sourceforge.net/" />
|
||||
<title>rapports eole</title>
|
||||
<style type="text/css">
|
||||
|
||||
|
|
32
option.py
32
option.py
|
@ -21,6 +21,7 @@
|
|||
# the whole pypy projet is under MIT licence
|
||||
# ____________________________________________________________
|
||||
from autolib import special_owners
|
||||
from basetype import HiddenBaseType, DisabledBaseType, ModeBaseType, modes
|
||||
from error import (ConfigError, ConflictConfigError, NotFoundError,
|
||||
RequiresError)
|
||||
available_actions = ['hide', 'show', 'enable', 'disable']
|
||||
|
@ -29,37 +30,6 @@ reverse_actions = {'hide': 'show', 'show': 'hide',
|
|||
# ____________________________________________________________
|
||||
# OptionDescription authorized group_type values
|
||||
group_types = ['default', 'family', 'group', 'master']
|
||||
# Option and OptionDescription modes
|
||||
modes = ['normal', 'expert']
|
||||
# ____________________________________________________________
|
||||
# interfaces
|
||||
class HiddenBaseType(object):
|
||||
hidden = False
|
||||
def hide(self):
|
||||
self.hidden = True
|
||||
def show(self):
|
||||
self.hidden = False
|
||||
def _is_hidden(self):
|
||||
# dangerous method: how an Option can determine its status by itself ?
|
||||
return self.hidden
|
||||
|
||||
class DisabledBaseType(object):
|
||||
disabled = False
|
||||
def disable(self):
|
||||
self.disabled = True
|
||||
def enable(self):
|
||||
self.disabled = False
|
||||
def _is_disabled(self):
|
||||
return self.disabled
|
||||
|
||||
class ModeBaseType(object):
|
||||
mode = 'normal'
|
||||
def get_mode(self):
|
||||
return self.mode
|
||||
def set_mode(self, mode):
|
||||
if mode not in modes:
|
||||
raise TypeError("Unknown mode: {0}".format(mode))
|
||||
self.mode = mode
|
||||
# ____________________________________________________________
|
||||
class Option(HiddenBaseType, DisabledBaseType, ModeBaseType):
|
||||
#reminder: an Option object is **not** a container for the value
|
||||
|
|
Loading…
Reference in a new issue