Open main menu

Changes

Relax source design

131 bytes added, 17:10, 6 November 2015
Added the Category:Infobox templates category.
{{lowercase title}}
 
{{stub}}
 
The following is a set of notes which will be used to design the layout of functions, modules, and packages in relax.
== The check_*() functions ==
These functions are for performing checks for certain data being present. The idea uses the [https://en.wikipedia.org/wiki/Strategy_pattern strategy design pattern] which is implemented in the lib.checks.Check class. Therefore these are really function-like objects.
=== Packages ===
=== Design ===
The check_*() functions, via the Check object__call__() method, accept the 'escalate' keyword argument which can have the following values:
* 0 - This will simply cause the function to return True or False.
* 1 - In addition to returning True or False, the function will throw a RelaxWarning for better user feedback.
* 2 - This will cause a RelaxError to be raised if the data is missing, not set up, etc. Otherwise the function returns True.
 
The default value is 2.
=== Implementation ===
# relax module imports.
from lib.checks import Check
from lib.errors import RelaxError
def check_xxx_funccheck_aaa_func(a, b=None): """Check if xxxaaa.
@param a: Some check specific argument.
@keyword b: Some check specific keyword argument.
@type b: int
@return: The status of the check and the message to send to the userinitialised RelaxError object or nothing. @rtype: bool, strNone or RelaxError instance
"""
 
# Init.
check_ok = True
# Check that...
if not something(a, b):
check_ok = False  # Return the status and message. return check_ok, RelaxError("Something is missing.Some text")
# Create the checking object.
check_xxx check_aaa = Check(check_xxx_funccheck_aaa_func)
</source>
# relax module imports.
from xxx aaa import check_xxxcheck_aaa
def aaabbb():
"""Some function."""
a = '600 MHz'
b = 600
check_xxxcheck_aaa(a, b=b, escalate=2)
</source>
Note that the lib.checks.Check.__call__() method will take the escalate argument for itself and pass 'a' and 'b' into the 'check_xxx_funccheck_aaa_func' function as arguments. The escalate argument defaults to 2. == See also == [[Category:Development]]
Trusted, Bureaucrats
4,223

edits