def guess_initrd(chroot='', regexp=None): """Tries to guess initrd by regexp :param chroot: Path to chroot :param regexp: (String) Regular expression (must have python syntax). Default is r'^(initrd|initramfs).*' """ initrd = utils.guess_filename(path=os.path.join(chroot, 'boot'), regexp=(regexp or r'^(initrd|initramfs).*')) if initrd: return initrd raise errors.GrubUtilsError('Error while trying to find initrd: ' 'regexp=%s' % regexp)
def guess_kernel(chroot='', regexp=None): """Tries to guess kernel by regexp :param chroot: Path to chroot :param regexp: (String) Regular expression (must have python syntax). Default is r'^vmlinuz.*' """ kernel = utils.guess_filename(path=os.path.join(chroot, 'boot'), regexp=(regexp or r'^vmlinuz.*')) if kernel: return kernel raise errors.GrubUtilsError('Error while trying to find kernel: ' 'regexp=%s' % regexp)
def guess_kernel(chroot='', regexp=None): """Tries to guess kernel by regexp :param chroot: Path to chroot :param regexp: (String) Regular expression (must have python syntax). Default is r'^vmlinuz.*' """ kernel = utils.guess_filename( path=os.path.join(chroot, 'boot'), regexp=(regexp or r'^vmlinuz.*')) if kernel: return kernel raise errors.GrubUtilsError('Error while trying to find kernel: ' 'regexp=%s' % regexp)
def guess_initrd(chroot='', regexp=None): """Tries to guess initrd by regexp :param chroot: Path to chroot :param regexp: (String) Regular expression (must have python syntax). Default is r'^(initrd|initramfs).*' """ initrd = utils.guess_filename( path=os.path.join(chroot, 'boot'), regexp=(regexp or r'^(initrd|initramfs).*')) if initrd: return initrd raise errors.GrubUtilsError('Error while trying to find initrd: ' 'regexp=%s' % regexp)
def test_guess_filename_not_exact_match_forward_sort(self, mock_oslistdir): mock_oslistdir.return_value = ["file1", "file2", "file3"] filename = utils.guess_filename("/some/path", "^file.*", reverse=False) # by default files are sorted in backward direction self.assertEqual(filename, "file1") mock_oslistdir.assert_called_once_with("/some/path")
def test_guess_filename_not_found(self, mock_oslistdir): mock_oslistdir.return_value = ["file1", "file2", "file3"] filename = utils.guess_filename("/some/path", "^file4.*") self.assertIsNone(filename) mock_oslistdir.assert_called_once_with("/some/path")
def test_guess_filename(self, mock_oslistdir): mock_oslistdir.return_value = ["file1", "file2", "file3"] filename = utils.guess_filename("/some/path", "^file2.*") self.assertEqual(filename, "file2") mock_oslistdir.assert_called_once_with("/some/path")
def test_guess_filename_not_exact_match_forward_sort(self, mock_oslistdir): mock_oslistdir.return_value = ['file1', 'file2', 'file3'] filename = utils.guess_filename('/some/path', '^file.*', reverse=False) # by default files are sorted in backward direction self.assertEqual(filename, 'file1') mock_oslistdir.assert_called_once_with('/some/path')
def test_guess_filename_not_found(self, mock_oslistdir): mock_oslistdir.return_value = ['file1', 'file2', 'file3'] filename = utils.guess_filename('/some/path', '^file4.*') self.assertIsNone(filename) mock_oslistdir.assert_called_once_with('/some/path')
def test_guess_filename(self, mock_oslistdir): mock_oslistdir.return_value = ['file1', 'file2', 'file3'] filename = utils.guess_filename('/some/path', '^file2.*') self.assertEqual(filename, 'file2') mock_oslistdir.assert_called_once_with('/some/path')