From 925f517d6fb7955338dbd3660cfc15443716aa15 Mon Sep 17 00:00:00 2001 From: Luciano Almeida Date: Mon, 15 May 2017 14:20:38 -0300 Subject: [PATCH 1/4] =?UTF-8?q?Adiciona=20novas=20extens=C3=B5es=20e=20arr?= =?UTF-8?q?uma=20assert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luciano Almeida --- sapl/legacy/migracao_documentos.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/sapl/legacy/migracao_documentos.py b/sapl/legacy/migracao_documentos.py index 21697dc4f..5320e6774 100644 --- a/sapl/legacy/migracao_documentos.py +++ b/sapl/legacy/migracao_documentos.py @@ -29,6 +29,17 @@ EXTENSOES = { 'text/html': '.html', 'text/rtf': '.rtf', 'text/x-python': '.py', + 'text/plain': '.ksh', + 'text/plain': '.c', + 'text/plain': '.h', + 'text/plain': '.txt', + 'text/plain': '.bat', + 'text/plain': '.pl', + 'text/plain': '.asc', + 'text/plain': '.text', + 'text/plain': '.pot', + 'text/plain': '.brf', + 'text/plain': '.srt', # sem extensao 'application/octet-stream': '', # binário @@ -105,9 +116,14 @@ def migrar_docs_logo(): print('#### Migrando logotipo da casa ####') [(_, origem, destino)] = DOCS[CasaLegislativa] props_sapl = os.path.dirname(origem) + # a pasta props_sapl deve conter apenas o origem e metadatas! + # Edit: Aparentemente há diretório que contém properties ao invés de + # metadata. O assert foi modificado para essa situação. assert set(os.listdir(em_media(props_sapl))) < { - 'logo_casa.gif', '.metadata', 'logo_casa.gif.metadata'} + 'logo_casa.gif', '.metadata', 'logo_casa.gif.metadata', + '.properties', 'logo_casa.gif.properties', '.objects'} + mover_documento(origem, destino) casa = get_casa_legislativa() casa.logotipo = destino From ec4fb23a6657e190e52ca473568536bda963cfff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rog=C3=A9rio=20Fr=C3=A1?= Date: Tue, 16 May 2017 09:38:09 -0300 Subject: [PATCH 2/4] ajusta nome colunas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adiciona migração de DocumentosAcessoriosAdministrativos Ajusta nome das colunas da base --- sapl/legacy/migracao_documentos.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sapl/legacy/migracao_documentos.py b/sapl/legacy/migracao_documentos.py index 5320e6774..a8ffa52b5 100644 --- a/sapl/legacy/migracao_documentos.py +++ b/sapl/legacy/migracao_documentos.py @@ -11,6 +11,7 @@ from sapl.materia.models import (DocumentoAcessorio, MateriaLegislativa, from sapl.norma.models import NormaJuridica from sapl.parlamentares.models import Parlamentar from sapl.protocoloadm.models import DocumentoAdministrativo +from sapl.protocoloadm.models import DocumentoAcessorioAdministrativo from sapl.sessao.models import SessaoPlenaria from sapl.settings import MEDIA_ROOT from sapl.utils import delete_texto, save_texto @@ -64,7 +65,7 @@ DOCS = { 'materia/{}', 'documentoacessorio/{0}/{0}{1}')], NormaJuridica: [( - 'texto_original', + 'texto_integral', 'norma_juridica/{}_texto_integral', 'normajuridica/{0}/{0}_texto_integral{1}')], SessaoPlenaria: [ @@ -82,7 +83,13 @@ DOCS = { DocumentoAdministrativo: [( 'texto_integral', 'administrativo/{}_texto_integral', - 'documentoadministrativo/{0}/{0}_texto_integral{1}')], + 'documentoadministrativo/{0}/{0}_texto_integral{1}') + ], + DocumentoAcessorioAdministrativo: [( + 'arquivo', + 'administrativo/{}', + 'documentoadministrativo/{0}/{0}_acessorio_administrativo{1}') + ], } DOCS = {tipo: [(campo, @@ -215,6 +222,7 @@ def migrar_documentos(): SessaoPlenaria, Proposicao, DocumentoAdministrativo, + DocumentoAcessorioAdministrativo, ]: migrar_docs_por_ids(tipo) From f66ff5965b3e472b9513e59bdf47f97ea02e1525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rog=C3=A9rio=20Fr=C3=A1?= Date: Wed, 17 May 2017 11:10:22 -0300 Subject: [PATCH 3/4] ajusta caminho DocumentoAcessorioAdministrativo --- sapl/legacy/migracao_documentos.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sapl/legacy/migracao_documentos.py b/sapl/legacy/migracao_documentos.py index a8ffa52b5..7e6182222 100644 --- a/sapl/legacy/migracao_documentos.py +++ b/sapl/legacy/migracao_documentos.py @@ -86,9 +86,9 @@ DOCS = { 'documentoadministrativo/{0}/{0}_texto_integral{1}') ], DocumentoAcessorioAdministrativo: [( - 'arquivo', + 'arquivo', 'administrativo/{}', - 'documentoadministrativo/{0}/{0}_acessorio_administrativo{1}') + 'documentoacessorioadministrativo/{0}/{0}_acessorio_administrativo{1}') ], } From dafc5132365a18408b81d6603533b1671fba8825 Mon Sep 17 00:00:00 2001 From: Luciano Almeida Date: Wed, 17 May 2017 11:44:46 -0300 Subject: [PATCH 4/4] =?UTF-8?q?Adiciona=20exception=20para=20extens=C3=A3o?= =?UTF-8?q?=20n=C3=A3o=20suportada?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luciano Almeida --- sapl/base/search_indexes.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sapl/base/search_indexes.py b/sapl/base/search_indexes.py index c85be523b..e41dac3bf 100644 --- a/sapl/base/search_indexes.py +++ b/sapl/base/search_indexes.py @@ -7,6 +7,8 @@ from haystack import indexes from sapl.materia.models import DocumentoAcessorio, MateriaLegislativa from sapl.norma.models import NormaJuridica +from textract.exceptions import ExtensionNotSupported + class DocumentoAcessorioIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) @@ -32,15 +34,19 @@ class DocumentoAcessorioIndex(indexes.SearchIndex, indexes.Indexable): if arquivo: try: arquivo.open() + arquivo.close() except OSError: return self.prepared_data if not os.path.splitext(arquivo.path)[1][:1]: return self.prepared_data - extracted_data = textract.process( - arquivo.path).decode( - 'utf-8').replace('\n', ' ') + try: + extracted_data = textract.process( + arquivo.path).decode( + 'utf-8').replace('\n', ' ') + except ExtensionNotSupported: + return self.prepared_data extracted_data = extracted_data.replace('\t', ' ')