Skip to content

Commit 4e647b3

Browse files
Script para criação/atualização de bindings XSD (#404)
1 parent 81c9667 commit 4e647b3

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ Lint
167167
* Formatar: `ruff format .`
168168

169169

170+
Bindings XSD
171+
-----------
172+
173+
Para atualizar os bindings XSD da NFSe, execute o script `gerarnfsebindings.sh`.
174+
175+
170176
Documentação
171177
-----------
172178
- https://github.com/TadaSoftware/PyNFe/wiki

gerarnfsebindings.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/sh
2+
3+
xsd_path="pynfe/data/XSDs/"
4+
bindings_root_path="pynfe/utils/"
5+
6+
main() {
7+
# NFSe
8+
main_xsd_nfse_path="${xsd_path}NFS-e/"
9+
main_bindings_root_nfse_path="${bindings_root_path}nfse/"
10+
11+
gera_bindings_diretorio "${main_xsd_nfse_path}Betha/" "${main_bindings_root_nfse_path}betha/"
12+
ajustes_betha "${main_bindings_root_nfse_path}betha/"
13+
14+
gera_bindings_diretorio "${main_xsd_nfse_path}Ginfes/" "${main_bindings_root_nfse_path}ginfes/"
15+
ajustes_ginfes "${main_bindings_root_nfse_path}ginfes/"
16+
}
17+
18+
gera_binding() {
19+
gb_xsd_nfse_path="$1"
20+
gb_module="$2"
21+
gb_bindings_root_nfse_path="$3"
22+
23+
pyxbgen \
24+
--schema-location=$gb_xsd_nfse_path \
25+
--module=$gb_module \
26+
--binding-root=$gb_bindings_root_nfse_path
27+
}
28+
29+
gera_bindings_diretorio() {
30+
gbd_xsd_nfse_path="$1"
31+
gbd_bindings_root_nfse_path="$2"
32+
33+
for file in $gbd_xsd_nfse_path*.xsd; do
34+
if [ -f $file ]; then
35+
filename="${file##*/}" # retorna apenas o nome do arquivo, sem o caminho - Ex: schema.xsd
36+
basename="${filename%.*}" # remove a extensão - Ex: schema
37+
38+
echo "Gerando: $basename"
39+
gera_binding "$gbd_xsd_nfse_path${basename}.xsd" $basename $gbd_bindings_root_nfse_path
40+
fi
41+
done
42+
43+
ignorar_lint $gbd_bindings_root_nfse_path
44+
}
45+
46+
ignorar_lint() {
47+
bindings_root_nfse_path="$1"
48+
49+
for file in $bindings_root_nfse_path*.py; do
50+
filename="${file##*/}" # retorna apenas o nome do arquivo, sem o caminho - Ex: schema.xsd
51+
if [ -f $file ] && [ $filename != "__init__.py" ]; then
52+
sed -i '1i# flake8: noqa' $file
53+
fi
54+
done
55+
}
56+
57+
ajustes_betha() {
58+
bindings_root_nfse_path="$1"
59+
60+
rm "${bindings_root_nfse_path}xmldsig_core_schema20020212.py"
61+
62+
for file in $bindings_root_nfse_path*.py; do
63+
filename="${file##*/}" # retorna apenas o nome do arquivo, sem o caminho - Ex: schema.xsd
64+
if [ -f $file ] && [ $filename != "__init__.py" ]; then
65+
sed -i 's/import _dsig/from pynfe.utils.nfse.betha import _dsig/g' $file
66+
fi
67+
done
68+
}
69+
70+
ajustes_ginfes() {
71+
bindings_root_nfse_path="$1"
72+
73+
rm "${bindings_root_nfse_path}tipos_v03.py"
74+
rm "${bindings_root_nfse_path}xmldsig_core_schema20020212_v03.py"
75+
76+
for file in $bindings_root_nfse_path*.py; do
77+
filename="${file##*/}" # retorna apenas o nome do arquivo, sem o caminho - Ex: schema.xsd
78+
if [ -f $file ] && [ $filename != "__init__.py" ]; then
79+
sed -i 's/import _dsig/from pynfe.utils.nfse.ginfes import _dsig/g' $file
80+
sed -i 's/import _tipos/from pynfe.utils.nfse.ginfes import _tipos/g' $file
81+
fi
82+
done
83+
}
84+
85+
main

0 commit comments

Comments
 (0)