def __init__(self, args, kwargs, cfgargs, popenargs, will): # Attach the global EVENT here for later access # remember this for resetting self._reset_async = cfgargs['async'] self.shell = cfgargs.shell self.encoding = cfgargs.encoding self.okcode = cfgargs.okcode self.timeout = cfgargs.timeout self.raise_ = cfgargs['raise'] self.should_close_fds = _Diot() # Should I wait for the results, or just run asyncronouslly # This should be controlled by plugins # to communicate between each other # This only works in sync mode self.should_wait = False self.did = self.curr = '' self.will = will # pipes self.stdin = _subprocess.PIPE self.stdout = _subprocess.PIPE self.stderr = _subprocess.PIPE popenargs.shell = False self.popenargs = popenargs # data carried by actions (ie redirect, pipe, etc) self.data = _Diot({'async': cfgargs['async'], 'hold': False}) self.cmd = _cmdy_compose_cmd(args, kwargs, cfgargs, shell=self.shell)
def reset(self): """Reset the holding object for reuse""" # pipes self.stdin = _subprocess.PIPE self.stdout = _subprocess.PIPE self.stderr = _subprocess.PIPE self.did = self.curr = self.will = '' self.should_close_fds = _Diot() self.data = _Diot({'async': self._reset_async, 'hold': False}) return self
def __call__(self, *args, **kwargs): _args, _kwargs, _cfgargs, _popenargs = _cmdy_parse_args( self._name, args, kwargs, CMDY_CONFIG, _CMDY_BAKED_ARGS) ready_args = (self._args or []) + _args ready_kwargs = self._kwargs.copy() if self._kwargs else {} ready_kwargs.update(_kwargs) ready_cfgargs = CMDY_CONFIG.copy() ready_cfgargs.update(self._cfgargs or {}) ready_cfgargs.update(_cfgargs) ready_popenargs = self._popenargs.copy() if self._popenargs else _Diot( ) ready_popenargs.update(_popenargs) # clear direct subcommand for reuse self._args = [] if ready_cfgargs.pop('sub', False): return CmdyHoldingWithSub(self._name, ready_args, ready_kwargs, ready_cfgargs, ready_popenargs) # update the executable exe = ready_cfgargs.pop('exe', None) or self._name # Let CmdyHolding handle the result return CmdyHolding([str(exe)] + ready_args, ready_kwargs, ready_cfgargs, ready_popenargs, _will(raise_exc=False))
def __init__(self, proc, holding): self.proc = proc self.holding = holding self.did = self.curr = '' self.will = holding.will self._stdout = None self._stderr = None self.data = _Diot() self._rc = None
def _bake(self, **kwargs): """Bake a command""" if _will(raise_exc=False): raise CmdyActionError("Baking Cmdy object is supposed to " "be reused.") pure_cmd_kwargs, global_config, popen_config = ( _cmdy_parse_single_kwarg(kwargs, True, self._cfgargs or CMDY_CONFIG)) kwargs = self._kwargs.copy() if self._kwargs else {} kwargs.update(pure_cmd_kwargs) config = self._cfgargs.copy() if self._cfgargs else _Diot() config.update(global_config) pconfig = self._popenargs.copy() if self._popenargs else _Diot() pconfig.update(popen_config) return self.__class__(self._name, self._args, kwargs, config, pconfig)
def __new__( cls, # pylint: disable=too-many-function-args args: list, kwargs: dict, cfgargs: _Diot, popenargs: _Diot, will: str = None): holding = super().__new__(cls) # Use the _onhold function, but fake an object if cls._onhold(_Diot(data=_Diot(hold=False), did='', will=will)): # __init__ automatically called return holding holding.__init__(args, kwargs, cfgargs, popenargs, will) result = holding.run() if not will: return result.wait() return result
from .cmdy_plugin import _cmdy_hook_class, _CmdyPluginProxy __version__ = "0.4.3" # pylint: disable=invalid-overridden-method # We cannot define the variables that need to be baked # in submodules, because we don't want to deepcopy the # whole module. _CMDY_DEFAULT_CONFIG = _Diot({ 'async': False, 'deform': lambda name: name.replace('_', '-'), 'dupkey': False, 'exe': None, 'encoding': 'utf-8', 'okcode': [0], 'prefix': 'auto', 'raise': True, 'sep': ' ', 'shell': False, 'sub': False, 'timeout': 0 }) CMDY_CONFIG = _Config() CMDY_CONFIG._load(dict(default=_CMDY_DEFAULT_CONFIG), '~/.cmdy.toml', './.cmdy.toml', 'CMDY.osenv') _CMDY_BAKED_ARGS = _Diot() _CMDY_EVENT = _Event() # The actions that will put left side on hold