Beispiel #1
0
    def from_elastic_entry(e):
        if e.kind == Constants.IMAGE_KIND:
            item = Image()
        elif e.kind == Constants.VIDEO_KIND:
            item = Video()
        elif e.kind == Constants.OTHER_KIND:
            item = Other()
        else:
            raise FactoryError(
                f"Entry mismatch, wrong kind {e.kind} found for: {e.name}; id:{e.meta.id}"
            )

        item.full_path = os.path.join(e.path, e.name)
        if e.type != item.type:
            raise FactoryError(f"Type mismatch for {e.name}")
        if e.kind != item.kind:
            raise FactoryError(f"Kind mismatch for {e.name}")
        for attr, value in inspect.getmembers(
                e, lambda a: not (inspect.isroutine(a))):
            if attr not in Constants.leave_out_when_reading_from_elastic:
                setattr(item, attr, value)
        if item.hash != e.hash:
            raise FactoryError(f"Hash mismatch for {e.name}")
        if item.path_hash != e.path_hash:
            raise FactoryError(f"Path-hash mismatch for {e.name}")
        item.id = e.meta.id

        return item
Beispiel #2
0
    def test_diff(self):
        image = Image()
        image.full_path = "/this/is/my/image.png"
        image.modified = 1000000
        image.size = 10
        image.checksum = "ABCDEFGH"

        self.assertFalse(image.diff(image))

        image2 = Image()
        image2.full_path = image.full_path
        image2.modified = 2000000
        image2.size = image.size
        image2.checksum = image.checksum

        self.assertEqual(image.diff(image2), {"modified": image2.modified})
Beispiel #3
0
 def from_dropbox(entry):
     """Create an Image or Video object based on the dropbox path given"""
     try:
         result = Image()
         result.full_path = entry['path']
     except InvalidImageError:
         try:
             result = Video()
             result.full_path = entry['path']
         except InvalidVideoError:
             try:
                 result = Other()
                 result.full_path = entry['path']
             except InvalidOtherError:
                 raise FactoryError(
                     f"Path {entry['path']} is neither image nor video nor other"
                 )
     del entry['path']
     return result.update(entry)