remotelogin/oper_sys/unix/__init__.py
def _can_execute_as_sudo(self, cmd):
        """ checks if cmd is one of the sudo commands available.
        The parsing of the sudo list will leave arguments out to compare. So this check is not exhaustive.

        :param cmd:
        :return:
        """

        def _check():
            # TODO: do a better check of command with command line arguments instead of only the first split
            # TODO: add more checks against command line arguments
            return (self._channels[-1].sudo_list[0] == 'ALL' or
                    cmd in self._channels[-1].sudo_list or cmd.split()[0] in self._channels[-1].sudo_list)

        if cmd == '-l' or (self._channels[-1].sudo_list and _check()):
            return True

        if not self._channels[-1].sudo_list:
            # retrieve shell sudo list
            sudo_cmds, err = self.check_output('-l', use_sudo=True, return_type='list', stderr_to_tmp=False)
            start_sudo = False
            for sudo_cmd in sudo_cmds:
                if start_sudo:
                    sudo_cmd = sudo_cmd.strip()
                    if re.match(r'\([^\)]+\) ALL', sudo_cmd):
                        self._channels[-1].sudo_list = ['ALL']
                        return True
                    self._channels[-1].sudo_list.append(sudo_cmd.split(' ')[2])
                elif sudo_cmd.get_img_coord('may run the following commands on this host') > -1:
                    start_sudo = True

            return _check()

        return False
 checks if cmd is one of the sudo commands available.
        The parsing of the sudo list will leave arguments out to compare. So this check is not exhaustive.

        :param cmd:
        :return:
        
checks if cmd is one of the sudo commands available.
The parsing of the sudo list will leave arguments out to compare. So this check is not exhaustive.
checks if cmd is one of the sudo commands available . The parsing of the sudo list will leave arguments out to compare . So this check is not exhaustive .
def _can_execute_as_sudo(self, cmd):
        def _check():
            return (self._channels[-1].sudo_list[0] == 'ALL' or
                    cmd in self._channels[-1].sudo_list or cmd.split()[0] in self._channels[-1].sudo_list)
        if cmd == '-l' or (self._channels[-1].sudo_list and _check()):
            return True
        if not self._channels[-1].sudo_list:
            sudo_cmds, err = self.check_output('-l', use_sudo=True, return_type='list', stderr_to_tmp=False)
            start_sudo = False
            for sudo_cmd in sudo_cmds:
                if start_sudo:
                    sudo_cmd = sudo_cmd.strip()
                    if re.match(r'\([^\)]+\) ALL', sudo_cmd):
                        self._channels[-1].sudo_list = ['ALL']
                        return True
                    self._channels[-1].sudo_list.append(sudo_cmd.split(' ')[2])
                elif sudo_cmd.get_img_coord('may run the following commands on this host') > -1:
                    start_sudo = True
            return _check()
        return False
def _can_execute_as_sudo ( self , cmd ) : def _check ( ) : return ( self . _channels [ - 1 ] . sudo_list [ 0 ] == 'ALL' or cmd in self . _channels [ - 1 ] . sudo_list or cmd . split ( ) [ 0 ] in self . _channels [ - 1 ] . sudo_list ) if cmd == '-l' or ( self . _channels [ - 1 ] . sudo_list and _check ( ) ) : return True if not self . _channels [ - 1 ] . sudo_list : sudo_cmds , err = self . check_output ( '-l' , use_sudo = True , return_type = 'list' , stderr_to_tmp = False ) start_sudo = False for sudo_cmd in sudo_cmds : if start_sudo : sudo_cmd = sudo_cmd . strip ( ) if re . match ( r'\([^\)]+\) ALL' , sudo_cmd ) : self . _channels [ - 1 ] . sudo_list = [ 'ALL' ] return True self . _channels [ - 1 ] . sudo_list . append ( sudo_cmd . split ( ' ' ) [ 2 ] ) elif sudo_cmd . get_img_coord ( 'may run the following commands on this host' ) > - 1 : start_sudo = True return _check ( ) return False
checks if cmd is one of the sudo commands available.
checks if cmd is one of the sudo commands available .
""" checks if cmd is one of the sudo commands available.
        The parsing of the sudo list will leave arguments out to compare. So this check is not exhaustive.

        :param cmd:
        :return:
        """ # TODO: do a better check of command with command line arguments instead of only the first split # TODO: add more checks against command line arguments # retrieve shell sudo list
None
self
cmd
None