forked from radeknovotny94/GRASS_Parse_to_QGIS_UI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GRASSDescribtionParser.py
138 lines (118 loc) · 4.67 KB
/
GRASSDescribtionParser.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from __future__ import print_function
import xml.etree.ElementTree
def print_name_desc(modul):
if child.tag == 'flag':
print('-' + modul.attrib['name'].strip() + '|', end='')
elif child.tag == 'parameter':
print(modul.attrib['name'].strip() + '|', end='')
else:
pass
if modul.find("label") is not None:
print(modul.find("label").text.strip() + '|', end='')
elif modul.find("description") is not None:
print(modul.find("description").text.strip() + '|', end='')
else:
pass
def check_default(parameter):
for par in parameter:
if par.tag == 'default':
return True
def print_default(parameter):
if check_default(parameter):
for par in parameter:
if par.tag == 'default':
print(par.text.strip() + '|', end='')
else:
print('None|', end='')
def print_optional(parameter):
if parameter.attrib['required'] == 'yes':
print('False')
else:
print('True')
tree = xml.etree.ElementTree.parse("v_surf_rst.xml")
root = tree.getroot()
name = root.attrib['name']
print(name)
print(tree.find("description").text.strip())
if name[:5] == 'nviz.': # ????
print('Visualization(NVIZ)') # ????
elif name[:2] == 'r.':
print('Raster (r.*)')
elif name[:2] == 'i.':
print('Imagery (i.*)')
elif name[:2] == 'v.':
print('Vector (v.*)')
elif name[:2] == 'm.':
print('Miscellaneous (m.*)')
else:
print('Not in plugin')
for child in root:
if child.tag == 'parameter':
if child.attrib['multiple'] == 'yes':
print('QgsProcessingParameterMultipleLayers|', end='')
print_name_desc(child)
for k in child:
if k.tag == 'gisprompt':
if k.attrib['prompt'] == 'raster':
print('TypeRaster|', end='')
if k.attrib['prompt'] == 'vector':
print('TypeVector|', end='')
print_default(child)
print_optional(child)
elif child.attrib['multiple'] == 'no':
for k in child:
if k.tag == 'gisprompt':
if k.attrib['age'] == 'old':
if k.attrib['prompt'] == 'raster':
print('QgsProcessingParameterRasterLayer|', end='')
elif k.attrib['prompt'] == 'vector':
print('QgsProcessingParameterVectorLayer|', end='')
elif k.attrib['prompt'] == 'dbcolumn':
print('QgsProcessingParameterField|', end='')
else:
print('Not recognized >>> ', end='')
print_name_desc(child)
elif k.attrib['age'] == 'new':
if k.attrib['prompt'] == 'raster':
print('QgsProcessingParameterRasterDestination|', end='')
print_name_desc(child)
elif k.attrib['prompt'] == 'vector':
print('QgsProcessingParameterVectorDestination|', end='')
print_name_desc(child)
print('TypeVector|', end='')
else:
print('Not recognized >>> ', end='')
print_name_desc(child)
print_default(child)
print_optional(child)
elif child.attrib['type'] == 'string':
promt = child.find('gisprompt')
if promt is None:
print('QgsProcessingParameterString|', end='')
print_name_desc(child)
print_default(child)
print('True|', end='')
print_optional(child)
else:
print('Not recognized >>> ', end='')
print_name_desc(child)
elif child.attrib['type'] == 'integer':
print('QgsProcessingParameterNumber|', end='')
print_name_desc(child)
print('QgsProcessingParameterNumber.Integer|', end='')
print_default(child)
print_optional(child)
elif child.attrib['type'] == 'float':
print('QgsProcessingParameterNumber|', end='')
print_name_desc(child)
print('QgsProcessingParameterNumber.Double|', end='')
print_default(child)
print_optional(child)
else:
print('Not recognized >>> ', end='')
print_name_desc(child)
elif child.tag == 'flag':
print('QgsProcessingParameterBoolean|', end='')
print_name_desc(child)
print_default(child)
print('True')