ovos-yaml-editor 0.0.1__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.

Potentially problematic release.


This version of ovos-yaml-editor might be problematic. Click here for more details.

@@ -0,0 +1,203 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2025 OpenVoiceOS
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
203
+
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.1
2
+ Name: ovos-yaml-editor
3
+ Version: 0.0.1
4
+ Summary: Simple YAML editor for OpenVoiceOS with FastAPI backend
5
+ Home-page: https://github.com/OpenVoiceOS/ovos-yaml-editor
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Operating System :: OS Independent
8
+ Requires-Python: >=3.9
9
+ License-File: LICENSE
@@ -0,0 +1,64 @@
1
+ # OpenVoiceOS YAML Config Editor
2
+
3
+ The **OpenVoiceOS Config Editor** is a web-based application for managing and editing the configuration files of OpenVoiceOS, supporting YAML and JSON formats. It provides an easy-to-use interface for modifying and saving configuration data, making it simple for users to adjust system settings.
4
+
5
+ It allows editing the configuration in two formats:
6
+ - **YAML**: This is the default format when the editor is opened.
7
+ - **JSON**: Users can switch to this format using the tabs in the editor.
8
+
9
+ ![](yaml.png)
10
+ ![](json.png)
11
+
12
+ ## Features
13
+
14
+ - **Authentication**: Password-protected editor with basic HTTP authentication.
15
+ - **Editor Interface**: Interactive editor with syntax highlighting for YAML and JSON formats, powered by CodeMirror.
16
+ - **Save and Reload**: Users can save changes to the configuration files and reload the current configuration into the editor.
17
+ - **Issue Reporting**: Direct link to report issues on GitHub.
18
+ - **Responsive UI**: Modern, clean user interface with tabs to switch between YAML and JSON formats.
19
+
20
+ ## Installation
21
+
22
+ 1. Clone the repository:
23
+ ```bash
24
+ git clone https://github.com/HiveMindInsiders/ovos-yaml-editor
25
+ pip install ./ovos-yaml-editor
26
+ ```
27
+ 2. Set up environment variables for authentication:
28
+ ```bash
29
+ export EDITOR_USERNAME="your_username"
30
+ export EDITOR_PASSWORD="your_password"
31
+ ```
32
+
33
+ (Defaults are "admin" and "password" if not set.)
34
+
35
+ ## Usage
36
+
37
+ ```bash
38
+ $ ovos-yaml-editor --help
39
+ Usage: ovos-yaml-editor [OPTIONS]
40
+
41
+ Run the OpenVoiceOS config editor Web UI.
42
+
43
+ Options:
44
+ --host TEXT Set to 0.0.0.0 to make externally accessible.
45
+ --port INTEGER Port to run the app on.
46
+ --help Show this message and exit.
47
+
48
+
49
+ $ ovos-yaml-editor --host "0.0.0.0" --port 9200
50
+ INFO: Started server process [2633268]
51
+ INFO: Waiting for application startup.
52
+ INFO: Application startup complete.
53
+ INFO: Uvicorn running on http://0.0.0.0:9200 (Press CTRL+C to quit)
54
+ ```
55
+
56
+ The application will be available at `http://localhost:9200`.
57
+
58
+
59
+ ## Authentication
60
+
61
+ The editor is protected with basic authentication. The username and password are fetched from environment variables `EDITOR_USERNAME` and `EDITOR_PASSWORD`. The default credentials are:
62
+ - **Username**: admin
63
+ - **Password**: password
64
+
@@ -0,0 +1,343 @@
1
+ import json
2
+ import os
3
+
4
+ import click
5
+ import yaml
6
+ from fastapi import FastAPI, Request, Response, Depends
7
+ from fastapi.responses import HTMLResponse, RedirectResponse
8
+ from fastapi.security import HTTPBasic, HTTPBasicCredentials
9
+ from ovos_config.config import Configuration, LocalConf, MycroftDefaultConfig
10
+ from ovos_config.locations import USER_CONFIG
11
+
12
+ app = FastAPI()
13
+
14
+ # Fetch username and password from environment variables
15
+ USER = os.getenv("EDITOR_USERNAME", "admin") # Default to "admin" if not set
16
+ PASSWORD = os.getenv("EDITOR_PASSWORD", "password") # Default to "password" if not set
17
+
18
+ security = HTTPBasic()
19
+
20
+
21
+ def authenticate(credentials: HTTPBasicCredentials = Depends(security)):
22
+ """Authenticate the user."""
23
+ if credentials.username == USER and credentials.password == PASSWORD:
24
+ return True
25
+ else:
26
+ return False
27
+
28
+
29
+ @app.get("/", response_class=HTMLResponse)
30
+ async def get_editor(credentials: HTTPBasicCredentials = Depends(authenticate)):
31
+ """Show the editor only if the user is authenticated."""
32
+ if not credentials:
33
+ return RedirectResponse(url="/login")
34
+
35
+ return """
36
+ <html>
37
+ <head>
38
+ <title>OpenVoiceOS Editor</title>
39
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/codemirror.min.css">
40
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
41
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/theme/darcula.min.css">
42
+ <style>
43
+ body {
44
+ font-family: Arial, sans-serif;
45
+ margin: 0;
46
+ background-color: #1e1e1e;
47
+ color: #f1f1f1;
48
+ height: 100vh;
49
+ display: flex;
50
+ flex-direction: column;
51
+ }
52
+ .header {
53
+ display: flex;
54
+ align-items: center;
55
+ padding: 20px;
56
+ background-color: #333;
57
+ justify-content: space-between;
58
+ }
59
+ .header img {
60
+ height: 40px;
61
+ margin-right: 10px;
62
+ }
63
+ .header h1 {
64
+ font-size: 24px;
65
+ margin: 0;
66
+ }
67
+ .button-container {
68
+ display: flex;
69
+ justify-content: flex-start;
70
+ gap: 10px;
71
+ margin-bottom: 10px;
72
+ }
73
+ button {
74
+ padding: 10px 15px;
75
+ font-size: 16px;
76
+ cursor: pointer;
77
+ background-color: #d32f2f; /* Red buttons */
78
+ color: white;
79
+ border: none;
80
+ border-radius: 4px;
81
+ }
82
+ #tabs {
83
+ display: flex;
84
+ gap: 10px;
85
+ margin-bottom: 10px;
86
+ }
87
+ #tabs button {
88
+ padding: 10px 20px;
89
+ background-color: #333;
90
+ color: white;
91
+ border: 1px solid #ccc;
92
+ cursor: pointer;
93
+ }
94
+ #tabs button.active {
95
+ background-color: #4CAF50;
96
+ }
97
+ #editor {
98
+ flex-grow: 1;
99
+ border: 1px solid #ccc;
100
+ }
101
+ .CodeMirror {
102
+ background-color: #1e1e1e;
103
+ color: #f1f1f1;
104
+ height: 100%;
105
+ }
106
+ .CodeMirror-gutters {
107
+ background-color: #1e1e1e;
108
+ border-right: 1px solid #ccc;
109
+ }
110
+ footer {
111
+ background-color: #333;
112
+ color: #f1f1f1;
113
+ padding: 10px;
114
+ text-align: center;
115
+ font-size: 14px;
116
+ }
117
+ footer a {
118
+ color: #4CAF50;
119
+ text-decoration: none;
120
+ }
121
+
122
+ button:disabled {
123
+ background-color: #d3d3d3; /* Light grey */
124
+ cursor: not-allowed;
125
+ }
126
+ .CodeMirror .cm-keyword {
127
+ color: #c586c0;
128
+ }
129
+ .CodeMirror .cm-string {
130
+ color: #ce9178;
131
+ }
132
+ .CodeMirror .cm-number {
133
+ color: #b5cea8;
134
+ }
135
+ .CodeMirror .cm-variable {
136
+ color: #9cdcfe;
137
+ }
138
+ .CodeMirror .cm-variable-2 {
139
+ color: #c586c0;
140
+ }
141
+ .CodeMirror .cm-variable-3 {
142
+ color: #9cdcfe;
143
+ }
144
+ .CodeMirror .cm-def {
145
+ color: #4ec9b0;
146
+ }
147
+ .CodeMirror .cm-comment {
148
+ color: #6a9955;
149
+ }
150
+ .CodeMirror .cm-error {
151
+ color: #f44747;
152
+ background-color: #ff000030;
153
+ }
154
+
155
+ </style>
156
+ </head>
157
+ <body>
158
+ <div class="header">
159
+ <div>
160
+ <img src="https://www.openvoiceos.org/_next/static/media/logo.02220a9b.png" alt="OpenVoiceOS Logo">
161
+ <h1>OpenVoiceOS Config Editor</h1>
162
+ </div>
163
+ <div class="button-container">
164
+ <button onclick="reloadConfig()"><i class="fas fa-sync-alt"></i> Reload</button>
165
+ <button onclick="saveConfig()" id="saveButton"><i class="fas fa-save"></i> Save</button>
166
+ <button onclick="resetConfig()"><i class="fas fa-undo"></i> Reset Config</button>
167
+ <button onclick="reportIssue()"><i class="fas fa-exclamation-circle"></i> Report Issue</button>
168
+ </div>
169
+ </div>
170
+
171
+ <div id="tabs">
172
+ <button class="active" onclick="switchTab('yaml')">YAML</button>
173
+ <button onclick="switchTab('json')">JSON</button>
174
+ </div>
175
+
176
+ <div id="editor"></div>
177
+
178
+ <footer>
179
+ <p>© 2025 OpenVoiceOS. <a href="https://github.com/OpenVoiceOS/ovos-yaml-editor">GitHub</a> | <a href="https://github.com/OpenVoiceOS/ovos-yaml-editor/blob/main/LICENSE">Apache 2.0 License</a></p>
180
+ </footer>
181
+
182
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/codemirror.min.js"></script>
183
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/mode/yaml/yaml.min.js"></script>
184
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/mode/javascript/javascript.min.js"></script>
185
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/mode/javascript/json.min.js"></script>
186
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js"></script>
187
+ <script>
188
+
189
+ let editor;
190
+
191
+ function initEditor(mode) {
192
+ editor = CodeMirror(document.getElementById('editor'), {
193
+ lineNumbers: true,
194
+ gutters: ["CodeMirror-linenumbers", "CodeMirror-lint-markers"],
195
+ mode: mode === 'yaml' ? "yaml" : { name: "javascript", json: true },
196
+ theme: "darcula",
197
+ tabSize: 2,
198
+ lint: true,
199
+ lintOnChange: true,
200
+ lintOptions: {
201
+ onUpdateLinting: (annotations, _, doc) => {
202
+ const errors = annotations.filter(a => a.severity === 'error');
203
+ console.log("Linting errors: ", errors); // Debugging line
204
+ if (errors.length > 0) {
205
+ document.getElementById('saveButton').disabled = true;
206
+ } else {
207
+ document.getElementById('saveButton').disabled = false;
208
+ }
209
+ }
210
+ }
211
+ });
212
+ }
213
+
214
+
215
+ function switchTab(tab) {
216
+ document.querySelectorAll("#tabs button").forEach(button => button.classList.remove("active"));
217
+ document.querySelector(`#tabs button:nth-child(${tab === 'yaml' ? 1 : 2})`).classList.add("active");
218
+ editor.setOption("mode", tab === 'yaml' ? "yaml" : "application/json");
219
+ reloadConfig(tab);
220
+ }
221
+
222
+ // Fetch the current config and load it into the editor
223
+ async function reloadConfig() {
224
+ const format = editor.getOption("mode") === "yaml" ? "yaml" : "json";
225
+ const response = await fetch(`/config/${format}`);
226
+ const config = await response.text();
227
+ editor.setValue(config);
228
+ }
229
+
230
+ // Save the content of the editor
231
+ async function saveConfig() {
232
+ const data = editor.getValue();
233
+ const format = editor.getOption("mode") === "yaml" ? "yaml" : "json";
234
+ const response = await fetch("/config", {
235
+ method: "POST",
236
+ headers: {
237
+ "Content-Type": "application/json"
238
+ },
239
+ body: JSON.stringify({ data: data, format: format })
240
+ });
241
+ const result = await response.json();
242
+ if (result.success) {
243
+ alert("Config saved successfully!");
244
+ } else {
245
+ alert("Error saving config: " + result.error);
246
+ }
247
+ }
248
+
249
+ async function resetConfig() {
250
+ if (!confirm("Are you sure you want to reset the config to default? This cannot be undone.")) return;
251
+
252
+ const response = await fetch("/config/reset", {
253
+ method: "POST"
254
+ });
255
+
256
+ const result = await response.json();
257
+ if (result.success) {
258
+ alert("Config has been reset to default.");
259
+ reloadConfig(); // Refresh the editor with new config
260
+ } else {
261
+ alert("Error resetting config: " + result.error);
262
+ }
263
+ }
264
+
265
+ // Report issue function
266
+ function reportIssue() {
267
+ window.open("https://github.com/OpenVoiceOS/ovos-yaml-editor/issues", "_blank");
268
+ }
269
+
270
+ // Initialize the editor with YAML mode
271
+ window.onload = () => {
272
+ initEditor("yaml");
273
+ reloadConfig('yaml');
274
+ };
275
+ </script>
276
+ </body>
277
+ </html>
278
+ """
279
+
280
+
281
+ # Endpoint to get the config as YAML or JSON based on the tab selected
282
+ @app.get("/config/{format}")
283
+ async def get_config(format: str):
284
+ config = Configuration()
285
+ if format == "json":
286
+ return Response(json.dumps(config, indent=2, ensure_ascii=False), media_type="text/plain")
287
+ elif format == "yaml":
288
+ return Response(yaml.dump(dict(config), default_flow_style=False, sort_keys=False), media_type="text/plain")
289
+ else:
290
+ return {"success": False, "error": "Unsupported format"}
291
+
292
+
293
+ @app.post("/config")
294
+ async def save_config_post(request: Request):
295
+ body = await request.json()
296
+ try:
297
+ data = body.get("data", "")
298
+ format = body.get("format", "yaml")
299
+
300
+ try:
301
+ if format == 'yaml':
302
+ data = yaml.safe_load(data)
303
+ else:
304
+ data = json.loads(data)
305
+ except Exception as e:
306
+ return {"success": False, "error": str(e)}
307
+
308
+ conf = LocalConf(USER_CONFIG)
309
+ default_conf = MycroftDefaultConfig()
310
+ for k, v in data.items():
311
+ v2 = default_conf.get(k)
312
+ # only save to file any value that differs from default config
313
+ if v2 is None or v != v2:
314
+ conf[k] = v
315
+ conf.store()
316
+ return {"success": True}
317
+ except Exception as e:
318
+ return {"success": False, "error": f"Failed to save config: {e}"}
319
+
320
+
321
+ @app.post("/config/reset")
322
+ async def reset_config_post(request: Request):
323
+ try:
324
+ conf = LocalConf(USER_CONFIG)
325
+ conf.clear()
326
+ conf.store()
327
+ Configuration.reload()
328
+ return {"success": True}
329
+ except Exception as e:
330
+ return {"success": False, "error": f"Failed to save config: {e}"}
331
+
332
+
333
+ @click.command()
334
+ @click.option('--host', default='127.0.0.1', help='Set to 0.0.0.0 to make externally accessible.')
335
+ @click.option('--port', default=9210, type=int, help='Port to run the app on.')
336
+ def main(host, port):
337
+ """Run the OpenVoiceOS config editor Web UI."""
338
+ import uvicorn
339
+ uvicorn.run(app, host=host, port=port)
340
+
341
+
342
+ if __name__ == "__main__":
343
+ main()
@@ -0,0 +1,6 @@
1
+ # START_VERSION_BLOCK
2
+ VERSION_MAJOR = 0
3
+ VERSION_MINOR = 0
4
+ VERSION_BUILD = 1
5
+ VERSION_ALPHA = 0
6
+ # END_VERSION_BLOCK
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.1
2
+ Name: ovos-yaml-editor
3
+ Version: 0.0.1
4
+ Summary: Simple YAML editor for OpenVoiceOS with FastAPI backend
5
+ Home-page: https://github.com/OpenVoiceOS/ovos-yaml-editor
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Operating System :: OS Independent
8
+ Requires-Python: >=3.9
9
+ License-File: LICENSE
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ ovos_yaml_editor/__init__.py
5
+ ovos_yaml_editor/version.py
6
+ ovos_yaml_editor.egg-info/PKG-INFO
7
+ ovos_yaml_editor.egg-info/SOURCES.txt
8
+ ovos_yaml_editor.egg-info/dependency_links.txt
9
+ ovos_yaml_editor.egg-info/entry_points.txt
10
+ ovos_yaml_editor.egg-info/requires.txt
11
+ ovos_yaml_editor.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ovos-yaml-editor = ovos_yaml_editor:main
@@ -0,0 +1,4 @@
1
+ fastapi
2
+ pyyaml
3
+ uvicorn
4
+ ovos-config
@@ -0,0 +1 @@
1
+ ovos_yaml_editor
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,60 @@
1
+ from setuptools import setup, find_packages
2
+ import os
3
+
4
+
5
+ BASEDIR = os.path.abspath(os.path.dirname(__file__))
6
+
7
+
8
+ def get_version():
9
+ version_file = os.path.join(BASEDIR, 'ovos_yaml_editor', 'version.py')
10
+ major, minor, build, alpha = (None, None, None, None)
11
+ with open(version_file) as f:
12
+ for line in f:
13
+ if 'VERSION_MAJOR' in line:
14
+ major = line.split('=')[1].strip()
15
+ elif 'VERSION_MINOR' in line:
16
+ minor = line.split('=')[1].strip()
17
+ elif 'VERSION_BUILD' in line:
18
+ build = line.split('=')[1].strip()
19
+ elif 'VERSION_ALPHA' in line:
20
+ alpha = line.split('=')[1].strip()
21
+
22
+ if ((major and minor and build and alpha) or
23
+ '# END_VERSION_BLOCK' in line):
24
+ break
25
+ version = f"{major}.{minor}.{build}"
26
+ if int(alpha):
27
+ version += f"a{alpha}"
28
+ return version
29
+
30
+
31
+ def required(requirements_file):
32
+ """ Read requirements file and remove comments and empty lines. """
33
+ with open(os.path.join(BASEDIR, requirements_file), 'r') as f:
34
+ requirements = f.read().splitlines()
35
+ if 'MYCROFT_LOOSE_REQUIREMENTS' in os.environ:
36
+ print('USING LOOSE REQUIREMENTS!')
37
+ requirements = [r.replace('==', '>=').replace('~=', '>=') for r in requirements]
38
+ return [pkg for pkg in requirements
39
+ if pkg.strip() and not pkg.startswith("#")]
40
+
41
+
42
+
43
+ setup(
44
+ name="ovos-yaml-editor",
45
+ version=get_version(),
46
+ description="Simple YAML editor for OpenVoiceOS with FastAPI backend",
47
+ url="https://github.com/OpenVoiceOS/ovos-yaml-editor",
48
+ packages=find_packages(),
49
+ install_requires=required('requirements.txt'),
50
+ entry_points={
51
+ "console_scripts": [
52
+ "ovos-yaml-editor = ovos_yaml_editor:main"
53
+ ]
54
+ },
55
+ classifiers=[
56
+ "Programming Language :: Python :: 3",
57
+ "Operating System :: OS Independent",
58
+ ],
59
+ python_requires=">=3.9",
60
+ )