Exemplo n.º 1
0
    def defaults_values(self, db, api_client):
        """Created default user and library."""
        self.api_client = api_client
        library_user = LibraryUserFactory()
        library = library_user.library
        user = library_user.user
        user.set_password('demo123456')
        user.save()
        LibraryPath.objects.create(library=library,
                                   type="St",
                                   backend_type='Lo',
                                   path='/data/photos/')
        snow_path = str(Path(__file__).parent / 'photos' / 'snow.jpg')
        snow_photo = record_photo(snow_path, library)

        tree_path = str(Path(__file__).parent / 'photos' / 'tree.jpg')
        tree_photo = record_photo(tree_path, library)

        self.defaults = {
            'library_user': library_user,
            'library': library,
            'user': user,
            'snow_photo': snow_photo,
            'tree_photo': tree_photo,
            'password': '******',
        }
Exemplo n.º 2
0
    def import_photos(self):
        # Create demo User account
        try:
            user = User.objects.create_user(username='******',
                                            email='*****@*****.**',
                                            password='******')
        except IntegrityError:
            user = User.objects.get(username='******')

        # Create Library
        library, _ = Library.objects.get_or_create(
            name='Demo Library',
            # base_thumbnail_path='/data/cache/thumbnails/',
            # base_thumbnail_url='/thumbnails/'
        )
        library_path, _ = LibraryPath.objects.get_or_create(
            library=library,
            type='St',
            backend_type='Lo',
            path='/data/photos/',
            url='/photos/',
        )
        library_user, _ = LibraryUser.objects.get_or_create(library=library,
                                                            user=user)

        # Add photos
        for url in URLS:
            dest_dir = determine_destination(url)
            fn = url.split('/')[-1]
            dest_path = str(Path(dest_dir) / fn)

            if not os.path.exists(dest_path):
                print('Fetching {} -> {}'.format(url, dest_path))
                download_file(url, dest_path)
                record_photo(dest_path, library)
Exemplo n.º 3
0
def import_photos_from_dir(orig, move=False):
    imported = 0
    were_duplicates = 0
    were_bad = 0

    for r, d, f in os.walk(orig):
        if SYNOLOGY_THUMBNAILS_DIR_NAME in r:
            continue
        for fn in sorted(f):
            filepath = os.path.join(r, fn)
            dest = determine_destination(filepath)
            if blacklisted_type(fn):
                # Blacklisted type
                were_bad += 1
            elif not dest:
                # No filters match this file type
                pass
            else:
                t = get_datetime(filepath)
                if t:
                    destpath = '%02d/%02d/%02d' % (t.year, t.month, t.day)
                    destpath = os.path.join(dest, destpath)
                    mkdir_p(destpath)
                    destpath = os.path.join(destpath, fn)

                    if filepath == destpath:
                        # File is already in the right place so be very careful not to do anything like delete it
                        pass
                    elif not os.path.exists(destpath):
                        if move:
                            shutil.move(filepath, destpath)
                        else:
                            shutil.copyfile(filepath, destpath)
                        record_photo(destpath)
                        imported += 1
                        print('IMPORTED  {} -> {}'.format(filepath, destpath))
                    else:
                        print('PATH EXISTS  {} -> {}'.format(filepath, destpath))
                        same = determine_same_file(filepath, destpath)
                        print('PHOTO IS THE SAME')
                        if same:
                            if move:
                                os.remove(filepath)
                                were_duplicates += 1
                                print('DELETED FROM SOURCE')
                        else:
                            print('NEED TO IMPORT UNDER DIFFERENT NAME')
                            exit(1)
                            destpath = find_new_file_name(destpath)
                            shutil.move(filepath, destpath)
                            record_photo(destpath)
                            imported += 1
                            # print 'IMPORTED  {} -> {}'.format(filepath, destpath)

                else:
                    print('ERROR READING DATE: {}'.format(filepath))
                    were_bad += 1

    if imported or were_duplicates:
        print('\n{} PHOTOS IMPORTED\n{} WERE DUPLICATES\n{} WERE BAD'.format(imported, were_duplicates, were_bad))
Exemplo n.º 4
0
    def import_photos(self):
        for url in URLS:
            dest_dir = determine_destination(url)
            fn = url.split('/')[-1]
            dest_path = str(Path(dest_dir) / fn)

            if not os.path.exists(dest_path):
                print('Fetching {} -> {}'.format(url, dest_path))
                download_file(url, dest_path)
                record_photo(dest_path)
Exemplo n.º 5
0
    def import_photos(self):
        # Create demo User account
        try:
            user = User.objects.create_user(username='******',
                                            email='*****@*****.**',
                                            password='******')
            user.has_config_persional_info = True
            user.has_created_library = True
            user.has_configured_importing = True
            user.has_configured_image_analysis = True
            user.save()
        except IntegrityError:
            user = User.objects.get(username='******')

        # Create Library
        try:
            library = Library.objects.get(name='Demo Library', )
        except Library.DoesNotExist:
            library = Library(name='Demo Library',
                              classification_color_enabled=True,
                              classification_location_enabled=True,
                              classification_style_enabled=True,
                              classification_object_enabled=True,
                              classification_face_enabled=True,
                              setup_stage_completed='Th')
            library.save()

        # LibraryPath as locally mounted volume
        LibraryPath.objects.get_or_create(
            library=library,
            type='St',
            backend_type='Lo',
            path='/data/photos/',
            url='/photos/',
        )

        # Link User to Library
        # In dev environment user needs to be owner to access all functionality
        # but demo.photonix.org this could lead to the system being messed up
        owner = os.environ.get('ENV') == 'dev'
        LibraryUser.objects.get_or_create(library=library,
                                          user=user,
                                          owner=owner)

        # Add photos
        for url in URLS:
            dest_dir = determine_destination(url)
            fn = url.split('/')[-1]
            dest_path = str(Path(dest_dir) / fn)

            if not os.path.exists(dest_path):
                logger.info('Fetching {} -> {}'.format(url, dest_path))
                download_file(url, dest_path)
                record_photo(dest_path, library)
Exemplo n.º 6
0
    def watch_photos(self, paths):
        for path in paths:
            print(path)
            # TODO: Work out how to watch multiple paths at once
            i = inotify.adapters.InotifyTree(path)

            for event in i.event_gen():
                if event is not None:
                    (header, type_names, watch_path, filename) = event
                    # if set(type_names).intersection(['IN_CLOSE_WRITE', 'IN_DELETE', 'IN_MOVED_FROM', 'IN_MOVED_TO']):  # TODO: Make moving photos really efficient by using the 'from' path
                    if set(type_names).intersection(['IN_CLOSE_WRITE', 'IN_DELETE', 'IN_MOVED_TO']):
                        photo_path = '{}/{}'.format(watch_path, filename)
                        record_photo(photo_path)
Exemplo n.º 7
0
    def test_fix347(self):
        # Test fix 347 - Photos with same date are not imported
        path_photo1 = str(
            Path(__file__).parent / 'photos' / 'photo_no_metadata_1.jpg')
        Path(path_photo1).touch()

        path_photo2 = str(
            Path(__file__).parent / 'photos' / 'photo_no_metadata_2.jpg')
        Path(path_photo2).touch()

        photo1 = record_photo(path_photo1, self._library)
        photo2 = record_photo(path_photo2, self._library)

        assert (not photo1 == photo2)
Exemplo n.º 8
0
def import_photos_in_place(library_path):
    orig = library_path.path
    imported = 0
    were_bad = 0

    for r, d, f in os.walk(orig):
        for fn in sorted(f):
            filepath = os.path.join(r, fn)
            if blacklisted_type(fn):
                # Blacklisted type
                were_bad += 1
            elif os.path.getsize(filepath) < 102400:
                print(
                    'FILE VERY SMALL (<100k - PROBABLY THUMBNAIL), NOT IMPORTING {}'
                    .format(filepath))
                were_bad += 1
            elif os.path.getsize(filepath) > 1073741824:
                print(
                    'FILE VERY LARGE (>1G - PROBABLY VIDEO), NOT IMPORTING {}'.
                    format(filepath))
                were_bad += 1
            else:
                modified = record_photo(filepath, library_path.library)
                if modified:
                    imported += 1
                    print('IMPORTED  {}'.format(filepath))

    if imported:
        print('\n{} PHOTOS IMPORTED\n{} WERE BAD'.format(imported, were_bad))
Exemplo n.º 9
0
    def import_photos(self):
        # Create demo User account
        try:
            user = User.objects.create_user(username='******',
                                            email='*****@*****.**',
                                            password='******')
            user.has_config_persional_info = True
            user.has_created_library = True
            user.has_configured_importing = True
            user.has_configured_image_analysis = True
            user.save()
        except IntegrityError:
            user = User.objects.get(username='******')

        # Create Library
        library, _ = Library.objects.get_or_create(
            name='Demo Library',
            # base_thumbnail_path='/data/cache/thumbnails/',
            # base_thumbnail_url='/thumbnails/'
        )
        # LibraryPath as locally mounted volume
        library_path, _ = LibraryPath.objects.get_or_create(
            library=library,
            type='St',
            backend_type='Lo',
            path='/data/photos/',
            url='/photos/',
        )

        # Link User to Library
        # In dev environment user needs to be owner to access all functionality
        # but demo.photonix.org this could lead to the system being messed up
        owner = os.environ.get('ENV') == 'dev'
        library_user, _ = LibraryUser.objects.get_or_create(library=library,
                                                            user=user,
                                                            owner=owner)

        # Add photos
        for url in URLS:
            dest_dir = determine_destination(url)
            fn = url.split('/')[-1]
            dest_path = str(Path(dest_dir) / fn)

            if not os.path.exists(dest_path):
                print('Fetching {} -> {}'.format(url, dest_path))
                download_file(url, dest_path)
                record_photo(dest_path, library)
Exemplo n.º 10
0
    def defaults(self, db):
        library_user = LibraryUserFactory()
        library = library_user.library
        user = library_user.user

        snow_path = str(Path(__file__).parent / 'photos' / 'snow.jpg')
        snow_photo = record_photo(snow_path, library)

        tree_path = str(Path(__file__).parent / 'photos' / 'tree.jpg')
        tree_photo = record_photo(tree_path, library)

        return {
            'library_user': library_user,
            'library': library,
            'user': user,
            'snow_photo': snow_photo,
            'tree_photo': tree_photo,
        }
Exemplo n.º 11
0
    def watch_photos(self):
        library_paths = LibraryPath.objects.filter(type='St',
                                                   backend_type='Lo')

        for library_path in library_paths:
            print(f'Watching path for changes {library_path.path}')

            # TODO: Work out how to watch multiple paths at once
            i = inotify.adapters.InotifyTree(library_path.path)

            for event in i.event_gen():
                if event is not None:
                    (header, type_names, watch_path, filename) = event
                    # if set(type_names).intersection(['IN_CLOSE_WRITE', 'IN_DELETE', 'IN_MOVED_FROM', 'IN_MOVED_TO']):  # TODO: Make moving photos really efficient by using the 'from' path
                    if set(type_names).intersection(
                        ['IN_CLOSE_WRITE', 'IN_DELETE', 'IN_MOVED_TO']):
                        photo_path = '{}{}'.format(watch_path, filename)
                        print(
                            f'Recording photo "{photo_path}" to library "{library_path.library}"'
                        )
                        record_photo(photo_path, library_path.library)
Exemplo n.º 12
0
def photo_fixture_raw(db):
    from photonix.photos.utils.db import record_photo
    photo_index = 4  # Photo selected because it doesn't have width and height metadata
    raw_photo_path = str(Path(__file__).parent / 'photos' / PHOTOS[photo_index][0])
    if not os.path.exists(raw_photo_path):
        urls = PHOTOS[photo_index][3]
        for url in urls:
            try:
                download_file(url, raw_photo_path)
                break
            except:
                pass
    return record_photo(raw_photo_path)
Exemplo n.º 13
0
def import_photos_in_place(orig):
    imported = 0
    were_bad = 0

    for r, d, f in os.walk(orig):
        for fn in sorted(f):
            filepath = os.path.join(r, fn)
            if os.path.getsize(filepath) < 102400:
                print('FILE VERY SMALL (<100k - PROBABLY THUMBNAIL), NOT IMPORTING {}'.format(filepath))
                were_bad += 1
            else:
                modified = record_photo(filepath)
                if modified:
                    imported += 1
                    print('IMPORTED  {}'.format(filepath))

    if imported:
        print('\n{} PHOTOS IMPORTED\n{} WERE BAD'.format(imported, were_bad))
Exemplo n.º 14
0
def import_photos_in_place(library_path):
    orig = library_path.path
    imported = 0
    were_bad = 0

    for r, d, f in os.walk(orig):
        for fn in sorted(f):
            filepath = os.path.join(r, fn)
            if blacklisted_type(fn):
                # Blacklisted type
                were_bad += 1
            else:
                modified = record_photo(filepath, library_path.library)
                if modified:
                    imported += 1
                    print('IMPORTED  {}'.format(filepath))

    if imported:
        print('\n{} PHOTOS IMPORTED\n{} WERE BAD'.format(imported, were_bad))
Exemplo n.º 15
0
 def record_photo_async(photo_path, library_id, event_mask):
     record_photo(photo_path, library_id, event_mask)
Exemplo n.º 16
0
def photo_fixture_snow(db):
    from photonix.photos.utils.db import record_photo
    snow_path = str(Path(__file__).parent / 'photos' / 'snow.jpg')
    return record_photo(snow_path)
def photo_fixture_tree(db):
    from photonix.photos.utils.db import record_photo
    tree_path = str(Path(__file__).parent / 'photos' / 'tree.jpg')
    library = LibraryFactory()
    return record_photo(tree_path, library)