Source code for libvhc

"""
"""
from __future__ import absolute_import, print_function

__version__ = "0.0.1"


[docs]class VCheck(object): """Store the information about the current check. The attributes can be accessed in the standard way, e.g. ``instance.attribute``, or as in a dictionary, e.g. ``instance["attribute"]``. Parameters ---------- recipe : string name of the recipe check : string name of the check Examples -------- >>> recipe = "flat" >>> checks = ["common:n_pixels", "flat:saturation"] >>> vcheck = VCheck(recipe) >>> for c in checks: ... vcheck.check = c ... # call the correct check function ... print(vcheck) recipe: flat, check: common:n_pixels recipe: flat, check: flat:saturation >>> print(vcheck.recipe) flat >>> print(vcheck["recipe"]) flat >>> print(vcheck.check) flat:saturation >>> print(vcheck["check"]) flat:saturation >>> for k in vcheck: ... print(k, vcheck[k]) recipe flat check flat:saturation >>> repr(vcheck) "VCheck('flat', 'flat:saturation')" >>> vcheck['attribute'] Traceback (most recent call last): ... KeyError: attribute is not a valid key >>> # you can also change the recipe name >>> vcheck.recipe = 'new_recipe' """ def __init__(self, recipe="", check=""): self._recipe = recipe self._check = check # list of attributes accessible as dictionary self._keys = ["recipe", "check"] @property def recipe(self): return self._recipe @recipe.setter def recipe(self, recipe): self._recipe = recipe @property def check(self): return self._check @check.setter def check(self, check): self._check = check def as_dict(self): """returns a dictionary of the keys-value accessible as :class:``VCheck`` where a dictionary""" return {k: self[k] for k in self._keys} def __str__(self): descr = "recipe: {}, check: {}".format(self.recipe, self.check) return descr def __repr__(self): descr = "{name}('{recipe}', '{check}')" return descr.format(name=self.__class__.__name__, recipe=self.recipe, check=self.check) def __getitem__(self, key): if key in self._keys: return getattr(self, key) else: raise KeyError("{} is not a valid key".format(key)) def __iter__(self): return iter(['recipe', 'check'])
[docs]def function_signature(vcheck, path, argv, *args, **kwargs): """Prototype of a function implementing a VHC driver. Parameters ---------- vcheck : instance of :class:`~libvhc.VCheck` store the recipe name and the check currently executing path : string path provided to the ``vhc`` executable. argv : list of strings remaining of the command line args : list positional arguments. Not used when calling from ``vhc`` kwargs : dictionary keyword arguments. Not used when calling from ``vhc`` """ pass # pragma: no cover