コード例 #1
0
ファイル: save_crops.py プロジェクト: edwbaker/inselect
def save_crops(dir, overwrite_existing, template):
    dir = Path(dir)
    export = DocumentExport(UserTemplate.load(template) if template else DWC)
    for p in dir.glob('*' + InselectDocument.EXTENSION):
        try:
            debug_print('Loading [{0}]'.format(p))
            doc = InselectDocument.load(p)
            validation = export.validation_problems(doc)
            if validation.any_problems:
                print(
                    u'Not saving crops for [{0}] because there are validation '
                    u'problems'.format(p)
                )
                for msg in format_validation_problems(validation):
                    print(msg)
            elif not overwrite_existing and doc.crops_dir.is_dir():
                print(u'Crops dir [{0}] exists - skipping'.format(doc.crops_dir))
            else:
                print(u'Will save crops for [{0}] to [{1}]'.format(p, doc.crops_dir))

                debug_print(u'Loading full-resolution scanned image')
                doc.scanned.array

                debug_print(u'Saving crops')
                export.save_crops(doc)
        except Exception:
            print(u'Error saving crops from [{0}]'.format(p))
            traceback.print_exc()
コード例 #2
0
def export_csv(dir, overwrite_existing, template):
    dir = Path(dir)
    export = DocumentExport(UserTemplate.load(template) if template else DWC)
    for p in dir.glob('*' + InselectDocument.EXTENSION):
        try:
            debug_print('Loading [{0}]'.format(p))
            doc = InselectDocument.load(p)
            validation = export.validation_problems(doc)
            csv_path = export.csv_path(doc)
            if validation.any_problems:
                print(
                    'Not exporting metadata for [{0}] because there are '
                    'validation problems'.format(p)
                )
                for msg in format_validation_problems(validation):
                    print(msg)
            elif not overwrite_existing and csv_path.is_file():
                print('CSV file [{0}] exists - skipping'.format(csv_path))
            else:
                print('Writing CSV for [{0}]'.format(p))
                export.export_csv(doc)
        except KeyboardInterrupt:
            raise
        except Exception:
            print('Error saving CSV from [{0}]'.format(p))
            traceback.print_exc()
コード例 #3
0
def save_crops(dir, overwrite_existing, template):
    dir = Path(dir)
    export = DocumentExport(UserTemplate.load(template) if template else DWC)
    for p in dir.glob('*' + InselectDocument.EXTENSION):
        try:
            debug_print('Loading [{0}]'.format(p))
            doc = InselectDocument.load(p)
            validation = export.validation_problems(doc)
            if validation.any_problems:
                print(
                    'Not saving crops for [{0}] because there are validation '
                    'problems'.format(p)
                )
                for msg in format_validation_problems(validation):
                    print(msg)
            elif not overwrite_existing and doc.crops_dir.is_dir():
                print('Crops dir [{0}] exists - skipping'.format(doc.crops_dir))
            else:
                print('Will save crops for [{0}] to [{1}]'.format(p, doc.crops_dir))

                debug_print('Loading full-resolution scanned image')
                doc.scanned.array

                debug_print('Saving crops')
                export.save_crops(doc)
        except KeyboardInterrupt:
            raise
        except Exception:
            print('Error saving crops from [{0}]'.format(p))
            traceback.print_exc()