MapleX 2.0.0__tar.gz
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.
- maplex-2.0.0/LICENSE +21 -0
- maplex-2.0.0/PKG-INFO +425 -0
- maplex-2.0.0/README.md +408 -0
- maplex-2.0.0/pyproject.toml +26 -0
- maplex-2.0.0/setup.cfg +4 -0
- maplex-2.0.0/setup.py +17 -0
- maplex-2.0.0/src/MapleX.egg-info/PKG-INFO +425 -0
- maplex-2.0.0/src/MapleX.egg-info/SOURCES.txt +15 -0
- maplex-2.0.0/src/MapleX.egg-info/dependency_links.txt +1 -0
- maplex-2.0.0/src/MapleX.egg-info/requires.txt +2 -0
- maplex-2.0.0/src/MapleX.egg-info/top_level.txt +1 -0
- maplex-2.0.0/src/maplex/__init__.py +41 -0
- maplex-2.0.0/src/maplex/mapleColors.py +46 -0
- maplex-2.0.0/src/maplex/mapleExceptions.py +105 -0
- maplex-2.0.0/src/maplex/mapleLogger.py +375 -0
- maplex-2.0.0/src/maplex/mapleTreeEditor.py +757 -0
- maplex-2.0.0/src/maplex/utils.py +42 -0
maplex-2.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ryuji Hazama
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
maplex-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: MapleX
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: MapleX: A Python library for Maple file format operations, with logging and console color utilities
|
|
5
|
+
Author: Ryuji Hazama
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: cryptography>=46.0.3
|
|
14
|
+
Requires-Dist: pydantic>=2.12.5
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
Dynamic: requires-python
|
|
17
|
+
|
|
18
|
+
# :maple_leaf: MapleX :deciduous_tree:
|
|
19
|
+
|
|
20
|
+
MapleX is a tool set for Maple file format operations, with logging and console color utilities for Python applications.
|
|
21
|
+
|
|
22
|
+
## Maple File
|
|
23
|
+
|
|
24
|
+
Maple is a file system that I created when I was a child. It's like a combination of the INI file and the Jason file. I created this easy to read and write for both humans and machines.
|
|
25
|
+
|
|
26
|
+
### Basic Format
|
|
27
|
+
|
|
28
|
+
```text
|
|
29
|
+
All datas before MAPLE\n will be ignored
|
|
30
|
+
|
|
31
|
+
MAPLE
|
|
32
|
+
CMT Maple data must start with "MAPLE"
|
|
33
|
+
|
|
34
|
+
*MAPLE_TIME
|
|
35
|
+
yyyy/MM/dd HH:mm:ss.fffffff
|
|
36
|
+
CMT Encoded time or optional time in method parameter
|
|
37
|
+
|
|
38
|
+
H *STATUS
|
|
39
|
+
CMT File status
|
|
40
|
+
ADT yyyy/MM/dd HH:mm:ss.fffffff
|
|
41
|
+
RDT yyyy/MM/dd HH:mm:ss.fffffff
|
|
42
|
+
CMT ADT is the most recent edited time
|
|
43
|
+
CMT RDT is the second most recent edited time (before ADT)
|
|
44
|
+
CNT {int}
|
|
45
|
+
CMT CNT is the data count (Optional)
|
|
46
|
+
E
|
|
47
|
+
H *Header
|
|
48
|
+
CMT Headers include '*' are system header
|
|
49
|
+
E
|
|
50
|
+
H Data Headers
|
|
51
|
+
H Sub Data Header
|
|
52
|
+
CMT Comments
|
|
53
|
+
Tags Propaties
|
|
54
|
+
CMT Propaties cannot include 'CRLF'
|
|
55
|
+
Tags2 Propaties
|
|
56
|
+
CMT Cannot use same tags in a Header except CMT and NTE in H NOTES
|
|
57
|
+
H Sub Data Header
|
|
58
|
+
Tags Propaties
|
|
59
|
+
CMT Can use same tag in sub header used in parents header
|
|
60
|
+
E
|
|
61
|
+
E
|
|
62
|
+
H *NOTES
|
|
63
|
+
CMT Notes header
|
|
64
|
+
NTE {strimg}
|
|
65
|
+
NTE ...
|
|
66
|
+
CMT Notes main strings for multi line data
|
|
67
|
+
E
|
|
68
|
+
E
|
|
69
|
+
H Data Headers2
|
|
70
|
+
E
|
|
71
|
+
CMT "\nEOF\n" must be needed for all data
|
|
72
|
+
EOF
|
|
73
|
+
|
|
74
|
+
All datas after "\nEOF\n" will be ignored
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Data boundary
|
|
78
|
+
|
|
79
|
+
- Maple data will start with a line `MAPLE\n` and end with `\nEOF\n`.
|
|
80
|
+
- Data outside those lines will be ignored.
|
|
81
|
+
|
|
82
|
+
E.g.:
|
|
83
|
+
|
|
84
|
+
```text
|
|
85
|
+
MAPLE
|
|
86
|
+
|
|
87
|
+
<MAPLE DATA>
|
|
88
|
+
|
|
89
|
+
EOF
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
:warning: ***Data outside the Maple data could be lost in the future update***.
|
|
93
|
+
|
|
94
|
+
### Blocks
|
|
95
|
+
|
|
96
|
+
- Block starts with `H <Header Name>` and end with `E`.
|
|
97
|
+
- Blocks can be nested.
|
|
98
|
+
|
|
99
|
+
E.g.:
|
|
100
|
+
|
|
101
|
+
```text
|
|
102
|
+
MAPLE
|
|
103
|
+
|
|
104
|
+
H APP DATA
|
|
105
|
+
H PATH INFO
|
|
106
|
+
...<DATA LINES>
|
|
107
|
+
E
|
|
108
|
+
...<DATA LINES>
|
|
109
|
+
E
|
|
110
|
+
|
|
111
|
+
EOF
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Data Lines
|
|
115
|
+
|
|
116
|
+
- Each data line has a 'tag' in front of the data.
|
|
117
|
+
- Before the very first white spece will be treated as a 'tag' and all the data after the white spece will be treated as the data.
|
|
118
|
+
|
|
119
|
+
E.g.: Store `ANY DATA` with a tag `BAR` inside the `FOO` block
|
|
120
|
+
|
|
121
|
+
```text
|
|
122
|
+
MAPLE
|
|
123
|
+
|
|
124
|
+
H FOO
|
|
125
|
+
BAR ANY DATA
|
|
126
|
+
E
|
|
127
|
+
|
|
128
|
+
EOF
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## MapleTree Class
|
|
132
|
+
|
|
133
|
+
### \_\_init\_\_
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
class MapleTree(
|
|
137
|
+
fileName: str,
|
|
138
|
+
tabInd: int = 4,
|
|
139
|
+
encrypt: bool = False,
|
|
140
|
+
key: bytes | None = None,
|
|
141
|
+
createBaseFile: bool = False
|
|
142
|
+
)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
|Property|Required|Value|
|
|
146
|
+
|--------|--------|-----|
|
|
147
|
+
|**fileName**|\*|Maple file name|
|
|
148
|
+
|**tabInd**||White space count for indents|
|
|
149
|
+
|**encrypt**||File encryption|
|
|
150
|
+
|**key**||Encryption key|
|
|
151
|
+
|**createBaseFile**||Create empty base file|
|
|
152
|
+
|
|
153
|
+
E.g.:
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
from maplex import MapleTree
|
|
157
|
+
|
|
158
|
+
mapleFile = MapleTree("FileName.mpl")
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### Open existing Maple file
|
|
162
|
+
|
|
163
|
+
`__init__` will open the Maple file and load data to the baffer.
|
|
164
|
+
|
|
165
|
+
```python
|
|
166
|
+
mapleFile = MapleTree("FileName.mpl")
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### Change indent size
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
mapleFile = MapleTree("FileName.mpl", tabInd=4)
|
|
173
|
+
mapleFile._saveToFile()
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
This makes the maple file look like
|
|
177
|
+
|
|
178
|
+
```text
|
|
179
|
+
MAPLE
|
|
180
|
+
|
|
181
|
+
H FOO
|
|
182
|
+
H BAR
|
|
183
|
+
<MAPLE DATA LINES>
|
|
184
|
+
E
|
|
185
|
+
<MAPLE DATA LINES>
|
|
186
|
+
E
|
|
187
|
+
|
|
188
|
+
EOF
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
If you change the `tabInd` value
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
mapleFile = MapleTree("FileName.mpl", tabInd=2)
|
|
195
|
+
mapleFile._saveToFile()
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
This makes the maple file look like
|
|
199
|
+
|
|
200
|
+
```text
|
|
201
|
+
MAPLE
|
|
202
|
+
|
|
203
|
+
H FOO
|
|
204
|
+
H BAR
|
|
205
|
+
<MAPLE DATA LINES>
|
|
206
|
+
E
|
|
207
|
+
<MAPLE DATA LINES>
|
|
208
|
+
E
|
|
209
|
+
|
|
210
|
+
EOF
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### Create a Base File
|
|
214
|
+
|
|
215
|
+
You can create an empty base file when you initialize the class instance.
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
mapleFile = MapleTree("NewFile.mpl", createBaseFile=True)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
This creates an empty Maple file if the file `NewFile.mpl` does not exist.
|
|
222
|
+
|
|
223
|
+
```text
|
|
224
|
+
MAPLE
|
|
225
|
+
EOF
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
#### File Data Encryption
|
|
229
|
+
|
|
230
|
+
If `encrypt=True`, the instance decrypt data when read it, and encrypt data when save it.
|
|
231
|
+
You need to specify the byte key when you use encryption and the file must be encrypted before read it.
|
|
232
|
+
|
|
233
|
+
```python
|
|
234
|
+
mapleFile = MapleTree("FileName.mpl", encrypt=True, key=key)
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
You can create an encrypted base file with `createBaseFile=True` if the file does not exist.
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
mapleFile = MapleTree("NewFile.mpl", encrypt=True, key=key, createBaseFile=True)
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### readMapleTag
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
def readMapleTag(
|
|
247
|
+
tag: str,
|
|
248
|
+
*headers: str
|
|
249
|
+
) -> str
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
|Property|Required|Value|
|
|
253
|
+
|--------|--------|-----|
|
|
254
|
+
|**tag**|\*|Tag to find|
|
|
255
|
+
|**headers**||Headers contains the tag|
|
|
256
|
+
|
|
257
|
+
`readMapleTag` returns data string tagged with the `tag` in `headers` and return `None` if the tag not found.
|
|
258
|
+
|
|
259
|
+
E.g.:
|
|
260
|
+
|
|
261
|
+
Sample Data (`Sample.mpl`)
|
|
262
|
+
|
|
263
|
+
```text
|
|
264
|
+
MAPLE
|
|
265
|
+
|
|
266
|
+
H FOO
|
|
267
|
+
H BAR
|
|
268
|
+
TAG1 DATA 1
|
|
269
|
+
TAG2 DATA 2
|
|
270
|
+
E
|
|
271
|
+
E
|
|
272
|
+
|
|
273
|
+
EOF
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
```python
|
|
277
|
+
from maplex import MapleTree
|
|
278
|
+
|
|
279
|
+
mapleFile = MapleTree("Sample.mpl")
|
|
280
|
+
mapleData = mapleFile.readMapleTag("TAG1", "FOO", "BAR")
|
|
281
|
+
|
|
282
|
+
print(mapleData)
|
|
283
|
+
# Outputs "DATA 1"
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### saveTagLine
|
|
287
|
+
|
|
288
|
+
```python
|
|
289
|
+
def saveTagLine(
|
|
290
|
+
tag: str,
|
|
291
|
+
valueStr: str,
|
|
292
|
+
willSave: bool,
|
|
293
|
+
*headers: str
|
|
294
|
+
) -> None
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
|Property|Required|Value|
|
|
298
|
+
|--------|--------|-----|
|
|
299
|
+
|**tag**|\*|Target tag|
|
|
300
|
+
|**valueStr**|\*|Data value (string)|
|
|
301
|
+
|**willSave**|\*|Save to file flag|
|
|
302
|
+
|**headers**||Target headers|
|
|
303
|
+
|
|
304
|
+
### deleteTag
|
|
305
|
+
|
|
306
|
+
```python
|
|
307
|
+
def deleteTag(
|
|
308
|
+
delTag: str,
|
|
309
|
+
willSave: bool = False,
|
|
310
|
+
*headers: str
|
|
311
|
+
) -> bool
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### getTagValueDict
|
|
315
|
+
|
|
316
|
+
```python
|
|
317
|
+
getTagValueDic(
|
|
318
|
+
*headers: str
|
|
319
|
+
) -> dict[str, str]
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### getTags
|
|
323
|
+
|
|
324
|
+
```python
|
|
325
|
+
def getTags(
|
|
326
|
+
*headers: str
|
|
327
|
+
) -> list[str]
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### deleteHeader
|
|
331
|
+
|
|
332
|
+
```python
|
|
333
|
+
def deleteHeader(
|
|
334
|
+
delHead: str,
|
|
335
|
+
willSave: bool = False,
|
|
336
|
+
*Headers: str
|
|
337
|
+
) -> bool
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### getHeaders
|
|
341
|
+
|
|
342
|
+
```python
|
|
343
|
+
def getHeaders(
|
|
344
|
+
*headers: str
|
|
345
|
+
) -> list
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
## Logger Class
|
|
349
|
+
|
|
350
|
+
Logger is a logging object for Python applications. It outputs application logs to log files and to standard output.
|
|
351
|
+
|
|
352
|
+
### Usage
|
|
353
|
+
|
|
354
|
+
```python
|
|
355
|
+
from maplex import Logger
|
|
356
|
+
|
|
357
|
+
logger = Logger("FunctionName")
|
|
358
|
+
logger.Info("Hello there!")
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
This outputs:
|
|
362
|
+
|
|
363
|
+
```console
|
|
364
|
+
[INFO ][FunctionName] <module>(4) Hello there!
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
File output will be: `log_yyyyMMdd.log`
|
|
368
|
+
|
|
369
|
+
```log
|
|
370
|
+
(PsNo) yyyy-MM-dd HH:mm:ss.fff [INFO ][FunctionName] <module>(4) Hello there!
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
#### Log Level
|
|
374
|
+
|
|
375
|
+
- TRACE
|
|
376
|
+
- DEBUG
|
|
377
|
+
- INFO
|
|
378
|
+
- WARN
|
|
379
|
+
- ERROR
|
|
380
|
+
- FATAL
|
|
381
|
+
|
|
382
|
+
#### ShowError function
|
|
383
|
+
|
|
384
|
+
This outputs the error logs and stuck trace.
|
|
385
|
+
|
|
386
|
+
Function:
|
|
387
|
+
|
|
388
|
+
```python
|
|
389
|
+
Logger.ShowError(
|
|
390
|
+
ex: Exception,
|
|
391
|
+
message: str | None = None,
|
|
392
|
+
fatal: bool = False
|
|
393
|
+
)
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
- If `fatal=True`, it outputs log as a `FATAL` log level.
|
|
397
|
+
|
|
398
|
+
### Settings
|
|
399
|
+
|
|
400
|
+
Working on...
|
|
401
|
+
|
|
402
|
+
## Exceptions
|
|
403
|
+
|
|
404
|
+
## Console Colors
|
|
405
|
+
|
|
406
|
+
## Install maplex :inbox_tray:
|
|
407
|
+
|
|
408
|
+
### From PyPI
|
|
409
|
+
|
|
410
|
+
```bash
|
|
411
|
+
pip install maplex
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### Manual Installation
|
|
415
|
+
|
|
416
|
+
1. Download `./dist/maplex-<version>-py3-none-any.whl`
|
|
417
|
+
2. Run `python[3] -m pip install /path/to/downloaded/maplex-<version>-py3-none-any.whl [--break-system-packages]`
|
|
418
|
+
|
|
419
|
+
## If You Build Package by Yourself
|
|
420
|
+
|
|
421
|
+
Run `python[3] -m build`
|
|
422
|
+
|
|
423
|
+
or
|
|
424
|
+
|
|
425
|
+
Run `python[3] setup.py sdist bdist_wheel`
|