Open main menu

Changes

Relax source design

663 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 ===
Here is a prototype functionfor implementing the check object:
<source lang="python">
# 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. @type a: str @keyword ab: Some check specific keyword argument. @type ab: 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
"""
# InitCheck that... check_ok if not something(a, b): return RelaxError("Some text") # Create the checking object.check_aaa = Check(check_aaa_func) </source> In the module where the check is performed, the code would be: <source lang= True"python"> # relax module imports.from aaa import check_aaa
# Check that...
if not something(a):
check_ok = False
# Return the status and message.def bbb(): return check_ok, "Something is missing""Some function."""
# Create the checking objectChecks.check_xxx a = Check'600 MHz' b = 600 check_aaa(check_xxx_funca, b=b)
</source>
 
Note that the lib.checks.Check.__call__() method will take the escalate argument for itself and pass 'a' and 'b' into the 'check_aaa_func' function as arguments. The escalate argument defaults to 2.
 
== See also ==
 
[[Category:Development]]
Trusted, Bureaucrats
4,228

edits