Skip to content
Snippets Groups Projects
Commit 3fde7df0 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Add dry run

parent 501b4d98
No related branches found
No related tags found
1 merge request!22Add score to transcriptions
......@@ -284,6 +284,9 @@ class ManifestsImporter(ABC):
def save_transcriptions(self):
"""To optimize transcription parsing, saving and indexing is done in bulk."""
if len(self.images_transcription_data) < 1:
return
total_zones, total_transcriptions, total_indexes = 0, 0, 0
for (image, page), data in self.images_transcription_data.items():
......
......@@ -18,6 +18,12 @@ class Command(BaseCommand):
help='Folder to recursively search for index files',
default='.'
)
parser.add_argument(
'--dry-run',
help='Only show the associated images found for all index files, without importing anything',
action='store_true',
default=False,
)
def handle(self, *args, **options):
# Handle verbosity level
......@@ -26,4 +32,8 @@ class Command(BaseCommand):
if verbosity > 1:
root_logger.setLevel(logging.DEBUG)
IndexImporter(options['index_folder']).run()
importer = IndexImporter(options['index_folder'])
if options['dry_run']:
importer.dry_run()
else:
importer.run()
......@@ -169,6 +169,25 @@ class IndexImporter(object):
def run(self):
for index_path in self.get_index_paths():
logger.info("Parsing index file {}".format(index_path))
image = self.get_image(index_path)
page = self.get_page(image)
import_indexes(image, page, index_path)
try:
image = self.get_image(index_path)
page = self.get_page(image)
import_indexes(image, page, index_path)
except Image.DoesNotExist:
logger.warning("No associated image found for file {}".format(index_path))
except Page.DoesNotExist:
logger.warning("No associated page found for file {}".format(index_path))
except Image.MultipleObjectsReturned:
logger.warning("Multiple associated images found for file {}".format(index_path))
def dry_run(self):
image = None
for index_path in self.get_index_paths():
try:
image = self.get_image(index_path)
except (Image.DoesNotExist, Image.MultipleObjectsReturned):
pass
if image is None:
print("{}\tFAIL".format(index_path))
else:
print("{}\t{}".format(index_path, image.path))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment