Browse Source

Estrutura dump de docs como script

pull/1634/head
Marcio Mazza 7 years ago
parent
commit
82de14e686
  1. 32
      sapl/legacy/scripts/exporta_zope/exporta_zope.py

32
sapl/legacy/scripts/exporta_zope/exporta_zope.py

@ -1,3 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# IMPORTANTE: # IMPORTANTE:
@ -5,9 +6,11 @@
# e depende apenas do descrito no arquivo requiments.txt # e depende apenas do descrito no arquivo requiments.txt
import os.path import os.path
import sys
from collections import defaultdict from collections import defaultdict
from functools import partial from functools import partial
import yaml
import ZODB.DB import ZODB.DB
import ZODB.FileStorage import ZODB.FileStorage
from ZODB.broken import Broken from ZODB.broken import Broken
@ -64,7 +67,6 @@ def dump_file(doc, path):
return name return name
nao_identificados = defaultdict(list)
def enumerate_folder(folder): def enumerate_folder(folder):
@ -85,6 +87,9 @@ def enumerate_btree(folder):
assert contagem_esperada == contagem_real assert contagem_esperada == contagem_real
nao_identificados = defaultdict(list)
def dump_folder(folder, path='', enum=enumerate_folder): def dump_folder(folder, path='', enum=enumerate_folder):
name = folder['id'] name = folder['id']
path = os.path.join(path, name) path = os.path.join(path, name)
@ -135,6 +140,16 @@ def find_sapl(app):
return sapl 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): def dump_sapl(data_fs_path):
app, close_db = get_app(data_fs_path) app, close_db = get_app(data_fs_path)
try: try:
@ -143,6 +158,7 @@ def dump_sapl(data_fs_path):
nao_identificados.clear() nao_identificados.clear()
dump_folder(docs) dump_folder(docs)
dump_propriedades(docs)
if nao_identificados: if nao_identificados:
print('#' * 80) print('#' * 80)
print('#' * 80) print('#' * 80)
@ -155,11 +171,9 @@ def dump_sapl(data_fs_path):
close_db() close_db()
def dump_propriedades(docs): if __name__ == "__main__":
props_sapl = br(docs['props_sapl']) if len(sys.argv) == 2:
ids = [p['id'] for p in props_sapl['_properties']] data_fs_path = sys.argv[1]
props = {id: props_sapl[id] for id in ids} dump_sapl(data_fs_path)
props = {id: p.decode('iso-8859-1') if isinstance(p, str) else p else:
for id, p in props.items()} print('Uso: python exporta_zope <caminho p Data.fs>')
with open('sapl_documentos/propriedades.yaml', 'w') as f:
f.write(yaml.safe_dump(props))

Loading…
Cancel
Save