Esempio n. 1
0
    def _translate_path(self, path: str) -> str:
        """Translate path to path in data dir.

        Args:
            path: Path in mounted directory eg.
                /example.com/2019-01-13H20:00/foo/bar.png

        Returns:
            Path in data directory to raw data
            str

        Raises:
            FileNotFoundError: If file at given path does not exist
        """
        parsed = Path(path)
        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 not exists:
            raise FileNotFoundError('photo do not exist in index')

        photo = self.index.photos_get_photo(domain=parsed.domain,
                                            captured_at=parsed.captured_at,
                                            full_filename=parsed.end_as_file(),
                                            refresh_rate=self.refresh_rate)

        return photo.path.full_path()
Esempio n. 2
0
    def test_end_can_be_treated_as_file(self):
        """Test end can be treated as file."""
        path = Path('/example.com/2019-01-13H20:00/foo/bar')
        self.assertEqual('/foo/bar', path.end_as_file())

        path = Path('/example.com/2019-01-13H20:00/foo/bar/')
        self.assertEqual('/foo/bar', path.end_as_file())

        path = Path('/example.com/2019-01-13H20:00/')
        self.assertEqual('/', path.end_as_file())
Esempio n. 3
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}')