python-oracle-apex 0.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,295 @@
1
+ from pathlib import Path
2
+
3
+
4
+ class ApexGroup():
5
+ def __init__(self, initial_data={}):
6
+ self.properties = {}
7
+ self.properties.update(initial_data)
8
+
9
+ def __setitem__(self, key, value):
10
+ self.properties[key] = value
11
+
12
+ def __getitem__(self, key):
13
+ return self.properties.get(key, None)
14
+
15
+ def get(self, key, default=None):
16
+ return self.properties.get(key, default)
17
+
18
+
19
+ class ApexObject():
20
+ def __init__(self, component_id=None, initial_data={}):
21
+ self.component_id = component_id
22
+ self.properties = {}
23
+ self.properties.update(initial_data)
24
+ self.groups = {}
25
+ self.children = []
26
+
27
+ def __setitem__(self, key, value):
28
+ if isinstance(value, ApexGroup):
29
+ self.groups[key] = value
30
+ elif isinstance(value, ApexObject):
31
+ self.children[key] = value
32
+ else:
33
+ self.properties[key] = value
34
+
35
+ def __getitem__(self, key):
36
+ if key in self.groups:
37
+ return self.groups.get(key, None)
38
+ elif key in self.children:
39
+ return self.children.get(key, None)
40
+ else:
41
+ return self.properties.get(key, None)
42
+
43
+ def add_property(self, key, value):
44
+ self.properties[key] = value
45
+
46
+ def add_group(self, key, value):
47
+ self.groups[key] = value
48
+
49
+ def add_child(self, child):
50
+ self.children.append(child)
51
+
52
+
53
+ class RegionLayout(ApexGroup):
54
+ def __init__(self, initial_data={}):
55
+ super().__init__(initial_data)
56
+
57
+ @property
58
+ def sequence(self):
59
+ return self.properties.get('sequence', None)
60
+
61
+ @property
62
+ def parentRegion(self):
63
+ return self.properties.get('parentRegion', None)
64
+
65
+ class RegionAppearance(ApexGroup):
66
+ def __init__(self, initial_data={}):
67
+ super().__init__(initial_data)
68
+
69
+
70
+
71
+ class Region(ApexObject):
72
+ def __init__(self, component_id=None, initial_data={}):
73
+ super().__init__(component_id, initial_data)
74
+
75
+ @property
76
+ def name(self):
77
+ return self.properties.get('name', None)
78
+
79
+ @property
80
+ def title(self):
81
+ return self.properties.get('title', None)
82
+
83
+ @property
84
+ def type(self):
85
+ return self.properties.get('type', None)
86
+
87
+ @property
88
+ def layout(self):
89
+ return self.groups.get('layout', RegionLayout())
90
+
91
+ @property
92
+ def appearance(self):
93
+ return self.groups.get('appearance', RegionAppearance())
94
+
95
+
96
+ class PageItemLabel(ApexGroup):
97
+ def __init__(self, initial_data={}):
98
+ super().__init__(initial_data)
99
+
100
+ @property
101
+ def label(self):
102
+ return self.properties.get('label', None)
103
+
104
+
105
+ class PageItemSettings(ApexGroup):
106
+ def __init__(self, initial_data={}):
107
+ super().__init__(initial_data)
108
+
109
+
110
+ class PageItemLayout(ApexGroup):
111
+ def __init__(self, initial_data={}):
112
+ super().__init__(initial_data)
113
+
114
+ @property
115
+ def sequence(self):
116
+ return self.properties.get('sequence', None)
117
+
118
+ @property
119
+ def region(self):
120
+ return self.properties.get('region', None)
121
+
122
+
123
+ class PageItemAppearance(ApexGroup):
124
+ def __init__(self, initial_data={}):
125
+ super().__init__(initial_data)
126
+
127
+ class PageItemValidation(ApexGroup):
128
+ def __init__(self, initial_data={}):
129
+ super().__init__(initial_data)
130
+
131
+ class PageItemAdvanced(ApexGroup):
132
+ def __init__(self, initial_data={}):
133
+ super().__init__(initial_data)
134
+
135
+ class PageItemSessionState(ApexGroup):
136
+ def __init__(self, initial_data={}):
137
+ super().__init__(initial_data)
138
+
139
+ class PageItemSecurity(ApexGroup):
140
+ def __init__(self, initial_data={}):
141
+ super().__init__(initial_data)
142
+
143
+
144
+ class PageItem(ApexObject):
145
+ def __init__(self, component_id=None, initial_data={}):
146
+ super().__init__(component_id, initial_data)
147
+
148
+ @property
149
+ def name(self):
150
+ return self.properties.get('name', self.component_id)
151
+
152
+ @property
153
+ def type(self):
154
+ return self.properties.get('type', None)
155
+
156
+
157
+ @property
158
+ def layout(self):
159
+ return self.groups.get('layout', PageItemLayout())
160
+
161
+ @property
162
+ def label(self):
163
+ return self.groups.get('label', PageItemLabel())
164
+
165
+
166
+ class ButtonLayout(ApexGroup):
167
+ def __init__(self, initial_data={}):
168
+ super().__init__(initial_data)
169
+
170
+ @property
171
+ def sequence(self):
172
+ return self.properties.get('sequence', None)
173
+
174
+ @property
175
+ def region(self):
176
+ return self.properties.get('region', None)
177
+
178
+
179
+ class ButtonAppearance(ApexGroup):
180
+ def __init__(self, initial_data={}):
181
+ super().__init__(initial_data)
182
+
183
+ class ButtonBehavior(ApexGroup):
184
+ def __init__(self, initial_data={}):
185
+ super().__init__(initial_data)
186
+
187
+
188
+
189
+ class Button(ApexObject):
190
+ def __init__(self, component_id=None, initial_data={}):
191
+ super().__init__(component_id, initial_data)
192
+
193
+ @property
194
+ def button_name(self):
195
+ return self.properties.get('buttonName', None)
196
+
197
+ @property
198
+ def label(self):
199
+ return self.properties.get('label', None)
200
+
201
+ @property
202
+ def layout(self):
203
+ return self.groups.get('layout', ButtonLayout({}))
204
+
205
+
206
+ class DynamicActionExecution(ApexGroup):
207
+ pass
208
+
209
+ class DynamicActionWhen(ApexGroup):
210
+ pass
211
+
212
+ class DynamicActionClientSideCondition(ApexGroup):
213
+ pass
214
+
215
+ class DynamicAction(ApexObject):
216
+ def __init__(self, component_id=None, initial_data={}):
217
+ super().__init__(component_id, initial_data)
218
+
219
+
220
+ class ActionAffectedElements(ApexGroup):
221
+ pass
222
+
223
+ class ActionExecution(ApexGroup):
224
+ pass
225
+
226
+
227
+ class Action(ApexObject):
228
+ pass
229
+
230
+ class Process(ApexObject):
231
+ def __init__(self, component_id=None, initial_data={}):
232
+ super().__init__(component_id, initial_data)
233
+
234
+
235
+ class Page(ApexObject):
236
+ def __init__(self, component_id=None, initial_data={}):
237
+ super().__init__(component_id, initial_data)
238
+
239
+ def __str__(self):
240
+ return f"Page<#{self.page} name: {self.name}>"
241
+
242
+ @property
243
+ def page(self):
244
+ return self.properties.get('page', self.component_id)
245
+
246
+ @property
247
+ def name(self):
248
+ return self.properties.get('name', "<NONAME>")
249
+
250
+ @property
251
+ def title(self):
252
+ return self.properties['title']
253
+
254
+ @property
255
+ def alias(self):
256
+ return self.properties['alias']
257
+
258
+
259
+ @property
260
+ def appearance(self):
261
+ return self.groups.get('appearance', None)
262
+
263
+ @appearance.setter
264
+ def appearance(self, value):
265
+ self.groups['appearance'] = value
266
+
267
+ @property
268
+ def regions(self):
269
+ return [x for x in self.children if isinstance(x, Region)]
270
+
271
+ @property
272
+ def page_items(self):
273
+ return [x for x in self.children if isinstance(x, PageItem)]
274
+
275
+ @property
276
+ def buttons(self):
277
+ return [x for x in self.children if isinstance(x, Button)]
278
+
279
+ @property
280
+ def dynamic_actions(self):
281
+ return [x for x in self.children if isinstance(x, DynamicAction)]
282
+
283
+ @property
284
+ def processes(self):
285
+ return [x for x in self.children if isinstance(x, Process)]
286
+
287
+
288
+ def get_region(self, reference_or_name):
289
+ regions = [x for x in self.regions if x.component_id==reference_or_name[1:] or x.name==reference_or_name]
290
+ if len(regions) == 1:
291
+ return regions[0]
292
+ elif len(regions) == 0:
293
+ return None
294
+
295
+ return regions
@@ -0,0 +1,189 @@
1
+ from pathlib import Path
2
+ from python_oracle_apex.objects import *
3
+ import yaml
4
+
5
+ """
6
+ Read YAML and transform to Page object.
7
+
8
+ Property names will be translated to the names used in de APEX Lang spec. (version 26.1)
9
+ """
10
+
11
+ def make_properties(mapper, data, section, object: ApexObject):
12
+ for field_src, field_dest in mapper.items():
13
+ if field_src in data[section]:
14
+ object.add_property(field_dest, data[section][field_src])
15
+
16
+ def make_group(mapper, data):
17
+ d = {}
18
+ for k, v in data.items():
19
+ if k in mapper:
20
+ d[mapper[k]] = v
21
+ else:
22
+ raise AttributeError(f"Unknown property '{k}'")
23
+ return d
24
+
25
+
26
+ def make_region_layout(data):
27
+ f = {
28
+ 'sequence': 'sequence',
29
+ 'parent-region': 'parentRegion',
30
+ 'slot': 'slot',
31
+ 'start-new-layout': 'startNewLayout',
32
+ 'start-new-row': 'startNewRow',
33
+ 'column': 'column',
34
+ 'new-column': 'newColumn',
35
+ 'column-span': 'columnSpan'
36
+ }
37
+ d = make_group(f, data)
38
+ return RegionLayout(d)
39
+
40
+
41
+
42
+ def make_region_appearance(data):
43
+ f = {
44
+ 'icon': 'icon',
45
+ 'template': 'template',
46
+ 'template-options': 'templateOptions',
47
+ 'render-components': 'renderComponents',
48
+ 'css-classes': 'cssClasses',
49
+ }
50
+ d = make_group(f, data)
51
+ return RegionAppearance(d)
52
+
53
+
54
+ def make_region(region):
55
+ r = Region(region['id'])
56
+ make_properties({
57
+ 'name': 'name',
58
+ 'title': 'title',
59
+ 'type': 'type'
60
+ },
61
+ region, 'identification', r
62
+ )
63
+
64
+ if 'layout' in region:
65
+ l = make_region_layout(region['layout'])
66
+ r.add_group('layout', l)
67
+
68
+ if 'appearance' in region:
69
+ a = make_region_appearance(region['appearance'])
70
+ r.add_group('appearance', a)
71
+ return r
72
+
73
+
74
+ def make_page_item_label(data):
75
+ f = {
76
+ 'label': 'label',
77
+ 'alignment': 'alignment',
78
+ }
79
+ d = make_group(f, data)
80
+ return PageItemLabel(d)
81
+
82
+ def make_page_item_layout(data):
83
+ f = {
84
+ 'sequence': 'sequence',
85
+ 'region': 'region',
86
+ 'alignment': 'alignment',
87
+ 'slot': 'slot',
88
+ 'start-new-layout': 'startNewLayout',
89
+ 'start-new-row': 'startNewRow',
90
+ 'column': 'column',
91
+ 'new-column': 'newColumn',
92
+ 'column-span': 'columnSpan',
93
+ 'label-column-span': 'labelColumnSpan',
94
+ }
95
+ d = make_group(f, data)
96
+ return PageItemLayout(d)
97
+
98
+ def make_page_item_appearance(data):
99
+ return {}
100
+
101
+
102
+ def make_page_item(page_item):
103
+ p = PageItem(page_item['id'])
104
+ make_properties({
105
+ 'name': 'name',
106
+ 'type': 'type'
107
+ },
108
+ page_item, 'identification', p
109
+ )
110
+
111
+ if 'label' in page_item:
112
+ l = make_page_item_label(page_item['label'])
113
+ p.add_group('label', l)
114
+
115
+ if 'layout' in page_item:
116
+ l = make_page_item_layout(page_item['layout'])
117
+ p.add_group('layout', l)
118
+
119
+ if 'appearance' in page_item:
120
+ a = make_page_item_appearance(page_item['appearance'])
121
+ p.add_group('appearance', a)
122
+ return p
123
+
124
+
125
+ def make_button_layout(data):
126
+ f = {
127
+ 'sequence': 'sequence',
128
+ 'region': 'region',
129
+ 'slot': 'slot',
130
+ 'column': 'column',
131
+ 'alignment': 'alignment',
132
+ 'new-column': 'newColumn',
133
+ 'column-span': 'columnSpan',
134
+ 'start-new-layout': 'startNewLayout',
135
+ 'start-new-row': 'startNewRow',
136
+
137
+ }
138
+ d = make_group(f, data)
139
+ return ButtonLayout(d)
140
+
141
+ def make_button(data):
142
+ b = Button(data['id'])
143
+ make_properties({
144
+ 'button-name': 'buttonName',
145
+ 'label': 'label'
146
+ }, data, 'identification', b)
147
+
148
+ if 'layout' in data:
149
+ l = make_button_layout(data['layout'])
150
+ b.add_group('layout', l)
151
+
152
+ return b
153
+
154
+
155
+ def parse_yaml_file(fn: Path) -> Page:
156
+
157
+ with open(fn, 'r') as f:
158
+ data = yaml.safe_load(f)
159
+
160
+
161
+
162
+ page = Page(data['id'])
163
+ for field in ['name', 'alias', 'title']:
164
+ if field in data['identification']:
165
+ page.add_property(field, data['identification'][field])
166
+
167
+ for region in data['regions']:
168
+ r = make_region(region)
169
+ page.add_child(r)
170
+
171
+ for page_item in data['page-items']:
172
+ p = make_page_item(page_item)
173
+ page.add_child(p)
174
+
175
+ for button in data['buttons']:
176
+ b = make_button(button)
177
+ page.add_child(b)
178
+
179
+ return page
180
+
181
+
182
+ if __name__ == '__main__': # pragma: no cover
183
+
184
+ page = parse_yaml_file("examples/f300_page_9999.yaml")
185
+
186
+ for r in page.regions:
187
+ print(r.component_id, r.name, r.type)
188
+
189
+ print(page)
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.3
2
+ Name: python-oracle-apex
3
+ Version: 0.0.0
4
+ Summary: Parsing files exported from Oracle APEX
5
+ Author: Maurice Koster
6
+ Author-email: Maurice Koster <maurice@mauricekoster.com>
7
+ Requires-Dist: parsimonious>=0.11.0
8
+ Requires-Dist: pyyaml>=6.0.3
9
+ Requires-Python: >=3.13
10
+ Description-Content-Type: text/markdown
11
+
12
+ # python-oracle-apex
13
+ Parsing an APEX lang export file into Objects
14
+
15
+ ## Oracle APEX
16
+
17
+ ## APEXLang - reading .apx files
18
+
19
+ ```python
20
+ page = parse_apex("examples/login.apx")
21
+ ```
22
+
23
+ ## Reading yaml files, pre APEX 26.1
24
+
25
+ ```python
26
+ page = parse_yaml("examples/login.yaml")
27
+ ```
@@ -0,0 +1,9 @@
1
+ python_oracle_apex/__init__.py,sha256=hEpJLozpFV20dt_RRFi2FTdU4OfAfo2capAj3PG3OiQ,173
2
+ python_oracle_apex/apexlang-26.1.peg,sha256=EpzBYDdKMndrqtIPgeRRl1jXGYY2ojaqs3JZ-mwkriU,27154
3
+ python_oracle_apex/grammar.py,sha256=N6hBdDOn4UNclb1kuEpZqhwact6pArsxeGiNTHwi5xI,32909
4
+ python_oracle_apex/objects.py,sha256=vq5NkBcXv_CuoEceBHdXz9PPgfoqN8Dxw4E7Di9s2sM,7285
5
+ python_oracle_apex/reader.py,sha256=XXOCGylHdu8YxzHd-4J5G__KwTWCCwxG1PYaY-ROwi0,4673
6
+ python_oracle_apex-0.0.0.dist-info/WHEEL,sha256=ZFFp7t7R4RYQ5KYZkmiFWoQvHay7SrTmn-6ZYfoFZ3U,80
7
+ python_oracle_apex-0.0.0.dist-info/entry_points.txt,sha256=4hypeKGZzJvVbIPe-A7DX5T8X1nb_ORdnkz-CwhWRVU,64
8
+ python_oracle_apex-0.0.0.dist-info/METADATA,sha256=y8BJj672MQ2wiZ-NfupikP7Uk1lwujiabHyyaVzm-ms,587
9
+ python_oracle_apex-0.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.12.7
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ python-oracle-apex = python_oracle_apex:main
3
+