def test_extract_jpg(): for fn, intended_process_params, intended_filesize, urls in PHOTOS: raw_photo_path = str(Path(__file__).parent / 'photos' / fn) if not os.path.exists(raw_photo_path): for url in urls: try: download_file(url, raw_photo_path) if not os.path.exists(raw_photo_path) or os.stat(raw_photo_path).st_size < 1024 * 1024: try: os.remove(raw_photo_path) except: pass else: break except: pass output_path, _, process_params, _ = generate_jpeg(raw_photo_path) assert process_params == intended_process_params assert identified_as_jpeg(output_path) == True filesizes = [intended_filesize, os.stat(output_path).st_size] assert min(filesizes) / max(filesizes) > 0.8 # Within 20% of the intended JPEG filesize os.remove(output_path)
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)
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)
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)
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)
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)