예제 #1
0
파일: test_path.py 프로젝트: nattvara/saas
    def test_end_can_be_treated_as_directory(self):
        """Test end can be treated as directory."""
        path = Path('/example.com/2019-01-13H20:00/foo/bar')
        self.assertEqual('/foo/bar/', path.end_as_directory())

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

        path = Path('/example.com/2019-01-13H20:00/')
        self.assertEqual('/', path.end_as_directory())
예제 #2
0
파일: filesystem.py 프로젝트: nattvara/saas
    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}')
예제 #3
0
파일: filesystem.py 프로젝트: nattvara/saas
    def _list(self, path: str) -> list:
        """List directory.

        Args:
            path: path to directory

        Returns:
            List of directory content
            list
        """
        if path == Filesystem.ROOT_PATH:
            return self._list_root()

        parsed = Path(path)

        if not parsed.includes_captured_at():
            return self._list_unique_captures(parsed.domain)

        return self._list_directory(parsed.domain, parsed.captured_at,
                                    parsed.end_as_directory())