-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate
executable file
·77 lines (64 loc) · 2.18 KB
/
generate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
# the project file layout is a template clone of http://www.davekuhlman.org/generateDS.html#id14
# for which we run:
git branch -D generated
git checkout -b generated
SCHEMA_NAME='mdfe'
python quick_start.py --schema-name="$SCHEMA_NAME"
generate() {
local version=$1
local schemas_url=$2
local lib_name="$SCHEMA_NAME"lib
local gen_path="$SCHEMA_NAME"lib/"$version"
wget -qO- --no-check-certificate "$schemas_url" -O /tmp/schemas.zip
unzip /tmp/schemas.zip -d schemas/
rm /tmp/schemas.zip
unzip_path=$(ls schemas | head -n1)
rm -rf "schemas/$version"
mv schemas/"$unzip_path" "schemas/$version"
rm -rf __init__.py
local module_contents=$(cat <<EOF
Module contents
=================
EOF
)
echo "$module_contents" > docs/module_contents.txt
echo "sys.path.append(os.path.abspath('../$gen_path'))" >> docs/conf.py
rm -rf $gen_path
mkdir -p $gen_path
touch "$lib_name"/__init__.py
touch "$gen_path/__init__.py"
for f in "schemas/$version"/*.xsd;
do
echo "Processing $f file..";
local name=$(echo "$f" | sed 's/\.xsd//g' | sed 's/\./_/g' | sed "s/_$version//g")
local module_name=$(echo $name | tr "/" "\n" | tail -n1)
# generateDS -o "$gen_path/$module_name".py -s "$gen_path/$module_name"_subs.py "$f"
if [[ "$module_name" == "leiauteNFe" ]]; then
generateDS -o "$gen_path/$module_name".py "$f"
else
# --no-process_includes is said to be a risky option that disable validators, but probably we
# only want them for the NFe layout. Doing this makes the lib much smaller.
generateDS --no-process-includes -o "$gen_path/$module_name".py "$f"
fi
module_name=$(echo $name | tr "/" "\n" | tail -n1)
module_contents_part=$(cat <<EOF
.. automodule:: $module_name
:members:
:undoc-members:
:show-inheritance:
EOF
)
echo "$module_contents_part" >> docs/module_contents.txt
done
}
generate "v3_00" "https://mdfe-portal.sefaz.rs.gov.br/Site/DownloadArquivoNovo/?tipoArquivo=2&nomeArquivo=PL_MDFe_300_NT032017.zip"
cd docs
make html
cd ..
rm -rf README.txt
rm -rf "$SCHEMA_NAME"utils.py
rm -rf sample_code
git add .
git commit . -m "classes and doc generated with ./generate"
git merge packaging