mycelium-ai 0.5.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.
Files changed (164) hide show
  1. mycelium/__init__.py +0 -0
  2. mycelium/api/__init__.py +0 -0
  3. mycelium/api/app.py +1147 -0
  4. mycelium/api/client_app.py +170 -0
  5. mycelium/api/generated_sources/__init__.py +0 -0
  6. mycelium/api/generated_sources/server_schemas/__init__.py +97 -0
  7. mycelium/api/generated_sources/server_schemas/api/__init__.py +5 -0
  8. mycelium/api/generated_sources/server_schemas/api/default_api.py +2473 -0
  9. mycelium/api/generated_sources/server_schemas/api_client.py +766 -0
  10. mycelium/api/generated_sources/server_schemas/api_response.py +25 -0
  11. mycelium/api/generated_sources/server_schemas/configuration.py +434 -0
  12. mycelium/api/generated_sources/server_schemas/exceptions.py +166 -0
  13. mycelium/api/generated_sources/server_schemas/models/__init__.py +41 -0
  14. mycelium/api/generated_sources/server_schemas/models/api_section.py +71 -0
  15. mycelium/api/generated_sources/server_schemas/models/chroma_section.py +69 -0
  16. mycelium/api/generated_sources/server_schemas/models/clap_section.py +75 -0
  17. mycelium/api/generated_sources/server_schemas/models/compute_on_server200_response.py +79 -0
  18. mycelium/api/generated_sources/server_schemas/models/compute_on_server_request.py +67 -0
  19. mycelium/api/generated_sources/server_schemas/models/compute_text_search_request.py +69 -0
  20. mycelium/api/generated_sources/server_schemas/models/config_request.py +81 -0
  21. mycelium/api/generated_sources/server_schemas/models/config_response.py +107 -0
  22. mycelium/api/generated_sources/server_schemas/models/create_playlist_request.py +71 -0
  23. mycelium/api/generated_sources/server_schemas/models/get_similar_by_track200_response.py +143 -0
  24. mycelium/api/generated_sources/server_schemas/models/library_stats_response.py +77 -0
  25. mycelium/api/generated_sources/server_schemas/models/logging_section.py +67 -0
  26. mycelium/api/generated_sources/server_schemas/models/media_server_section.py +67 -0
  27. mycelium/api/generated_sources/server_schemas/models/playlist_response.py +73 -0
  28. mycelium/api/generated_sources/server_schemas/models/plex_section.py +71 -0
  29. mycelium/api/generated_sources/server_schemas/models/processing_response.py +90 -0
  30. mycelium/api/generated_sources/server_schemas/models/save_config_response.py +73 -0
  31. mycelium/api/generated_sources/server_schemas/models/scan_library_response.py +75 -0
  32. mycelium/api/generated_sources/server_schemas/models/search_result_response.py +75 -0
  33. mycelium/api/generated_sources/server_schemas/models/server_section.py +67 -0
  34. mycelium/api/generated_sources/server_schemas/models/stop_processing_response.py +71 -0
  35. mycelium/api/generated_sources/server_schemas/models/task_status_response.py +87 -0
  36. mycelium/api/generated_sources/server_schemas/models/track_database_stats.py +75 -0
  37. mycelium/api/generated_sources/server_schemas/models/track_response.py +77 -0
  38. mycelium/api/generated_sources/server_schemas/models/tracks_list_response.py +81 -0
  39. mycelium/api/generated_sources/server_schemas/rest.py +329 -0
  40. mycelium/api/generated_sources/server_schemas/test/__init__.py +0 -0
  41. mycelium/api/generated_sources/server_schemas/test/test_api_section.py +57 -0
  42. mycelium/api/generated_sources/server_schemas/test/test_chroma_section.py +55 -0
  43. mycelium/api/generated_sources/server_schemas/test/test_clap_section.py +60 -0
  44. mycelium/api/generated_sources/server_schemas/test/test_compute_on_server200_response.py +52 -0
  45. mycelium/api/generated_sources/server_schemas/test/test_compute_on_server_request.py +53 -0
  46. mycelium/api/generated_sources/server_schemas/test/test_compute_text_search_request.py +54 -0
  47. mycelium/api/generated_sources/server_schemas/test/test_config_request.py +66 -0
  48. mycelium/api/generated_sources/server_schemas/test/test_config_response.py +97 -0
  49. mycelium/api/generated_sources/server_schemas/test/test_create_playlist_request.py +60 -0
  50. mycelium/api/generated_sources/server_schemas/test/test_default_api.py +150 -0
  51. mycelium/api/generated_sources/server_schemas/test/test_get_similar_by_track200_response.py +61 -0
  52. mycelium/api/generated_sources/server_schemas/test/test_library_stats_response.py +63 -0
  53. mycelium/api/generated_sources/server_schemas/test/test_logging_section.py +53 -0
  54. mycelium/api/generated_sources/server_schemas/test/test_media_server_section.py +53 -0
  55. mycelium/api/generated_sources/server_schemas/test/test_playlist_response.py +58 -0
  56. mycelium/api/generated_sources/server_schemas/test/test_plex_section.py +56 -0
  57. mycelium/api/generated_sources/server_schemas/test/test_processing_response.py +61 -0
  58. mycelium/api/generated_sources/server_schemas/test/test_save_config_response.py +58 -0
  59. mycelium/api/generated_sources/server_schemas/test/test_scan_library_response.py +61 -0
  60. mycelium/api/generated_sources/server_schemas/test/test_search_result_response.py +69 -0
  61. mycelium/api/generated_sources/server_schemas/test/test_server_section.py +53 -0
  62. mycelium/api/generated_sources/server_schemas/test/test_stop_processing_response.py +55 -0
  63. mycelium/api/generated_sources/server_schemas/test/test_task_status_response.py +71 -0
  64. mycelium/api/generated_sources/server_schemas/test/test_track_database_stats.py +60 -0
  65. mycelium/api/generated_sources/server_schemas/test/test_track_response.py +63 -0
  66. mycelium/api/generated_sources/server_schemas/test/test_tracks_list_response.py +75 -0
  67. mycelium/api/generated_sources/worker_schemas/__init__.py +61 -0
  68. mycelium/api/generated_sources/worker_schemas/api/__init__.py +5 -0
  69. mycelium/api/generated_sources/worker_schemas/api/default_api.py +318 -0
  70. mycelium/api/generated_sources/worker_schemas/api_client.py +766 -0
  71. mycelium/api/generated_sources/worker_schemas/api_response.py +25 -0
  72. mycelium/api/generated_sources/worker_schemas/configuration.py +434 -0
  73. mycelium/api/generated_sources/worker_schemas/exceptions.py +166 -0
  74. mycelium/api/generated_sources/worker_schemas/models/__init__.py +23 -0
  75. mycelium/api/generated_sources/worker_schemas/models/save_config_response.py +73 -0
  76. mycelium/api/generated_sources/worker_schemas/models/worker_clap_section.py +75 -0
  77. mycelium/api/generated_sources/worker_schemas/models/worker_client_api_section.py +69 -0
  78. mycelium/api/generated_sources/worker_schemas/models/worker_client_section.py +79 -0
  79. mycelium/api/generated_sources/worker_schemas/models/worker_config_request.py +73 -0
  80. mycelium/api/generated_sources/worker_schemas/models/worker_config_response.py +89 -0
  81. mycelium/api/generated_sources/worker_schemas/models/worker_logging_section.py +67 -0
  82. mycelium/api/generated_sources/worker_schemas/rest.py +329 -0
  83. mycelium/api/generated_sources/worker_schemas/test/__init__.py +0 -0
  84. mycelium/api/generated_sources/worker_schemas/test/test_default_api.py +45 -0
  85. mycelium/api/generated_sources/worker_schemas/test/test_save_config_response.py +58 -0
  86. mycelium/api/generated_sources/worker_schemas/test/test_worker_clap_section.py +60 -0
  87. mycelium/api/generated_sources/worker_schemas/test/test_worker_client_api_section.py +55 -0
  88. mycelium/api/generated_sources/worker_schemas/test/test_worker_client_section.py +65 -0
  89. mycelium/api/generated_sources/worker_schemas/test/test_worker_config_request.py +59 -0
  90. mycelium/api/generated_sources/worker_schemas/test/test_worker_config_response.py +89 -0
  91. mycelium/api/generated_sources/worker_schemas/test/test_worker_logging_section.py +53 -0
  92. mycelium/api/worker_models.py +99 -0
  93. mycelium/application/__init__.py +11 -0
  94. mycelium/application/job_queue.py +323 -0
  95. mycelium/application/library_management_use_cases.py +292 -0
  96. mycelium/application/search_use_cases.py +96 -0
  97. mycelium/application/services.py +340 -0
  98. mycelium/client.py +554 -0
  99. mycelium/client_config.py +251 -0
  100. mycelium/client_frontend_dist/404.html +1 -0
  101. mycelium/client_frontend_dist/_next/static/a4iyRdfsvkjdyMAK9cE9Y/_buildManifest.js +1 -0
  102. mycelium/client_frontend_dist/_next/static/a4iyRdfsvkjdyMAK9cE9Y/_ssgManifest.js +1 -0
  103. mycelium/client_frontend_dist/_next/static/chunks/4bd1b696-cf72ae8a39fa05aa.js +1 -0
  104. mycelium/client_frontend_dist/_next/static/chunks/964-830f77d7ce1c2463.js +1 -0
  105. mycelium/client_frontend_dist/_next/static/chunks/app/_not-found/page-d25eede5a9099bd3.js +1 -0
  106. mycelium/client_frontend_dist/_next/static/chunks/app/layout-9b3d32f96dfe13b6.js +1 -0
  107. mycelium/client_frontend_dist/_next/static/chunks/app/page-cc6bad295789134e.js +1 -0
  108. mycelium/client_frontend_dist/_next/static/chunks/framework-7c95b8e5103c9e90.js +1 -0
  109. mycelium/client_frontend_dist/_next/static/chunks/main-6b37be50736577a2.js +1 -0
  110. mycelium/client_frontend_dist/_next/static/chunks/main-app-4153d115599d3126.js +1 -0
  111. mycelium/client_frontend_dist/_next/static/chunks/pages/_app-0a0020ddd67f79cf.js +1 -0
  112. mycelium/client_frontend_dist/_next/static/chunks/pages/_error-03529f2c21436739.js +1 -0
  113. mycelium/client_frontend_dist/_next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  114. mycelium/client_frontend_dist/_next/static/chunks/webpack-c81e624915b2ea70.js +1 -0
  115. mycelium/client_frontend_dist/_next/static/css/1eb7f0e2c78e0734.css +1 -0
  116. mycelium/client_frontend_dist/favicon.ico +0 -0
  117. mycelium/client_frontend_dist/file.svg +1 -0
  118. mycelium/client_frontend_dist/globe.svg +1 -0
  119. mycelium/client_frontend_dist/index.html +1 -0
  120. mycelium/client_frontend_dist/index.txt +20 -0
  121. mycelium/client_frontend_dist/next.svg +1 -0
  122. mycelium/client_frontend_dist/vercel.svg +1 -0
  123. mycelium/client_frontend_dist/window.svg +1 -0
  124. mycelium/config.py +346 -0
  125. mycelium/domain/__init__.py +13 -0
  126. mycelium/domain/models.py +71 -0
  127. mycelium/domain/repositories.py +98 -0
  128. mycelium/domain/worker.py +77 -0
  129. mycelium/frontend_dist/404.html +1 -0
  130. mycelium/frontend_dist/_next/static/chunks/4bd1b696-cf72ae8a39fa05aa.js +1 -0
  131. mycelium/frontend_dist/_next/static/chunks/964-830f77d7ce1c2463.js +1 -0
  132. mycelium/frontend_dist/_next/static/chunks/app/_not-found/page-d25eede5a9099bd3.js +1 -0
  133. mycelium/frontend_dist/_next/static/chunks/app/layout-9b3d32f96dfe13b6.js +1 -0
  134. mycelium/frontend_dist/_next/static/chunks/app/page-a761463485e0540b.js +1 -0
  135. mycelium/frontend_dist/_next/static/chunks/framework-7c95b8e5103c9e90.js +1 -0
  136. mycelium/frontend_dist/_next/static/chunks/main-6b37be50736577a2.js +1 -0
  137. mycelium/frontend_dist/_next/static/chunks/main-app-4153d115599d3126.js +1 -0
  138. mycelium/frontend_dist/_next/static/chunks/pages/_app-0a0020ddd67f79cf.js +1 -0
  139. mycelium/frontend_dist/_next/static/chunks/pages/_error-03529f2c21436739.js +1 -0
  140. mycelium/frontend_dist/_next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  141. mycelium/frontend_dist/_next/static/chunks/webpack-c81e624915b2ea70.js +1 -0
  142. mycelium/frontend_dist/_next/static/css/1eb7f0e2c78e0734.css +1 -0
  143. mycelium/frontend_dist/_next/static/glVJ0yJSL0zWN7anTTG3_/_buildManifest.js +1 -0
  144. mycelium/frontend_dist/_next/static/glVJ0yJSL0zWN7anTTG3_/_ssgManifest.js +1 -0
  145. mycelium/frontend_dist/favicon.ico +0 -0
  146. mycelium/frontend_dist/file.svg +1 -0
  147. mycelium/frontend_dist/globe.svg +1 -0
  148. mycelium/frontend_dist/index.html +10 -0
  149. mycelium/frontend_dist/index.txt +20 -0
  150. mycelium/frontend_dist/next.svg +1 -0
  151. mycelium/frontend_dist/vercel.svg +1 -0
  152. mycelium/frontend_dist/window.svg +1 -0
  153. mycelium/infrastructure/__init__.py +17 -0
  154. mycelium/infrastructure/chroma_adapter.py +232 -0
  155. mycelium/infrastructure/clap_adapter.py +280 -0
  156. mycelium/infrastructure/plex_adapter.py +145 -0
  157. mycelium/infrastructure/track_database.py +467 -0
  158. mycelium/main.py +183 -0
  159. mycelium_ai-0.5.0.dist-info/METADATA +312 -0
  160. mycelium_ai-0.5.0.dist-info/RECORD +164 -0
  161. mycelium_ai-0.5.0.dist-info/WHEEL +5 -0
  162. mycelium_ai-0.5.0.dist-info/entry_points.txt +2 -0
  163. mycelium_ai-0.5.0.dist-info/licenses/LICENSE +21 -0
  164. mycelium_ai-0.5.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,25 @@
1
+ """API response object."""
2
+
3
+ from __future__ import annotations
4
+ from typing import Any, Dict, Optional
5
+ from pydantic import Field, StrictInt, StrictStr
6
+
7
+ class ApiResponse:
8
+ """
9
+ API response object
10
+ """
11
+
12
+ status_code: Optional[StrictInt] = Field(None, description="HTTP status code")
13
+ headers: Optional[Dict[StrictStr, StrictStr]] = Field(None, description="HTTP headers")
14
+ data: Optional[Any] = Field(None, description="Deserialized data given the data type")
15
+ raw_data: Optional[Any] = Field(None, description="Raw data (HTTP response body)")
16
+
17
+ def __init__(self,
18
+ status_code=None,
19
+ headers=None,
20
+ data=None,
21
+ raw_data=None) -> None:
22
+ self.status_code = status_code
23
+ self.headers = headers
24
+ self.data = data
25
+ self.raw_data = raw_data
@@ -0,0 +1,434 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Mycelium Worker (Client) API
5
+
6
+ Configuration API for Mycelium client workers
7
+
8
+ The version of the OpenAPI document: 0.1.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ import copy
16
+ import logging
17
+ import multiprocessing
18
+ import sys
19
+ import urllib3
20
+
21
+ import http.client as httplib
22
+
23
+ JSON_SCHEMA_VALIDATION_KEYWORDS = {
24
+ 'multipleOf', 'maximum', 'exclusiveMaximum',
25
+ 'minimum', 'exclusiveMinimum', 'maxLength',
26
+ 'minLength', 'pattern', 'maxItems', 'minItems'
27
+ }
28
+
29
+ class Configuration:
30
+ """This class contains various settings of the API client.
31
+
32
+ :param host: Base url.
33
+ :param api_key: Dict to store API key(s).
34
+ Each entry in the dict specifies an API key.
35
+ The dict key is the name of the security scheme in the OAS specification.
36
+ The dict value is the API key secret.
37
+ :param api_key_prefix: Dict to store API prefix (e.g. Bearer).
38
+ The dict key is the name of the security scheme in the OAS specification.
39
+ The dict value is an API key prefix when generating the auth data.
40
+ :param username: Username for HTTP basic authentication.
41
+ :param password: Password for HTTP basic authentication.
42
+ :param access_token: Access token.
43
+ :param server_index: Index to servers configuration.
44
+ :param server_variables: Mapping with string values to replace variables in
45
+ templated server configuration. The validation of enums is performed for
46
+ variables with defined enum values before.
47
+ :param server_operation_index: Mapping from operation ID to an index to server
48
+ configuration.
49
+ :param server_operation_variables: Mapping from operation ID to a mapping with
50
+ string values to replace variables in templated server configuration.
51
+ The validation of enums is performed for variables with defined enum
52
+ values before.
53
+ :param ssl_ca_cert: str - the path to a file of concatenated CA certificates
54
+ in PEM format.
55
+
56
+ """
57
+
58
+ _default = None
59
+
60
+ def __init__(self, host=None,
61
+ api_key=None, api_key_prefix=None,
62
+ username=None, password=None,
63
+ access_token=None,
64
+ server_index=None, server_variables=None,
65
+ server_operation_index=None, server_operation_variables=None,
66
+ ssl_ca_cert=None,
67
+ ) -> None:
68
+ """Constructor
69
+ """
70
+ self._base_path = "http://localhost:8001" if host is None else host
71
+ """Default Base url
72
+ """
73
+ self.server_index = 0 if server_index is None and host is None else server_index
74
+ self.server_operation_index = server_operation_index or {}
75
+ """Default server index
76
+ """
77
+ self.server_variables = server_variables or {}
78
+ self.server_operation_variables = server_operation_variables or {}
79
+ """Default server variables
80
+ """
81
+ self.temp_folder_path = None
82
+ """Temp file folder for downloading files
83
+ """
84
+ # Authentication Settings
85
+ self.api_key = {}
86
+ if api_key:
87
+ self.api_key = api_key
88
+ """dict to store API key(s)
89
+ """
90
+ self.api_key_prefix = {}
91
+ if api_key_prefix:
92
+ self.api_key_prefix = api_key_prefix
93
+ """dict to store API prefix (e.g. Bearer)
94
+ """
95
+ self.refresh_api_key_hook = None
96
+ """function hook to refresh API key if expired
97
+ """
98
+ self.username = username
99
+ """Username for HTTP basic authentication
100
+ """
101
+ self.password = password
102
+ """Password for HTTP basic authentication
103
+ """
104
+ self.access_token = access_token
105
+ """Access token
106
+ """
107
+ self.logger = {}
108
+ """Logging Settings
109
+ """
110
+ self.logger["package_logger"] = logging.getLogger("mycelium.api.generated_sources.worker_schemas")
111
+ self.logger["urllib3_logger"] = logging.getLogger("urllib3")
112
+ self.logger_format = '%(asctime)s %(levelname)s %(message)s'
113
+ """Log format
114
+ """
115
+ self.logger_stream_handler = None
116
+ """Log stream handler
117
+ """
118
+ self.logger_file_handler = None
119
+ """Log file handler
120
+ """
121
+ self.logger_file = None
122
+ """Debug file location
123
+ """
124
+ self.debug = False
125
+ """Debug switch
126
+ """
127
+
128
+ self.verify_ssl = True
129
+ """SSL/TLS verification
130
+ Set this to false to skip verifying SSL certificate when calling API
131
+ from https server.
132
+ """
133
+ self.ssl_ca_cert = ssl_ca_cert
134
+ """Set this to customize the certificate file to verify the peer.
135
+ """
136
+ self.cert_file = None
137
+ """client certificate file
138
+ """
139
+ self.key_file = None
140
+ """client key file
141
+ """
142
+ self.assert_hostname = None
143
+ """Set this to True/False to enable/disable SSL hostname verification.
144
+ """
145
+ self.tls_server_name = None
146
+ """SSL/TLS Server Name Indication (SNI)
147
+ Set this to the SNI value expected by the server.
148
+ """
149
+
150
+ self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
151
+ """urllib3 connection pool's maximum number of connections saved
152
+ per pool. urllib3 uses 1 connection as default value, but this is
153
+ not the best value when you are making a lot of possibly parallel
154
+ requests to the same host, which is often the case here.
155
+ cpu_count * 5 is used as default value to increase performance.
156
+ """
157
+
158
+ self.proxy = None
159
+ """Proxy URL
160
+ """
161
+ self.proxy_headers = None
162
+ """Proxy headers
163
+ """
164
+ self.safe_chars_for_path_param = ''
165
+ """Safe chars for path_param
166
+ """
167
+ self.retries = None
168
+ """Adding retries to override urllib3 default value 3
169
+ """
170
+ # Enable client side validation
171
+ self.client_side_validation = True
172
+
173
+ self.socket_options = None
174
+ """Options to pass down to the underlying urllib3 socket
175
+ """
176
+
177
+ self.datetime_format = "%Y-%m-%dT%H:%M:%S.%f%z"
178
+ """datetime format
179
+ """
180
+
181
+ self.date_format = "%Y-%m-%d"
182
+ """date format
183
+ """
184
+
185
+ def __deepcopy__(self, memo):
186
+ cls = self.__class__
187
+ result = cls.__new__(cls)
188
+ memo[id(self)] = result
189
+ for k, v in self.__dict__.items():
190
+ if k not in ('logger', 'logger_file_handler'):
191
+ setattr(result, k, copy.deepcopy(v, memo))
192
+ # shallow copy of loggers
193
+ result.logger = copy.copy(self.logger)
194
+ # use setters to configure loggers
195
+ result.logger_file = self.logger_file
196
+ result.debug = self.debug
197
+ return result
198
+
199
+ def __setattr__(self, name, value):
200
+ object.__setattr__(self, name, value)
201
+
202
+ @classmethod
203
+ def set_default(cls, default):
204
+ """Set default instance of configuration.
205
+
206
+ It stores default configuration, which can be
207
+ returned by get_default_copy method.
208
+
209
+ :param default: object of Configuration
210
+ """
211
+ cls._default = default
212
+
213
+ @classmethod
214
+ def get_default_copy(cls):
215
+ """Deprecated. Please use `get_default` instead.
216
+
217
+ Deprecated. Please use `get_default` instead.
218
+
219
+ :return: The configuration object.
220
+ """
221
+ return cls.get_default()
222
+
223
+ @classmethod
224
+ def get_default(cls):
225
+ """Return the default configuration.
226
+
227
+ This method returns newly created, based on default constructor,
228
+ object of Configuration class or returns a copy of default
229
+ configuration.
230
+
231
+ :return: The configuration object.
232
+ """
233
+ if cls._default is None:
234
+ cls._default = Configuration()
235
+ return cls._default
236
+
237
+ @property
238
+ def logger_file(self):
239
+ """The logger file.
240
+
241
+ If the logger_file is None, then add stream handler and remove file
242
+ handler. Otherwise, add file handler and remove stream handler.
243
+
244
+ :param value: The logger_file path.
245
+ :type: str
246
+ """
247
+ return self.__logger_file
248
+
249
+ @logger_file.setter
250
+ def logger_file(self, value):
251
+ """The logger file.
252
+
253
+ If the logger_file is None, then add stream handler and remove file
254
+ handler. Otherwise, add file handler and remove stream handler.
255
+
256
+ :param value: The logger_file path.
257
+ :type: str
258
+ """
259
+ self.__logger_file = value
260
+ if self.__logger_file:
261
+ # If set logging file,
262
+ # then add file handler and remove stream handler.
263
+ self.logger_file_handler = logging.FileHandler(self.__logger_file)
264
+ self.logger_file_handler.setFormatter(self.logger_formatter)
265
+ for _, logger in self.logger.items():
266
+ logger.addHandler(self.logger_file_handler)
267
+
268
+ @property
269
+ def debug(self):
270
+ """Debug status
271
+
272
+ :param value: The debug status, True or False.
273
+ :type: bool
274
+ """
275
+ return self.__debug
276
+
277
+ @debug.setter
278
+ def debug(self, value):
279
+ """Debug status
280
+
281
+ :param value: The debug status, True or False.
282
+ :type: bool
283
+ """
284
+ self.__debug = value
285
+ if self.__debug:
286
+ # if debug status is True, turn on debug logging
287
+ for _, logger in self.logger.items():
288
+ logger.setLevel(logging.DEBUG)
289
+ # turn on httplib debug
290
+ httplib.HTTPConnection.debuglevel = 1
291
+ else:
292
+ # if debug status is False, turn off debug logging,
293
+ # setting log level to default `logging.WARNING`
294
+ for _, logger in self.logger.items():
295
+ logger.setLevel(logging.WARNING)
296
+ # turn off httplib debug
297
+ httplib.HTTPConnection.debuglevel = 0
298
+
299
+ @property
300
+ def logger_format(self):
301
+ """The logger format.
302
+
303
+ The logger_formatter will be updated when sets logger_format.
304
+
305
+ :param value: The format string.
306
+ :type: str
307
+ """
308
+ return self.__logger_format
309
+
310
+ @logger_format.setter
311
+ def logger_format(self, value):
312
+ """The logger format.
313
+
314
+ The logger_formatter will be updated when sets logger_format.
315
+
316
+ :param value: The format string.
317
+ :type: str
318
+ """
319
+ self.__logger_format = value
320
+ self.logger_formatter = logging.Formatter(self.__logger_format)
321
+
322
+ def get_api_key_with_prefix(self, identifier, alias=None):
323
+ """Gets API key (with prefix if set).
324
+
325
+ :param identifier: The identifier of apiKey.
326
+ :param alias: The alternative identifier of apiKey.
327
+ :return: The token for api key authentication.
328
+ """
329
+ if self.refresh_api_key_hook is not None:
330
+ self.refresh_api_key_hook(self)
331
+ key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
332
+ if key:
333
+ prefix = self.api_key_prefix.get(identifier)
334
+ if prefix:
335
+ return "%s %s" % (prefix, key)
336
+ else:
337
+ return key
338
+
339
+ def get_basic_auth_token(self):
340
+ """Gets HTTP basic authentication header (string).
341
+
342
+ :return: The token for basic HTTP authentication.
343
+ """
344
+ username = ""
345
+ if self.username is not None:
346
+ username = self.username
347
+ password = ""
348
+ if self.password is not None:
349
+ password = self.password
350
+ return urllib3.util.make_headers(
351
+ basic_auth=username + ':' + password
352
+ ).get('authorization')
353
+
354
+ def auth_settings(self):
355
+ """Gets Auth Settings dict for api client.
356
+
357
+ :return: The Auth Settings information dict.
358
+ """
359
+ auth = {}
360
+ return auth
361
+
362
+ def to_debug_report(self):
363
+ """Gets the essential information for debugging.
364
+
365
+ :return: The report for debugging.
366
+ """
367
+ return "Python SDK Debug Report:\n"\
368
+ "OS: {env}\n"\
369
+ "Python Version: {pyversion}\n"\
370
+ "Version of the API: 0.1.0\n"\
371
+ "SDK Package Version: 0.1.0".\
372
+ format(env=sys.platform, pyversion=sys.version)
373
+
374
+ def get_host_settings(self):
375
+ """Gets an array of host settings
376
+
377
+ :return: An array of host settings
378
+ """
379
+ return [
380
+ {
381
+ 'url': "http://localhost:8001",
382
+ 'description': "No description provided",
383
+ }
384
+ ]
385
+
386
+ def get_host_from_settings(self, index, variables=None, servers=None):
387
+ """Gets host URL based on the index and variables
388
+ :param index: array index of the host settings
389
+ :param variables: hash of variable and the corresponding value
390
+ :param servers: an array of host settings or None
391
+ :return: URL based on host settings
392
+ """
393
+ if index is None:
394
+ return self._base_path
395
+
396
+ variables = {} if variables is None else variables
397
+ servers = self.get_host_settings() if servers is None else servers
398
+
399
+ try:
400
+ server = servers[index]
401
+ except IndexError:
402
+ raise ValueError(
403
+ "Invalid index {0} when selecting the host settings. "
404
+ "Must be less than {1}".format(index, len(servers)))
405
+
406
+ url = server['url']
407
+
408
+ # go through variables and replace placeholders
409
+ for variable_name, variable in server.get('variables', {}).items():
410
+ used_value = variables.get(
411
+ variable_name, variable['default_value'])
412
+
413
+ if 'enum_values' in variable \
414
+ and used_value not in variable['enum_values']:
415
+ raise ValueError(
416
+ "The variable `{0}` in the host URL has invalid value "
417
+ "{1}. Must be {2}.".format(
418
+ variable_name, variables[variable_name],
419
+ variable['enum_values']))
420
+
421
+ url = url.replace("{" + variable_name + "}", used_value)
422
+
423
+ return url
424
+
425
+ @property
426
+ def host(self):
427
+ """Return generated host."""
428
+ return self.get_host_from_settings(self.server_index, variables=self.server_variables)
429
+
430
+ @host.setter
431
+ def host(self, value):
432
+ """Fix base path."""
433
+ self._base_path = value
434
+ self.server_index = None
@@ -0,0 +1,166 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Mycelium Worker (Client) API
5
+
6
+ Configuration API for Mycelium client workers
7
+
8
+ The version of the OpenAPI document: 0.1.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ class OpenApiException(Exception):
16
+ """The base exception class for all OpenAPIExceptions"""
17
+
18
+
19
+ class ApiTypeError(OpenApiException, TypeError):
20
+ def __init__(self, msg, path_to_item=None, valid_classes=None,
21
+ key_type=None) -> None:
22
+ """ Raises an exception for TypeErrors
23
+
24
+ Args:
25
+ msg (str): the exception message
26
+
27
+ Keyword Args:
28
+ path_to_item (list): a list of keys an indices to get to the
29
+ current_item
30
+ None if unset
31
+ valid_classes (tuple): the primitive classes that current item
32
+ should be an instance of
33
+ None if unset
34
+ key_type (bool): False if our value is a value in a dict
35
+ True if it is a key in a dict
36
+ False if our item is an item in a list
37
+ None if unset
38
+ """
39
+ self.path_to_item = path_to_item
40
+ self.valid_classes = valid_classes
41
+ self.key_type = key_type
42
+ full_msg = msg
43
+ if path_to_item:
44
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
45
+ super(ApiTypeError, self).__init__(full_msg)
46
+
47
+
48
+ class ApiValueError(OpenApiException, ValueError):
49
+ def __init__(self, msg, path_to_item=None) -> None:
50
+ """
51
+ Args:
52
+ msg (str): the exception message
53
+
54
+ Keyword Args:
55
+ path_to_item (list) the path to the exception in the
56
+ received_data dict. None if unset
57
+ """
58
+
59
+ self.path_to_item = path_to_item
60
+ full_msg = msg
61
+ if path_to_item:
62
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
63
+ super(ApiValueError, self).__init__(full_msg)
64
+
65
+
66
+ class ApiAttributeError(OpenApiException, AttributeError):
67
+ def __init__(self, msg, path_to_item=None) -> None:
68
+ """
69
+ Raised when an attribute reference or assignment fails.
70
+
71
+ Args:
72
+ msg (str): the exception message
73
+
74
+ Keyword Args:
75
+ path_to_item (None/list) the path to the exception in the
76
+ received_data dict
77
+ """
78
+ self.path_to_item = path_to_item
79
+ full_msg = msg
80
+ if path_to_item:
81
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
82
+ super(ApiAttributeError, self).__init__(full_msg)
83
+
84
+
85
+ class ApiKeyError(OpenApiException, KeyError):
86
+ def __init__(self, msg, path_to_item=None) -> None:
87
+ """
88
+ Args:
89
+ msg (str): the exception message
90
+
91
+ Keyword Args:
92
+ path_to_item (None/list) the path to the exception in the
93
+ received_data dict
94
+ """
95
+ self.path_to_item = path_to_item
96
+ full_msg = msg
97
+ if path_to_item:
98
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
99
+ super(ApiKeyError, self).__init__(full_msg)
100
+
101
+
102
+ class ApiException(OpenApiException):
103
+
104
+ def __init__(self, status=None, reason=None, http_resp=None) -> None:
105
+ if http_resp:
106
+ self.status = http_resp.status
107
+ self.reason = http_resp.reason
108
+ self.body = http_resp.data
109
+ self.headers = http_resp.getheaders()
110
+ else:
111
+ self.status = status
112
+ self.reason = reason
113
+ self.body = None
114
+ self.headers = None
115
+
116
+ def __str__(self):
117
+ """Custom error messages for exception"""
118
+ error_message = "({0})\n"\
119
+ "Reason: {1}\n".format(self.status, self.reason)
120
+ if self.headers:
121
+ error_message += "HTTP response headers: {0}\n".format(
122
+ self.headers)
123
+
124
+ if self.body:
125
+ error_message += "HTTP response body: {0}\n".format(self.body)
126
+
127
+ return error_message
128
+
129
+ class BadRequestException(ApiException):
130
+
131
+ def __init__(self, status=None, reason=None, http_resp=None) -> None:
132
+ super(BadRequestException, self).__init__(status, reason, http_resp)
133
+
134
+ class NotFoundException(ApiException):
135
+
136
+ def __init__(self, status=None, reason=None, http_resp=None) -> None:
137
+ super(NotFoundException, self).__init__(status, reason, http_resp)
138
+
139
+
140
+ class UnauthorizedException(ApiException):
141
+
142
+ def __init__(self, status=None, reason=None, http_resp=None) -> None:
143
+ super(UnauthorizedException, self).__init__(status, reason, http_resp)
144
+
145
+
146
+ class ForbiddenException(ApiException):
147
+
148
+ def __init__(self, status=None, reason=None, http_resp=None) -> None:
149
+ super(ForbiddenException, self).__init__(status, reason, http_resp)
150
+
151
+
152
+ class ServiceException(ApiException):
153
+
154
+ def __init__(self, status=None, reason=None, http_resp=None) -> None:
155
+ super(ServiceException, self).__init__(status, reason, http_resp)
156
+
157
+
158
+ def render_path(path_to_item):
159
+ """Returns a string representation of a path"""
160
+ result = ""
161
+ for pth in path_to_item:
162
+ if isinstance(pth, int):
163
+ result += "[{0}]".format(pth)
164
+ else:
165
+ result += "['{0}']".format(pth)
166
+ return result
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+
3
+ # flake8: noqa
4
+ """
5
+ Mycelium Worker (Client) API
6
+
7
+ Configuration API for Mycelium client workers
8
+
9
+ The version of the OpenAPI document: 0.1.0
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501
14
+
15
+
16
+ # import models into model package
17
+ from mycelium.api.generated_sources.worker_schemas.models.save_config_response import SaveConfigResponse
18
+ from mycelium.api.generated_sources.worker_schemas.models.worker_clap_section import WorkerClapSection
19
+ from mycelium.api.generated_sources.worker_schemas.models.worker_client_api_section import WorkerClientAPISection
20
+ from mycelium.api.generated_sources.worker_schemas.models.worker_client_section import WorkerClientSection
21
+ from mycelium.api.generated_sources.worker_schemas.models.worker_config_request import WorkerConfigRequest
22
+ from mycelium.api.generated_sources.worker_schemas.models.worker_config_response import WorkerConfigResponse
23
+ from mycelium.api.generated_sources.worker_schemas.models.worker_logging_section import WorkerLoggingSection