From ebac10bdfbb0e1fdb6eb5f5097436b8875de042a Mon Sep 17 00:00:00 2001 From: Jonas Winkler Date: Tue, 3 Nov 2020 14:10:53 +0100 Subject: [PATCH] added migration step to create initial classifier, silences consumption warnings --- .../migrations/1000_update_paperless.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/documents/migrations/1000_update_paperless.py b/src/documents/migrations/1000_update_paperless.py index 9a6ccd077..900510c72 100644 --- a/src/documents/migrations/1000_update_paperless.py +++ b/src/documents/migrations/1000_update_paperless.py @@ -41,6 +41,21 @@ def restore_filenames(apps, schema_editor): pass +def initialize_document_classifier(apps, schema_editor): + try: + print("Initalizing document classifier...") + from documents.classifier import DocumentClassifier + classifier = DocumentClassifier() + try: + classifier.train() + classifier.save_classifier() + except Exception as e: + print("Classifier error: {}".format(e)) + except ImportError: + print("Document classifier not found, skipping") + + + class Migration(migrations.Migration): dependencies = [ @@ -50,6 +65,7 @@ class Migration(migrations.Migration): operations = [ migrations.RunPython(make_index, migrations.RunPython.noop), migrations.RunPython(restore_filenames), + migrations.RunPython(initialize_document_classifier, migrations.RunPython.noop), migrations.RemoveField( model_name='document', name='filename',