Best Python code snippet using keyboard
zcbuildout.py
Source:zcbuildout.py
1# -*- coding: utf-8 -*-2"""3Management of zc.buildout4=========================5This module is inspired from minitage's buildout maker6(https://github.com/minitage/minitage/blob/master/src/minitage/core/makers/buildout.py)7.. versionadded:: 2016.3.08.. note::9 This state module is beta; the API is subject to change and no promise10 as to performance or functionality is yet present11Available Functions12-------------------13- built14 .. code-block:: yaml15 installed116 buildout.installed:17 - name: /path/to/buildout18 installed219 buildout.installed:20 - name: /path/to/buildout21 - parts:22 - a23 - b24 - python: /path/to/pythonpath/bin/python25 - unless: /bin/test_something_installed26 - onlyif: /bin/test_else_installed27"""28from __future__ import absolute_import, print_function, unicode_literals29# Import python libs30import logging31import sys32# Import salt libs33from salt.ext.six import string_types34# Define the module's virtual name35__virtualname__ = "buildout"36log = logging.getLogger(__name__)37def __virtual__():38 """39 Only load if zc.buildout libs available40 """41 if "buildout.buildout" in __salt__:42 return __virtualname__43 return (False, "buildout module could not be loaded")44INVALID_RESPONSE = "We did not get any expectable answer from docker"45VALID_RESPONSE = ""46NOTSET = object()47MAPPING_CACHE = {}48FN_CACHE = {}49def __salt(fn):50 if fn not in FN_CACHE:51 FN_CACHE[fn] = __salt__[fn]52 return FN_CACHE[fn]53def _ret_status(54 exec_status=None, name="", comment="", result=None, quiet=False, changes=None55):56 if not changes:57 changes = {}58 if exec_status is None:59 exec_status = {}60 if exec_status:61 if result is None:62 result = exec_status["status"]63 scomment = exec_status.get("comment", None)64 if scomment:65 comment += "\n" + scomment66 out = exec_status.get("out", "")67 if not quiet:68 if out:69 if isinstance(out, string_types):70 comment += "\n" + out71 outlog = exec_status.get("outlog", None)72 if outlog:73 if isinstance(outlog, string_types):74 comment += "\n" + outlog75 return {76 "changes": changes,77 "result": result,78 "name": name,79 "comment": comment,80 }81def _valid(exec_status=None, name="", comment="", changes=None):82 return _ret_status(83 exec_status=exec_status,84 comment=comment,85 name=name,86 changes=changes,87 result=True,88 )89def _invalid(exec_status=None, name="", comment="", changes=None):90 return _ret_status(91 exec_status=exec_status,92 comment=comment,93 name=name,94 changes=changes,95 result=False,96 )97def installed(98 name,99 config="buildout.cfg",100 quiet=False,101 parts=None,102 user=None,103 env=(),104 buildout_ver=None,105 test_release=False,106 distribute=None,107 new_st=None,108 offline=False,109 newest=False,110 python=sys.executable,111 debug=False,112 verbose=False,113 unless=None,114 onlyif=None,115 use_vt=False,116 loglevel="debug",117 **kwargs118):119 """120 Install buildout in a specific directory121 It is a thin wrapper to modules.buildout.buildout122 name123 directory to execute in124 quiet125 do not output console & logs126 config127 buildout config to use (default: buildout.cfg)128 parts129 specific buildout parts to run130 user131 user used to run buildout as132 .. versionadded:: 2014.1.4133 env134 environment variables to set when running135 buildout_ver136 force a specific buildout version (1 | 2)137 test_release138 buildout accept test release139 new_st140 Forcing use of setuptools >= 0.7141 distribute142 use distribute over setuptools if possible143 offline144 does buildout run offline145 python146 python to use147 debug148 run buildout with -D debug flag149 onlyif150 Only execute cmd if statement on the host return 0151 unless152 Do not execute cmd if statement on the host return 0153 newest154 run buildout in newest mode155 verbose156 run buildout in verbose mode (-vvvvv)157 use_vt158 Use the new salt VT to stream output [experimental]159 loglevel160 loglevel for buildout commands161 """162 ret = {}163 if "group" in kwargs:164 log.warning("Passing 'group' is deprecated, just remove it")165 output_loglevel = kwargs.get("output_loglevel", None)166 if output_loglevel and not loglevel:167 log.warning(168 "Passing 'output_loglevel' is deprecated," " please use loglevel instead"169 )170 try:171 test_release = int(test_release)172 except ValueError:173 test_release = None174 func = __salt("buildout.buildout")175 kwargs = dict(176 directory=name,177 config=config,178 parts=parts,179 runas=user,180 env=env,181 buildout_ver=buildout_ver,182 test_release=test_release,183 distribute=distribute,184 new_st=new_st,185 offline=offline,186 newest=newest,187 python=python,188 debug=debug,189 verbose=verbose,190 onlyif=onlyif,191 unless=unless,192 use_vt=use_vt,193 loglevel=loglevel,194 )195 ret.update(_ret_status(func(**kwargs), name, quiet=quiet))...
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!!