From 82de14e686df5ed8078aaa05de939cd7e62f39ea Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Tue, 14 Nov 2017 11:36:11 -0200 Subject: [PATCH] Estrutura dump de docs como script --- .../scripts/exporta_zope/exporta_zope.py | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) mode change 100644 => 100755 sapl/legacy/scripts/exporta_zope/exporta_zope.py diff --git a/sapl/legacy/scripts/exporta_zope/exporta_zope.py b/sapl/legacy/scripts/exporta_zope/exporta_zope.py old mode 100644 new mode 100755 index 9d43ce4f2..2ac6eaad2 --- a/sapl/legacy/scripts/exporta_zope/exporta_zope.py +++ b/sapl/legacy/scripts/exporta_zope/exporta_zope.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python # -*- coding: utf-8 -*- # IMPORTANTE: @@ -5,9 +6,11 @@ # e depende apenas do descrito no arquivo requiments.txt import os.path +import sys from collections import defaultdict from functools import partial +import yaml import ZODB.DB import ZODB.FileStorage from ZODB.broken import Broken @@ -64,7 +67,6 @@ def dump_file(doc, path): return name -nao_identificados = defaultdict(list) def enumerate_folder(folder): @@ -85,6 +87,9 @@ def enumerate_btree(folder): assert contagem_esperada == contagem_real +nao_identificados = defaultdict(list) + + def dump_folder(folder, path='', enum=enumerate_folder): name = folder['id'] path = os.path.join(path, name) @@ -135,6 +140,16 @@ def find_sapl(app): return sapl +def dump_propriedades(docs): + props_sapl = br(docs['props_sapl']) + ids = [p['id'] for p in props_sapl['_properties']] + props = {id: props_sapl[id] for id in ids} + props = {id: p.decode('iso-8859-1') if isinstance(p, str) else p + for id, p in props.items()} + with open('sapl_documentos/propriedades.yaml', 'w') as f: + f.write(yaml.safe_dump(props)) + + def dump_sapl(data_fs_path): app, close_db = get_app(data_fs_path) try: @@ -143,6 +158,7 @@ def dump_sapl(data_fs_path): nao_identificados.clear() dump_folder(docs) + dump_propriedades(docs) if nao_identificados: print('#' * 80) print('#' * 80) @@ -155,11 +171,9 @@ def dump_sapl(data_fs_path): close_db() -def dump_propriedades(docs): - props_sapl = br(docs['props_sapl']) - ids = [p['id'] for p in props_sapl['_properties']] - props = {id: props_sapl[id] for id in ids} - props = {id: p.decode('iso-8859-1') if isinstance(p, str) else p - for id, p in props.items()} - with open('sapl_documentos/propriedades.yaml', 'w') as f: - f.write(yaml.safe_dump(props)) +if __name__ == "__main__": + if len(sys.argv) == 2: + data_fs_path = sys.argv[1] + dump_sapl(data_fs_path) + else: + print('Uso: python exporta_zope ')