Best Python code snippet using pandera_python
sge_centos7.py
Source:sge_centos7.py  
...40        self.sge_master_host = self.args.get('sge_master_host', {})41        self.need_variable_names = ["sge_install_dir", "sge_root_name", "sge_cluster_name", "sge_admin_user"]42        self.require_params = ["sge_master_host"]43        self._check_params(self.require_params)44        self._custom_check()45        self._state = self.args.get("state", "install")46        self.task_name = "sge_master_%s" % self._state47        self.target_hosts = [self.sge_master_host]48        self.extra_var = self._get_extra_var(self.need_variable_names)49        self._custom_extra_var()50    def _custom_check(self):51        for key in ["ip", "hostname"]:52            if not self.sge_master_host.has_key(key):53                raise exception.ParamsMissing("sge_master_host<%s>" % key)54    def _custom_extra_var(self):55        self.extra_var["etc_hosts"] = [56            {key: self.sge_master_host[key] for key in ["ip", "hostname"]}57        ]58    def run(self):59        return AnsibleTask(self.task_name, self.extra_var).api_run(self.target_hosts)60class SgeClient(Sge):61    """62    å®è£
é¨ç½²sge客æ·ç«¯63    åæ°:64        sge_install_dir: sgeå®è£
ç®å½65        sge_root_name: sgeæ ¹åç§°66        sge_cluster_name: é群åç§°67        sge_master_host: sge master主æº68        sge_execd_hosts: æ§è¡ä¸»æºå表69        queue_name: éååç§°70    """71    def __init__(self, **kwargs):72        self.args = utils.convert(kwargs)73        self.sge_install_dir = self.args.get('sge_install_dir', '/opt')74        self.sge_root_name = self.args.get('sge_root_name', 'sge')75        self.sge_cluster_name = self.args.get('sge_cluster_name', 'rzl')76        self.sge_master_host = self.args.get('sge_master_host', {})77        self.sge_execd_hosts = self.args.get('sge_execd_hosts', [])78        self.queue_name = self.args.get('queue_name', "")79        self.need_variable_names = ["sge_install_dir", "sge_root_name", "sge_cluster_name", "queue_name"]80        self.require_params = ["sge_master_host", "sge_execd_hosts"]81        self._check_params(self.require_params)82        self._custom_check()83        self._state = self.args.get("state", "install")84        self.task_name = "sge_client_%s" % self._state85        self.target_hosts = self.sge_execd_hosts86        self.extra_var = self._get_extra_var(self.need_variable_names)87        self._custom_extra_var()88    def _custom_check(self):89        for key in ["ip", "hostname"]:90            if not self.sge_master_host.has_key(key):91                raise exception.ParamsMissing("sge_master_host<%s>" % key)92        for d in self.sge_execd_hosts:93            for key in ["ip", "hostname"]:94                if not d.has_key(key):95                    raise exception.ParamsMissing("sge_execd_hosts<%s>" % key)96    def _custom_extra_var(self):97        etc_hosts = []98        execd_hostname_list = []99        etc_hosts.append({key: self.sge_master_host[key] for key in ["ip", "hostname"]})100        for d in self.sge_execd_hosts:101            etc_hosts.append({key: d[key] for key in ["ip", "hostname"]})102            execd_hostname_list.append(d["hostname"])...common.py
Source:common.py  
1"""Shared functions and classes for frontends."""2from __future__ import absolute_import as _abs3import warnings4from .._base import string_types5class Renamer(object):6    """A simply renamer for operators.7    Parameters8    ----------9    new_name : str10        The new name for the operator11    """12    def __init__(self, new_name):13        self._new_name = new_name14    def __call__(self, attrs):15        return self._new_name, attrs16class AttrConverter(object):17    """Common attribute conveter. An AttrConverter instance is a callable:18    ```19    attr_converter = AttrConverter(op_name, transforms={'a':'b', 'c':('d', 1)})20    new_op_name, new_attr = attr_converter(attrs)21    ```22    Parameters23    ----------24    op_name : str or callable25        If set as str, returned operator name is the str.26        If set as callable, returned operator is the str returned by calling:27        `op_name = func(attr)`28    transforms : dict of `new_name, or (new_name, default_value, transform function)`29        If only a new_name is provided, it's like renaming the attribute name.30        If default_value if provded, then the attribute is considered as optional.31        If transform function is provided, the original attribute value is handled32        by transform function.33    excludes : list34        A list of excluded attributes that should `NOT` appear.35        Raise NotImplementedError if occured.36    disables : list37        A list of attributes that is disabled in nnvm. Raise warnings.38    ignores : list39        A list of attributes that is ignored in nnvm. Silent.40    extras : dict41        A series of additional attributes should be added anyway to the returned42        attribute dict.43    custom_check : callable44        A custom function takes attribute, and return True/False.45        Raise RuntimeError if not bool(True) returned.46    """47    def __init__(self, op_name, transforms=None,48                 excludes=None, disables=None, ignores=None,49                 extras=None, custom_check=None):50        self._op_name = op_name51        self._transforms = transforms if transforms else {}52        self._excludes = excludes if excludes else []53        self._disables = disables if disables else []54        self._ignores = ignores if ignores else []55        self._extras = extras if extras else {}56        self._custom_check = custom_check57    def __call__(self, attrs):58        # apply custom check59        if self._custom_check:60            func, msg = self._custom_check61            if not func(attrs):62                raise RuntimeError("Check failed: {}".format(msg))63        # get new op_name64        if isinstance(self._op_name, string_types):65            op_name = self._op_name66        else:67            assert callable(self._op_name), "op_name can either be string or callable"68            op_name = self._op_name(attrs)69        # convert attributes70        new_attrs = {}71        for k in attrs.keys():72            if k in self._excludes:73                raise NotImplementedError("Attribute {} not supported yet.".format(k))74            elif k in self._disables:75                warnings.warn("Attribute {} is disabled in nnvm.sym.{}".format(k, op_name))76            elif k in self._ignores:77                pass78            elif k in self._transforms:79                new_name, defaults, transform = self._parse_default(self._transforms[k])80                if defaults is None:81                    new_attr = self._required_attr(attrs, k)82                else:83                    new_attr = attrs.get(k, None)84                if new_attr is None:85                    new_attrs[new_name] = defaults86                else:87                    new_attrs[new_name] = transform(new_attr)88            else:89                # copy90                new_attrs[k] = attrs[k]91        # add extras92        new_attrs.update(self._extras)93        return op_name, new_attrs94    def _parse_default(self, target):95        """Helper function to parse default values."""96        if not isinstance(target, (list, tuple)):97            k, v, t = target, None, lambda x: x98        elif len(target) == 1:99            k, v, t = target[0], None, lambda x: x100        elif len(target) == 2:101            k, v, t = target[0], target[1], lambda x: x102        elif len(target) > 2:103            k, v, t = target[0], target[1], target[2]104        else:105            k = None  # should raise106        if not isinstance(k, string_types):107            msg = "{} is not a valid target, (name, default) expected.".format(target)108            raise ValueError(msg)109        return k, v, t110    def _parse_bool(self, value):111        """Helper function to parse default boolean values."""112        if isinstance(value, string_types):113            return value.strip().lower() in ['true', '1', 't', 'y', 'yes']114        return bool(value)115    def _required_attr(self, attr, key):116        """Wrapper for getting required attributes."""117        assert isinstance(attr, dict)118        if key not in attr:119            raise AttributeError("Required attribute {} not found.".format(key))...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
