xmlgenerator 0.5.1__py3-none-any.whl → 0.5.3__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.
- xmlgenerator/arguments.py +10 -10
- xmlgenerator/bootstrap.py +19 -1
- xmlgenerator/generator.py +48 -12
- xmlgenerator-0.5.3.dist-info/METADATA +205 -0
- xmlgenerator-0.5.3.dist-info/RECORD +14 -0
- {xmlgenerator-0.5.1.dist-info → xmlgenerator-0.5.3.dist-info}/WHEEL +1 -1
- xmlgenerator-0.5.1.dist-info/METADATA +0 -319
- xmlgenerator-0.5.1.dist-info/RECORD +0 -14
- {xmlgenerator-0.5.1.dist-info → xmlgenerator-0.5.3.dist-info}/entry_points.txt +0 -0
- {xmlgenerator-0.5.1.dist-info → xmlgenerator-0.5.3.dist-info}/licenses/LICENSE +0 -0
- {xmlgenerator-0.5.1.dist-info → xmlgenerator-0.5.3.dist-info}/top_level.txt +0 -0
xmlgenerator/arguments.py
CHANGED
@@ -37,49 +37,49 @@ def _get_parser():
|
|
37
37
|
"-c", "--config",
|
38
38
|
metavar="<config.yml>",
|
39
39
|
dest="config_yaml",
|
40
|
-
help="pass
|
40
|
+
help="pass a YAML configuration file"
|
41
41
|
)
|
42
42
|
parser.add_argument(
|
43
43
|
"-l", "--locale",
|
44
44
|
metavar="<locale>",
|
45
45
|
default="en_US",
|
46
|
-
help="randomizer
|
46
|
+
help="locale for the randomizer (default: %(default)s)"
|
47
47
|
)
|
48
48
|
output_arg = parser.add_argument(
|
49
49
|
"-o", "--output",
|
50
50
|
metavar="<output.xml>",
|
51
51
|
dest="output_path",
|
52
|
-
help="save output to
|
52
|
+
help="save the output to a directory or file"
|
53
53
|
)
|
54
54
|
parser.add_argument(
|
55
55
|
"-p", "--pretty",
|
56
56
|
action="store_true",
|
57
|
-
help="prettify output XML"
|
57
|
+
help="prettify the output XML"
|
58
58
|
)
|
59
59
|
parser.add_argument(
|
60
60
|
"-v", "--validation",
|
61
61
|
metavar="<validation>",
|
62
62
|
choices=["none", "schema", "schematron"],
|
63
63
|
default="schema",
|
64
|
-
help="validate generated XML document (none, schema, schematron
|
64
|
+
help="validate the generated XML document (none, schema, schematron; default: %(default)s)"
|
65
65
|
)
|
66
66
|
parser.add_argument(
|
67
67
|
"-ff", "--fail-fast",
|
68
68
|
action="store_true",
|
69
69
|
default="true",
|
70
|
-
help="terminate execution on validation error (default
|
70
|
+
help="terminate execution on a validation error (default: %(default)s)"
|
71
71
|
)
|
72
72
|
parser.add_argument(
|
73
73
|
"-e", "--encoding",
|
74
74
|
metavar="<encoding>",
|
75
75
|
choices=["utf-8", "windows-1251"],
|
76
76
|
default="utf-8",
|
77
|
-
help="output XML encoding (utf-8, windows-1251
|
77
|
+
help="the output XML encoding (utf-8, windows-1251; default: %(default)s)"
|
78
78
|
)
|
79
79
|
parser.add_argument(
|
80
80
|
"-s", "--seed",
|
81
81
|
metavar="<seed>",
|
82
|
-
help="set randomization seed"
|
82
|
+
help="set the randomization seed"
|
83
83
|
)
|
84
84
|
parser.add_argument(
|
85
85
|
"-d", "--debug",
|
@@ -90,14 +90,14 @@ def _get_parser():
|
|
90
90
|
"-V", "--version",
|
91
91
|
action='version',
|
92
92
|
version='%(prog)s 0.1.0',
|
93
|
-
help="
|
93
|
+
help="show the current version"
|
94
94
|
)
|
95
95
|
|
96
96
|
# add shell completions
|
97
97
|
config_arg.complete = shtab.FILE
|
98
98
|
source_arg.complete = shtab.FILE
|
99
99
|
output_arg.complete = shtab.FILE
|
100
|
-
shtab.add_argument_to(parser, ["-C", "--completion"], "print shell completion script (bash, zsh, tcsh)")
|
100
|
+
shtab.add_argument_to(parser, ["-C", "--completion"], "print a shell completion script (bash, zsh, tcsh)")
|
101
101
|
completion_act = [a for a in parser._actions if a.dest == 'completion']
|
102
102
|
if completion_act:
|
103
103
|
completion_act[0].metavar = '<shell>'
|
xmlgenerator/bootstrap.py
CHANGED
@@ -12,13 +12,31 @@ from xmlgenerator.randomization import Randomizer
|
|
12
12
|
from xmlgenerator.substitution import Substitutor
|
13
13
|
from xmlgenerator.validation import XmlValidator
|
14
14
|
|
15
|
-
# TODO Generator - обработка стандартных xsd типов
|
16
15
|
# TODO кастомные переменные для локального контекста
|
17
16
|
# TODO валидация по Schematron
|
18
17
|
# TODO типизировать
|
19
18
|
# TODO Почистить и перевести комментарии
|
20
19
|
# TODO Дописать тесты
|
21
20
|
|
21
|
+
# TODO _generate_duration
|
22
|
+
# TODO _generate_base64_binary
|
23
|
+
# TODO _generate_any_uri
|
24
|
+
# TODO _generate_qname
|
25
|
+
# TODO _generate_notation
|
26
|
+
|
27
|
+
# TODO _generate_language
|
28
|
+
# TODO _generate_name
|
29
|
+
# TODO _generate_nc_name
|
30
|
+
# TODO _generate_normalized_string
|
31
|
+
# TODO _generate_token
|
32
|
+
# TODO _generate_id
|
33
|
+
# TODO _generate_idref
|
34
|
+
# TODO _generate_idrefs
|
35
|
+
# TODO _generate_entity
|
36
|
+
# TODO _generate_entities
|
37
|
+
# TODO _generate_nmtoken
|
38
|
+
# TODO _generate_nmtokens
|
39
|
+
|
22
40
|
logging.basicConfig(level=logging.WARN, format='%(asctime)s [%(name)-26s] %(levelname)-6s - %(message)s')
|
23
41
|
|
24
42
|
logger = logging.getLogger('xmlgenerator.bootstrap')
|
xmlgenerator/generator.py
CHANGED
@@ -71,18 +71,18 @@ class XmlGenerator:
|
|
71
71
|
'nonNegativeInteger': self._generate_non_negative_integer,
|
72
72
|
|
73
73
|
# derived - from string
|
74
|
-
'language':
|
75
|
-
'Name':
|
76
|
-
'NCName':
|
77
|
-
'normalizedString':
|
78
|
-
'token':
|
79
|
-
'ID':
|
80
|
-
'IDREF':
|
81
|
-
'IDREFS':
|
82
|
-
'ENTITY':
|
83
|
-
'ENTITIES':
|
84
|
-
'NMTOKEN':
|
85
|
-
'NMTOKENS':
|
74
|
+
'language': self._generate_language,
|
75
|
+
'Name': self._generate_name,
|
76
|
+
'NCName': self._generate_nc_name,
|
77
|
+
'normalizedString': self._generate_normalized_string,
|
78
|
+
'token': self._generate_token,
|
79
|
+
'ID': self._generate_id,
|
80
|
+
'IDREF': self._generate_idref,
|
81
|
+
'IDREFS': self._generate_idrefs,
|
82
|
+
'ENTITY': self._generate_entity,
|
83
|
+
'ENTITIES': self._generate_entities,
|
84
|
+
'NMTOKEN': self._generate_nmtoken,
|
85
|
+
'NMTOKENS': self._generate_nmtokens,
|
86
86
|
}
|
87
87
|
|
88
88
|
def generate_xml(self, xsd_schema, local_config: GeneratorConfig) -> etree.Element:
|
@@ -492,6 +492,42 @@ class XmlGenerator:
|
|
492
492
|
constraints = replace(constraints, min_value=min_value, max_value=max_value, fraction_digits=0)
|
493
493
|
return self._generate_decimal(constraints)
|
494
494
|
|
495
|
+
def _generate_language(self, constraints: TypeConstraints):
|
496
|
+
raise RuntimeError('not yet implemented')
|
497
|
+
|
498
|
+
def _generate_name(self, constraints: TypeConstraints):
|
499
|
+
raise RuntimeError('not yet implemented')
|
500
|
+
|
501
|
+
def _generate_nc_name(self, constraints: TypeConstraints):
|
502
|
+
raise RuntimeError('not yet implemented')
|
503
|
+
|
504
|
+
def _generate_normalized_string(self, constraints: TypeConstraints):
|
505
|
+
raise RuntimeError('not yet implemented')
|
506
|
+
|
507
|
+
def _generate_token(self, constraints: TypeConstraints):
|
508
|
+
raise RuntimeError('not yet implemented')
|
509
|
+
|
510
|
+
def _generate_id(self, constraints: TypeConstraints):
|
511
|
+
raise RuntimeError('not yet implemented')
|
512
|
+
|
513
|
+
def _generate_idref(self, constraints: TypeConstraints):
|
514
|
+
raise RuntimeError('not yet implemented')
|
515
|
+
|
516
|
+
def _generate_idrefs(self, constraints: TypeConstraints):
|
517
|
+
raise RuntimeError('not yet implemented')
|
518
|
+
|
519
|
+
def _generate_entity(self, constraints: TypeConstraints):
|
520
|
+
raise RuntimeError('not yet implemented')
|
521
|
+
|
522
|
+
def _generate_entities(self, constraints: TypeConstraints):
|
523
|
+
raise RuntimeError('not yet implemented')
|
524
|
+
|
525
|
+
def _generate_nmtoken(self, constraints: TypeConstraints):
|
526
|
+
raise RuntimeError('not yet implemented')
|
527
|
+
|
528
|
+
def _generate_nmtokens(self, constraints: TypeConstraints):
|
529
|
+
raise RuntimeError('not yet implemented')
|
530
|
+
|
495
531
|
|
496
532
|
def extract_type_constraints(xsd_type, local_config: GeneratorConfig) -> TypeConstraints:
|
497
533
|
min_length = getattr(xsd_type, 'min_length', None)
|
@@ -0,0 +1,205 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: xmlgenerator
|
3
|
+
Version: 0.5.3
|
4
|
+
Summary: Generates XML documents from XSD schemas
|
5
|
+
Home-page: https://github.com/lexakimov/xmlgenerator
|
6
|
+
Author: Alexey Akimov
|
7
|
+
Author-email: lex.akimov23@gmail.com
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Requires-Python: >=3.6
|
12
|
+
Description-Content-Type: text/markdown
|
13
|
+
License-File: LICENSE
|
14
|
+
Requires-Dist: lxml
|
15
|
+
Requires-Dist: xmlschema
|
16
|
+
Requires-Dist: Faker
|
17
|
+
Requires-Dist: rstr
|
18
|
+
Requires-Dist: PyYAML
|
19
|
+
Requires-Dist: shtab
|
20
|
+
Dynamic: author
|
21
|
+
Dynamic: author-email
|
22
|
+
Dynamic: classifier
|
23
|
+
Dynamic: description
|
24
|
+
Dynamic: description-content-type
|
25
|
+
Dynamic: home-page
|
26
|
+
Dynamic: license-file
|
27
|
+
Dynamic: requires-dist
|
28
|
+
Dynamic: requires-python
|
29
|
+
Dynamic: summary
|
30
|
+
|
31
|
+
# XML Generator
|
32
|
+
|
33
|
+
- [Русский 🇷🇺](README_RU.md)
|
34
|
+
- [English 🇺🇸](README.md)
|
35
|
+
|
36
|
+
Generates XML documents based on XSD schemas with the ability to customize data through a YAML configuration file.
|
37
|
+
|
38
|
+
Simplifies the creation of test or demonstration XML data for complex schemas.
|
39
|
+
|
40
|
+
## Features
|
41
|
+
|
42
|
+
- Generation of XML documents based on XSD schemas
|
43
|
+
- Customization of generated values via a YAML configuration file
|
44
|
+
- Validation of generated documents
|
45
|
+
- Command-line interface for convenient use
|
46
|
+
|
47
|
+
## Installation
|
48
|
+
|
49
|
+
### Installation via pip
|
50
|
+
|
51
|
+
```bash
|
52
|
+
pip install xmlgenerator
|
53
|
+
```
|
54
|
+
|
55
|
+
### Install executable file manually (linux)
|
56
|
+
|
57
|
+
```bash
|
58
|
+
curl -LO https://github.com/lexakimov/xmlgenerator/releases/download/v0.5.3/xmlgenerator-linux-amd64
|
59
|
+
chmod +x xmlgenerator-linux-amd64
|
60
|
+
sudo install xmlgenerator-linux-amd64 /usr/local/bin/xmlgenerator
|
61
|
+
```
|
62
|
+
|
63
|
+
### Install shell completions (linux)
|
64
|
+
|
65
|
+
```shell
|
66
|
+
# also available: zsh, tcsh
|
67
|
+
xmlgenerator -C bash | sudo tee /etc/bash_completion.d/xmlgenerator
|
68
|
+
```
|
69
|
+
|
70
|
+
## Usage
|
71
|
+
|
72
|
+
The generator command is `xmlgenerator`
|
73
|
+
|
74
|
+
**Flags and parameters:**
|
75
|
+
|
76
|
+
```
|
77
|
+
usage: xmlgenerator [-h] [-c <config.yml>] [-l <locale>] [-o <output.xml>] [-p] [-v <validation>] [-ff] [-e <encoding>]
|
78
|
+
[-s <seed>] [-d] [-V] [-C <shell>]
|
79
|
+
xsd [xsd ...]
|
80
|
+
|
81
|
+
Generates XML documents from XSD schemas
|
82
|
+
|
83
|
+
positional arguments:
|
84
|
+
xsd paths to xsd schema(s) or directory with xsd schemas
|
85
|
+
|
86
|
+
options:
|
87
|
+
-h, --help show this help message and exit
|
88
|
+
-c, --config <config.yml> pass a YAML configuration file
|
89
|
+
-l, --locale <locale> locale for the randomizer (default: en_US)
|
90
|
+
-o, --output <output.xml> save the output to a directory or file
|
91
|
+
-p, --pretty prettify the output XML
|
92
|
+
-v, --validation <validation> validate the generated XML document (none, schema, schematron; default: schema)
|
93
|
+
-ff, --fail-fast terminate execution on a validation error (default: true)
|
94
|
+
-e, --encoding <encoding> the output XML encoding (utf-8, windows-1251; default: utf-8)
|
95
|
+
-s, --seed <seed> set the randomization seed
|
96
|
+
-d, --debug enable debug mode
|
97
|
+
-V, --version show the current version
|
98
|
+
-C, --completion <shell> print a shell completion script (bash, zsh, tcsh)
|
99
|
+
```
|
100
|
+
|
101
|
+
**Examples:**
|
102
|
+
|
103
|
+
- Generate XML from a single schema and print to console:
|
104
|
+
```bash
|
105
|
+
xmlgenerator path/to/your/schema.xsd
|
106
|
+
```
|
107
|
+
|
108
|
+
- Generate XML from all schemas in a directory and save to the `output` folder using a configuration file:
|
109
|
+
```bash
|
110
|
+
xmlgenerator -c config.yml -o output/ path/to/schemas/
|
111
|
+
```
|
112
|
+
|
113
|
+
- Generate XML from a specific schema, save to a file with pretty formatting and windows-1251 encoding:
|
114
|
+
```bash
|
115
|
+
xmlgenerator -o output.xml -p -e windows-1251 path/to/your/schema.xsd
|
116
|
+
```
|
117
|
+
|
118
|
+
- Generate XML with validation disabled:
|
119
|
+
```bash
|
120
|
+
xmlgenerator -v none path/to/your/schema.xsd
|
121
|
+
```
|
122
|
+
|
123
|
+
## Configuration
|
124
|
+
|
125
|
+
The generator can be configured using a YAML file passed via the `-c` or `--config` option.
|
126
|
+
|
127
|
+
Description and examples of configuration are in [CONFIGURATION](./CONFIGURATION.md).
|
128
|
+
|
129
|
+
## Validation
|
130
|
+
|
131
|
+
Generated XML documents are checked for conformance against the schema used for generation.
|
132
|
+
By default, validation against the source XSD schema is used.
|
133
|
+
|
134
|
+
If a document does not conform to the schema, execution stops immediately.
|
135
|
+
This behavior can be disabled using the flag `-ff false` or `--fail-fast false`.
|
136
|
+
|
137
|
+
To disable validation, use the flag `-v none` or `--validation none`.
|
138
|
+
|
139
|
+
## Contribution
|
140
|
+
|
141
|
+
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
|
142
|
+
|
143
|
+
### Build from source
|
144
|
+
|
145
|
+
1. **Clone the repository:**
|
146
|
+
```bash
|
147
|
+
git clone https://github.com/lexakimov/xmlgenerator.git
|
148
|
+
cd xmlgenerator
|
149
|
+
```
|
150
|
+
|
151
|
+
2. **Create and activate a virtual environment (recommended):**
|
152
|
+
```bash
|
153
|
+
python -m venv .venv
|
154
|
+
```
|
155
|
+
* **For Linux/macOS:**
|
156
|
+
```bash
|
157
|
+
source .venv/bin/activate
|
158
|
+
```
|
159
|
+
* **For Windows (Command Prompt/PowerShell):**
|
160
|
+
```bash
|
161
|
+
.\.venv\Scripts\activate
|
162
|
+
```
|
163
|
+
|
164
|
+
3. **Install dependencies:**
|
165
|
+
```bash
|
166
|
+
pip install -r requirements.txt
|
167
|
+
```
|
168
|
+
|
169
|
+
4.1. **Install the package:**
|
170
|
+
|
171
|
+
```bash
|
172
|
+
pip install .
|
173
|
+
# or for development mode (code changes will be immediately reflected)
|
174
|
+
# pip install -e .
|
175
|
+
```
|
176
|
+
|
177
|
+
4.2. **Otherwise, build single executable:**
|
178
|
+
|
179
|
+
```bash
|
180
|
+
python build_native.py
|
181
|
+
```
|
182
|
+
|
183
|
+
### Project Structure
|
184
|
+
|
185
|
+
- `xmlgenerator/` - main project code
|
186
|
+
- `tests/` - tests
|
187
|
+
|
188
|
+
### Running Tests
|
189
|
+
|
190
|
+
```bash
|
191
|
+
pytest
|
192
|
+
```
|
193
|
+
|
194
|
+
---
|
195
|
+
|
196
|
+
## License
|
197
|
+
|
198
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
199
|
+
|
200
|
+
## Contacts
|
201
|
+
|
202
|
+
For any questions or issues, please contact [lex.akimov23@gmail.com].
|
203
|
+
|
204
|
+
You can also create an [Issue on GitHub](https://github.com/lexakimov/xmlgenerator/issues) to report bugs or suggest
|
205
|
+
improvements.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
xmlgenerator/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
xmlgenerator/arguments.py,sha256=AifALtYzVo_j_Pawj8gX3I1YrNTJHtDjCCe5z4vSp4k,4891
|
3
|
+
xmlgenerator/bootstrap.py,sha256=YIgdumv_JK20Qnf_0RetoFPv344YflERklJMkNqInS8,4010
|
4
|
+
xmlgenerator/configuration.py,sha256=JYhz_lONxd0faUiZHG-TVEs6yocn0s__Ulwtcvq9eDs,5946
|
5
|
+
xmlgenerator/generator.py,sha256=FDZ8U52wpbhvbunFY_8F5CkviFs4u14NojfxPnw7zkw,30095
|
6
|
+
xmlgenerator/randomization.py,sha256=azXW1SxKSA9_lw1IBQDPOwSUXFEXo8IGWFD0an-eVF0,4416
|
7
|
+
xmlgenerator/substitution.py,sha256=v4rzqnF1p1yN0VKRDFwQM5zQbpdg9ebbrh65cnh9qxw,6078
|
8
|
+
xmlgenerator/validation.py,sha256=uCJjS5YmRDlAp9C-5Rd4E2Brh6_3WOG2-dSGxDiaH14,2023
|
9
|
+
xmlgenerator-0.5.3.dist-info/licenses/LICENSE,sha256=QlXK8O3UcoAYUYwVJNgB9MSM7O94ogNo_1hd9GzznUQ,1070
|
10
|
+
xmlgenerator-0.5.3.dist-info/METADATA,sha256=BIQSk5Y8jzaCHce-L6BdLBT4G96_z4fF6boWaBU729Y,5675
|
11
|
+
xmlgenerator-0.5.3.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
|
12
|
+
xmlgenerator-0.5.3.dist-info/entry_points.txt,sha256=ly9hKr3o4AzFUkelBZNRzyKYf-Ld4kfcffvBu1oHq54,61
|
13
|
+
xmlgenerator-0.5.3.dist-info/top_level.txt,sha256=jr7FbMBm8MQ6j8I_-nWzQQEseXzwSCZNXgrkWuk9P4E,13
|
14
|
+
xmlgenerator-0.5.3.dist-info/RECORD,,
|
@@ -1,319 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: xmlgenerator
|
3
|
-
Version: 0.5.1
|
4
|
-
Summary: Generates XML documents from XSD schemas
|
5
|
-
Home-page: https://github.com/lexakimov/xmlgenerator
|
6
|
-
Author: Alexey Akimov
|
7
|
-
Author-email: lex.akimov23@gmail.com
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
10
|
-
Classifier: Operating System :: OS Independent
|
11
|
-
Requires-Python: >=3.6
|
12
|
-
Description-Content-Type: text/markdown
|
13
|
-
License-File: LICENSE
|
14
|
-
Requires-Dist: lxml
|
15
|
-
Requires-Dist: xmlschema
|
16
|
-
Requires-Dist: Faker
|
17
|
-
Requires-Dist: rstr
|
18
|
-
Requires-Dist: PyYAML
|
19
|
-
Dynamic: author
|
20
|
-
Dynamic: author-email
|
21
|
-
Dynamic: classifier
|
22
|
-
Dynamic: description
|
23
|
-
Dynamic: description-content-type
|
24
|
-
Dynamic: home-page
|
25
|
-
Dynamic: license-file
|
26
|
-
Dynamic: requires-dist
|
27
|
-
Dynamic: requires-python
|
28
|
-
Dynamic: summary
|
29
|
-
|
30
|
-
# XML Generator
|
31
|
-
|
32
|
-
- [Русский 🇷🇺](README_RU.md)
|
33
|
-
- [English 🇺🇸](README.md)
|
34
|
-
|
35
|
-
Generates XML documents based on XSD schemas with the ability to customize data through a YAML configuration file.
|
36
|
-
Simplifies the creation of test or demonstration XML data for complex schemas.
|
37
|
-
|
38
|
-
## Features
|
39
|
-
|
40
|
-
- Generation of XML documents based on XSD schemas
|
41
|
-
- Customization of generated values via a YAML configuration file
|
42
|
-
- Validation of generated documents
|
43
|
-
- Command-line interface for convenient use
|
44
|
-
|
45
|
-
## Installation
|
46
|
-
|
47
|
-
### Installation via pip
|
48
|
-
|
49
|
-
```bash
|
50
|
-
pip install xmlgenerator
|
51
|
-
```
|
52
|
-
|
53
|
-
### Build from source
|
54
|
-
|
55
|
-
1. **Clone the repository:**
|
56
|
-
```bash
|
57
|
-
git clone https://github.com/lexakimov/xmlgenerator.git
|
58
|
-
cd xmlgenerator
|
59
|
-
```
|
60
|
-
|
61
|
-
2. **Create and activate a virtual environment (recommended):**
|
62
|
-
```bash
|
63
|
-
python -m venv .venv
|
64
|
-
```
|
65
|
-
* **For Linux/macOS:**
|
66
|
-
```bash
|
67
|
-
source .venv/bin/activate
|
68
|
-
```
|
69
|
-
* **For Windows (Command Prompt/PowerShell):**
|
70
|
-
```bash
|
71
|
-
.\.venv\Scripts\activate
|
72
|
-
```
|
73
|
-
|
74
|
-
3. **Install dependencies:**
|
75
|
-
```bash
|
76
|
-
pip install -r requirements.txt
|
77
|
-
```
|
78
|
-
|
79
|
-
4.1. **Install the package:**
|
80
|
-
```bash
|
81
|
-
pip install .
|
82
|
-
# or for development mode (code changes will be immediately reflected)
|
83
|
-
# pip install -e .
|
84
|
-
```
|
85
|
-
|
86
|
-
4.2. **Otherwise, build single executable:**
|
87
|
-
```bash
|
88
|
-
python build_native.py
|
89
|
-
```
|
90
|
-
|
91
|
-
## CLI Usage
|
92
|
-
|
93
|
-
The main command to run the generator is `xmlgenerator`.
|
94
|
-
|
95
|
-
**Examples:**
|
96
|
-
|
97
|
-
- Generate XML from a single schema and print to console:
|
98
|
-
```bash
|
99
|
-
xmlgenerator path/to/your/schema.xsd
|
100
|
-
```
|
101
|
-
|
102
|
-
- Generate XML from all schemas in a directory and save to the `output` folder using a configuration file:
|
103
|
-
```bash
|
104
|
-
xmlgenerator -c config.yml -o output/ path/to/schemas/
|
105
|
-
```
|
106
|
-
|
107
|
-
- Generate XML from a specific schema, save to a file with pretty formatting and windows-1251 encoding:
|
108
|
-
```bash
|
109
|
-
xmlgenerator -o output.xml -p -e windows-1251 path/to/your/schema.xsd
|
110
|
-
```
|
111
|
-
|
112
|
-
- Generate XML with validation disabled:
|
113
|
-
```bash
|
114
|
-
xmlgenerator -v none path/to/your/schema.xsd
|
115
|
-
```
|
116
|
-
|
117
|
-
**Install shell completions:**
|
118
|
-
|
119
|
-
```shell
|
120
|
-
# also available: zsh, tcsh
|
121
|
-
xmlgenerator -C bash | sudo tee /etc/bash_completion.d/xmlgenerator
|
122
|
-
```
|
123
|
-
|
124
|
-
**Detailed CLI Usage:**
|
125
|
-
|
126
|
-
```
|
127
|
-
usage: xmlgenerator [-h] [-c <config.yml>] [-o <output.xml>] [-p] [-v <validation>] [-ff] [-e <encoding>]
|
128
|
-
[--seed <seed>] [-d] [-V]
|
129
|
-
xsd [xsd ...]
|
130
|
-
|
131
|
-
Generates XML documents from XSD schemas
|
132
|
-
|
133
|
-
positional arguments:
|
134
|
-
xsd paths to xsd schema(s) or directory with xsd schemas
|
135
|
-
|
136
|
-
options:
|
137
|
-
-h, --help show this help message and exit
|
138
|
-
-c, --config <config.yml> pass yaml configuration file
|
139
|
-
-l, --locale <locale> randomizer locale (default: en_US)
|
140
|
-
-o, --output <output.xml> save output to dir or file
|
141
|
-
-p, --pretty prettify output XML
|
142
|
-
-v, --validation <validation> validate generated XML document (none, schema, schematron, default is schema)
|
143
|
-
-ff, --fail-fast terminate execution on validation error (default is true)
|
144
|
-
-e, --encoding <encoding> output XML encoding (utf-8, windows-1251, default is utf-8)
|
145
|
-
-s, --seed <seed> set randomization seed
|
146
|
-
-d, --debug enable debug mode
|
147
|
-
-V, --version shows current version
|
148
|
-
-C, --completion <shell> print shell completion script (bash, zsh, tcsh)
|
149
|
-
```
|
150
|
-
|
151
|
-
## Configuration
|
152
|
-
|
153
|
-
The generator can be configured using a YAML file passed via the `-c` or `--config` option.
|
154
|
-
|
155
|
-
**Configuration File Structure:**
|
156
|
-
|
157
|
-
```yaml
|
158
|
-
# Global settings (apply to all schemas)
|
159
|
-
global:
|
160
|
-
|
161
|
-
# Regular expression to extract a substring from the source xsd schema filename.
|
162
|
-
# The extracted substring can be used via the `source_extracted` function.
|
163
|
-
# The regular expression must contain the group `extracted`.
|
164
|
-
# Default value: `(?P<extracted>.*).(xsd|XSD)` (extracts the filename without extension).
|
165
|
-
source_filename: ...
|
166
|
-
|
167
|
-
# Filename template for saving the generated document.
|
168
|
-
# Default value: `{{ source_extracted }}_{{ uuid }}` (xsd schema filename + random UUID)
|
169
|
-
output_filename: ...
|
170
|
-
|
171
|
-
# Random value generator settings
|
172
|
-
randomization:
|
173
|
-
# Probability of adding optional elements (0.0-1.0)
|
174
|
-
# Default value: 0.5
|
175
|
-
probability: 1
|
176
|
-
# Limit for the minimal number of elements
|
177
|
-
min_occurs: 0
|
178
|
-
# Limit for the maximum number of elements
|
179
|
-
max_occurs: 5
|
180
|
-
# Minimum string length
|
181
|
-
min_length: 5
|
182
|
-
# Maximum string length
|
183
|
-
max_length: 20
|
184
|
-
# Minimum numeric value
|
185
|
-
min_inclusive: 10
|
186
|
-
# Maximum numeric value
|
187
|
-
max_inclusive: 1000000
|
188
|
-
|
189
|
-
# Override generated values for tags and attributes.
|
190
|
-
# Key - string or regular expression to match the tag/attribute name.
|
191
|
-
# Value - string with optional use of placeholders:
|
192
|
-
# `{{ function }}` - substitutes the value provided by the predefined function.
|
193
|
-
# `{{ function | modifier }}` - same, but with a modifier [ global | local ].
|
194
|
-
# - `global` - a single value will be used along all generation.
|
195
|
-
# - `local` - a single value will be used in context of current document.
|
196
|
-
#
|
197
|
-
# The list of available functions is below.
|
198
|
-
# The order of entries matters; the first matching override will be selected.
|
199
|
-
# Key matching is case-insensitive.
|
200
|
-
value_override:
|
201
|
-
name_regexp_1: "static value"
|
202
|
-
name_regexp_2: "{{ function_call }}"
|
203
|
-
"name_regexp_\d": "static-text-and-{{ function_call }}"
|
204
|
-
name: "static-text-and-{{ function_call }}-{{ another_function_call }}"
|
205
|
-
|
206
|
-
# Extend/override global settings for specific files.
|
207
|
-
# Key - string or regular expression to match the xsd filename(s).
|
208
|
-
# The order of entries matters; the first matching override will be selected.
|
209
|
-
# Key matching is case-insensitive.
|
210
|
-
specific:
|
211
|
-
# Each value can have the same set of parameters as the global section
|
212
|
-
"SCHEM.*":
|
213
|
-
# for schemas named "SCHEM.*", xml document names will only contain UUIDv4 + '.xml'
|
214
|
-
output_filename: "{{ uuid }}"
|
215
|
-
# Random value generator settings for schemas named "SCHEM.*"
|
216
|
-
randomization:
|
217
|
-
# for schemas named "SCHEM.*", the probability of adding optional elements will be 30%
|
218
|
-
probability: 0.3
|
219
|
-
value_override:
|
220
|
-
# override the value set by the global configuration
|
221
|
-
name_regexp_1: "static value"
|
222
|
-
# reset overrides for tags/attributes containing 'name' set by the global configuration
|
223
|
-
name:
|
224
|
-
```
|
225
|
-
|
226
|
-
Configuration Priority:
|
227
|
-
|
228
|
-
- specific settings
|
229
|
-
- global settings
|
230
|
-
- default settings
|
231
|
-
|
232
|
-
### Placeholder Functions
|
233
|
-
|
234
|
-
In the `value_override` sections, you can specify either a string value or special placeholders:
|
235
|
-
|
236
|
-
- `{{ function }}` - Substitutes the value provided by the predefined function.
|
237
|
-
- `{{ function | modifier }}` - Same, but with a modifier `[ global | local ]`, where:
|
238
|
-
- `global`: The function will generate and use *the same single value* throughout the *entire generation process*
|
239
|
-
for all documents.
|
240
|
-
- `local`: The function will generate and use *the same single value* within the scope of *a single generated
|
241
|
-
document*.
|
242
|
-
- No modifier: A new value is generated each time the function is called.
|
243
|
-
|
244
|
-
**List of Placeholder Functions:**
|
245
|
-
|
246
|
-
| Function | Description |
|
247
|
-
|------------------------------------|------------------------------------------------------------------------------------------------------------|
|
248
|
-
| `source_filename` | Filename of the source xsd schema with extension (e.g., `schema.xsd`) |
|
249
|
-
| `source_extracted` | String extracted from the source xsd filename using the regex specified in `source_filename_extract_regex` |
|
250
|
-
| `output_filename` | String described by the `output_filename_template` configuration parameter |
|
251
|
-
| `uuid` | Random UUIDv4 |
|
252
|
-
| `regex("pattern")` | Random string value matching the specified regular expression |
|
253
|
-
| `any('A', "B", C)` | Random value from enumeration |
|
254
|
-
| `number(A, B)` | Random number between A and B |
|
255
|
-
| `date("2010-01-01", "2025-01-01")` | Random date within the specified range |
|
256
|
-
| `last_name` | Last Name |
|
257
|
-
| `first_name` | First Name |
|
258
|
-
| `middle_name` | Middle Name |
|
259
|
-
| `address_text` | Address |
|
260
|
-
| `administrative_unit` | Administrative Unit (e.g., District) |
|
261
|
-
| `house_number` | House Number |
|
262
|
-
| `city_name` | City Name |
|
263
|
-
| `postcode` | Postal Code |
|
264
|
-
| `company_name` | Company Name |
|
265
|
-
| `bank_name` | Bank Name |
|
266
|
-
| `phone_number` | Phone Number |
|
267
|
-
| `inn_fl` | Individual Taxpayer Number (Physical Person) |
|
268
|
-
| `inn_ul` | Taxpayer Identification Number (Legal Entity) |
|
269
|
-
| `ogrn_ip` | Primary State Registration Number (Individual Entrepreneur) |
|
270
|
-
| `ogrn_fl` | Primary State Registration Number (Physical Person) |
|
271
|
-
| `kpp` | Reason Code for Registration |
|
272
|
-
| `snils_formatted` | SNILS (Personal Insurance Account Number) in the format `123-456-789 90` |
|
273
|
-
| `email` | Random email address |
|
274
|
-
|
275
|
-
**Configuration Examples:**
|
276
|
-
|
277
|
-
```yaml
|
278
|
-
# TODO Add configuration examples.
|
279
|
-
```
|
280
|
-
|
281
|
-
---
|
282
|
-
|
283
|
-
## Validation
|
284
|
-
|
285
|
-
Generated XML documents are checked for conformance against the schema used for generation.
|
286
|
-
By default, validation against the source XSD schema is used.
|
287
|
-
|
288
|
-
If a document does not conform to the schema, execution stops immediately.
|
289
|
-
This behavior can be disabled using the flag `-ff false` or `--fail-fast false`.
|
290
|
-
|
291
|
-
To disable validation, use the flag `-v none` or `--validation none`.
|
292
|
-
|
293
|
-
## Contribution
|
294
|
-
|
295
|
-
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
|
296
|
-
|
297
|
-
### Project Structure
|
298
|
-
|
299
|
-
- `xmlgenerator/` - main project code
|
300
|
-
- `tests/` - tests
|
301
|
-
|
302
|
-
### Running Tests
|
303
|
-
|
304
|
-
```bash
|
305
|
-
pytest
|
306
|
-
```
|
307
|
-
|
308
|
-
---
|
309
|
-
|
310
|
-
## License
|
311
|
-
|
312
|
-
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
313
|
-
|
314
|
-
## Contacts
|
315
|
-
|
316
|
-
For any questions or issues, please contact [lex.akimov23@gmail.com].
|
317
|
-
|
318
|
-
You can also create an [Issue on GitHub](https://github.com/lexakimov/xmlgenerator/issues) to report bugs or suggest
|
319
|
-
improvements.
|
@@ -1,14 +0,0 @@
|
|
1
|
-
xmlgenerator/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
xmlgenerator/arguments.py,sha256=Pf7Bccan0FeO6v5INpBkhLlGfJg-FGMRX5pG8E2KVgo,4834
|
3
|
-
xmlgenerator/bootstrap.py,sha256=T_Xy5PElb75EuyKIwXUGkQ2mntt3v2RwC1ulFI-CZnM,3654
|
4
|
-
xmlgenerator/configuration.py,sha256=JYhz_lONxd0faUiZHG-TVEs6yocn0s__Ulwtcvq9eDs,5946
|
5
|
-
xmlgenerator/generator.py,sha256=Qp0L4K37o5LrdDbg9l24jMY1MToRrshe6mkcNq1b2zQ,29245
|
6
|
-
xmlgenerator/randomization.py,sha256=azXW1SxKSA9_lw1IBQDPOwSUXFEXo8IGWFD0an-eVF0,4416
|
7
|
-
xmlgenerator/substitution.py,sha256=v4rzqnF1p1yN0VKRDFwQM5zQbpdg9ebbrh65cnh9qxw,6078
|
8
|
-
xmlgenerator/validation.py,sha256=uCJjS5YmRDlAp9C-5Rd4E2Brh6_3WOG2-dSGxDiaH14,2023
|
9
|
-
xmlgenerator-0.5.1.dist-info/licenses/LICENSE,sha256=QlXK8O3UcoAYUYwVJNgB9MSM7O94ogNo_1hd9GzznUQ,1070
|
10
|
-
xmlgenerator-0.5.1.dist-info/METADATA,sha256=UdsDphTVuCRdiWsr9IAP0cN9guCwZMImlvepUQyrpH4,13083
|
11
|
-
xmlgenerator-0.5.1.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
|
12
|
-
xmlgenerator-0.5.1.dist-info/entry_points.txt,sha256=ly9hKr3o4AzFUkelBZNRzyKYf-Ld4kfcffvBu1oHq54,61
|
13
|
-
xmlgenerator-0.5.1.dist-info/top_level.txt,sha256=jr7FbMBm8MQ6j8I_-nWzQQEseXzwSCZNXgrkWuk9P4E,13
|
14
|
-
xmlgenerator-0.5.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|