'Implements the boot once feature for the grub bootloader'

def boot_once_grub(self, entry_index):

    grubonce_cmd = find_executable('grubonce')
    if (grubonce_cmd is None):
        grub_instructions = [('savedefault    --default=%s    --once' % entry_index), 'quit']
        grub_instructions_text = '\n'.join(grub_instructions)
        grub_binary = find_executable('grub')
        if (grub_binary is None):
            self.log.error("Could    not    find    the    'grub'    binary,    aborting")
            return (-1)
        p = subprocess.Popen([grub_binary, '--batch'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        (out, err) = p.communicate(grub_instructions_text)
        complete_out = ''
        if (out is not None):
            complete_out = out
        if (err is not None):
            complete_out += ('\n%s' % err)
        grub_batch_err = []
        if complete_out:
            for l in complete_out.splitlines():
                if re.search('error', l, re.IGNORECASE):
                    grub_batch_err.append(l)
            if grub_batch_err:
                self.log.error('Error    while    running    grub    to    set    boot    once:    %s', '\n'.join(grub_batch_err))
                return (-1)
        self.log.debug('No    error    detected    while    running    grub    to    set    boot    once')
        return 0
    else:
        rc = self._run_get_return([grubonce_cmd, str(entry_index)])
        if rc:
            self.log.error('Error    running    %s', grubonce_cmd)
        else:
            self.log.debug('No    error    detected    while    running    %s', grubonce_cmd)
        return rc
