Пример #1
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)
Пример #2
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))
Пример #3
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)
Пример #4
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)
Пример #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
        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)