Beispiel #1
0
    def test_check_for_end(self):
        """Test check for end."""
        path = Path('/example.com/2019-01-13H20:00/foo/bar')
        self.assertTrue(path.includes_end())

        path = Path('/example.com/2019-01-13H20:00/foo')
        self.assertTrue(path.includes_end())

        path = Path('/example.com/2019-01-13H20:00/')
        self.assertFalse(path.includes_end())

        path = Path('/example.com/2019-01-13H20:00')
        self.assertFalse(path.includes_end())

        path = Path('/example.com/')
        self.assertFalse(path.includes_end())

        path = Path('/')
        self.assertFalse(path.includes_captured_at())
Beispiel #2
0
    def _attributes(self, path: str) -> dict:
        """Get attributes of file at path.

        Args:
            path: path to file

        Returns:
            Dictionary with file attributes, see files module
            dict

        Raises:
            FileNotFoundError: if no file exists at given path
        """
        if path == Filesystem.ROOT_PATH:
            return Directory.attributes()

        parsed = Path(path)

        if parsed.includes_domain() and not parsed.includes_captured_at():
            domains = self.index.photos_unique_domains(self.refresh_rate)
            if parsed.domain not in domains:
                raise FileNotFoundError(f'Unkown domain: {parsed.domain}')
            return Directory.attributes()

        if parsed.includes_captured_at() and not parsed.includes_end():
            captures = self.index.photos_unique_captures_of_domain(
                parsed.domain, self.refresh_rate)
            captures.append(LastCapture.FILENAME)
            if parsed.captured_at not in captures:
                raise FileNotFoundError(
                    f'Unkown capture: {parsed.captured_at}')
            return Directory.attributes()

        if self.index.photos_directory_exists(
                domain=parsed.domain,
                captured_at=parsed.captured_at,
                directory=parsed.end_as_directory(),
                refresh_rate=self.refresh_rate):
            return Directory.attributes()

        file_exists = self.index.photos_file_exists(
            domain=parsed.domain,
            captured_at=parsed.captured_at,
            full_filename=parsed.end_as_file(),
            refresh_rate=self.refresh_rate)
        if file_exists:
            return File.attributes(None, file_exists)

        raise FileNotFoundError(f'No file at path: {path}')