tiferet 1.0.0a3__py3-none-any.whl → 1.0.0a5__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.
tiferet/__init__.py CHANGED
@@ -0,0 +1 @@
1
+ from .contexts import *
@@ -0,0 +1 @@
1
+ from . import yaml as yaml_client
@@ -1,2 +1,4 @@
1
- from .app import AppContext
2
- from .env import EnvironmentContext
1
+ from .app import AppInterfaceContext
2
+ from .env import EnvironmentContext
3
+ from .request import RequestContext
4
+ from .error import ErrorContext
tiferet/contexts/env.py CHANGED
@@ -89,14 +89,19 @@ class EnvironmentContext(Model):
89
89
  # Get the app interface.
90
90
  app_interface: AppInterface = self.interfaces.get(interface_id)
91
91
 
92
- # Get the dependencies for the app interface.
92
+ # Get the default dependencies for the app interface.
93
93
  dependencies = dict(
94
94
  interface_id=app_interface.id,
95
95
  feature_flag=app_interface.feature_flag,
96
96
  data_flag=app_interface.data_flag,
97
+ app_context=container_service.import_dependency(
98
+ **app_interface.app_context.to_primitive()
99
+ ),
97
100
  **app_interface.constants
98
101
  )
99
- for dep in app_interface.get_dependencies():
102
+
103
+ # Import the dependencies.
104
+ for dep in app_interface.dependencies:
100
105
  dependencies[dep.attribute_id] = container_service.import_dependency(dep.module_path, dep.class_name)
101
106
 
102
107
  # Create the injector from the dependencies, constants, and the app interface.
tiferet/data/app.py CHANGED
@@ -1,5 +1,8 @@
1
1
  # *** imports
2
2
 
3
+ # ** core
4
+ from typing import Dict
5
+
3
6
  # ** app
4
7
  from ..configs import *
5
8
  from ..domain import DataObject
@@ -14,6 +17,13 @@ class AppDependencyYamlData(AppDependency, DataObject):
14
17
  A YAML data representation of an app dependency object.
15
18
  '''
16
19
 
20
+ # * attribute: attribute_id
21
+ attribute_id = StringType(
22
+ metadata=dict(
23
+ description='The attribute id for the application dependency.'
24
+ ),
25
+ )
26
+
17
27
  class Options():
18
28
  '''
19
29
  The options for the app dependency data.
@@ -38,9 +48,8 @@ class AppDependencyYamlData(AppDependency, DataObject):
38
48
 
39
49
  # Create a new AppDependencyData object.
40
50
  return AppDependencyYamlData(
41
- super(AppDependencyYamlData, AppDependencyYamlData).new(
42
- **kwargs
43
- )
51
+ dict(**kwargs),
52
+ strict=False,
44
53
  )
45
54
 
46
55
  # * method: map
@@ -72,7 +81,7 @@ class AppInterfaceYamlData(AppInterface, DataObject):
72
81
  '''
73
82
  serialize_when_none = False
74
83
  roles = {
75
- 'to_model': DataObject.allow(),
84
+ 'to_model': DataObject.deny('app_context', 'container_context', 'feature_context', 'error_context', 'feature_repo', 'container_repo', 'error_repo'),
76
85
  'to_data.yaml': DataObject.deny('id')
77
86
  }
78
87
 
@@ -89,6 +98,11 @@ class AppInterfaceYamlData(AppInterface, DataObject):
89
98
  feature_context = ModelType(
90
99
  AppDependencyYamlData,
91
100
  required=True,
101
+ default=AppDependencyYamlData.new(
102
+ attribute_id='feature_context',
103
+ module_path='tiferet.contexts.feature',
104
+ class_name='FeatureContext',
105
+ ),
92
106
  metadata=dict(
93
107
  description='The feature context dependency.'
94
108
  ),
@@ -98,6 +112,11 @@ class AppInterfaceYamlData(AppInterface, DataObject):
98
112
  container_context = ModelType(
99
113
  AppDependencyYamlData,
100
114
  required=True,
115
+ default=AppDependencyYamlData.new(
116
+ attribute_id='container_context',
117
+ module_path='tiferet.contexts.container',
118
+ class_name='ContainerContext',
119
+ ),
101
120
  metadata=dict(
102
121
  description='The container context dependency.'
103
122
  ),
@@ -107,6 +126,11 @@ class AppInterfaceYamlData(AppInterface, DataObject):
107
126
  error_context = ModelType(
108
127
  AppDependencyYamlData,
109
128
  required=True,
129
+ default=AppDependencyYamlData.new(
130
+ attribute_id='error_context',
131
+ module_path='tiferet.contexts.error',
132
+ class_name='ErrorContext',
133
+ ),
110
134
  metadata=dict(
111
135
  description='The error context dependency.'
112
136
  ),
@@ -116,6 +140,11 @@ class AppInterfaceYamlData(AppInterface, DataObject):
116
140
  feature_repo = ModelType(
117
141
  AppDependencyYamlData,
118
142
  required=True,
143
+ default=AppDependencyYamlData.new(
144
+ attribute_id='feature_repo',
145
+ module_path='tiferet.repos.feature',
146
+ class_name='FeatureRepository',
147
+ ),
119
148
  metadata=dict(
120
149
  description='The feature repository dependency.'
121
150
  ),
@@ -125,6 +154,11 @@ class AppInterfaceYamlData(AppInterface, DataObject):
125
154
  container_repo = ModelType(
126
155
  AppDependencyYamlData,
127
156
  required=True,
157
+ default=AppDependencyYamlData.new(
158
+ attribute_id='container_repo',
159
+ module_path='tiferet.repos.container',
160
+ class_name='ContainerRepository',
161
+ ),
128
162
  metadata=dict(
129
163
  description='The container repository dependency.'
130
164
  ),
@@ -134,6 +168,11 @@ class AppInterfaceYamlData(AppInterface, DataObject):
134
168
  error_repo = ModelType(
135
169
  AppDependencyYamlData,
136
170
  required=True,
171
+ default=AppDependencyYamlData.new(
172
+ attribute_id='error_repo',
173
+ module_path='tiferet.repos.error',
174
+ class_name='ErrorRepository',
175
+ ),
137
176
  metadata=dict(
138
177
  description='The error repository dependency.'
139
178
  ),
@@ -141,7 +180,14 @@ class AppInterfaceYamlData(AppInterface, DataObject):
141
180
 
142
181
  # * method: new
143
182
  @staticmethod
144
- def new(**kwargs) -> 'AppInterfaceYamlData':
183
+ def new(app_context: Dict[str, str],
184
+ container_context: Dict[str, str] = None,
185
+ feature_context: Dict[str, str] = None,
186
+ error_context: Dict[str, str] = None,
187
+ feature_repo: Dict[str, str] = None,
188
+ container_repo: Dict[str, str] = None,
189
+ error_repo: Dict[str, str] = None,
190
+ **kwargs) -> 'AppInterfaceYamlData':
145
191
  '''
146
192
  Initializes a new YAML representation of an AppInterface object.
147
193
 
@@ -151,12 +197,33 @@ class AppInterfaceYamlData(AppInterface, DataObject):
151
197
  :rtype: AppInterfaceData
152
198
  '''
153
199
 
200
+ # Format the dependencies.
201
+ dependencies = {}
202
+ if app_context:
203
+ dependencies['app_context'] = AppDependencyYamlData.new(attribute_id='app_context', **app_context)
204
+ if container_context:
205
+ dependencies['container_context'] = AppDependencyYamlData.new(attribute_id='container_context', **container_context)
206
+ if feature_context:
207
+ dependencies['feature_context'] = AppDependencyYamlData.new(attribute_id='feature_context', **feature_context)
208
+ if error_context:
209
+ dependencies['error_context'] = AppDependencyYamlData.new(attribute_id='error_context', **error_context)
210
+ if feature_repo:
211
+ dependencies['feature_repo'] = AppDependencyYamlData.new(attribute_id='feature_repo', **feature_repo)
212
+ if container_repo:
213
+ dependencies['container_repo'] = AppDependencyYamlData.new(attribute_id='container_repo', **container_repo)
214
+ if error_repo:
215
+ dependencies['error_repo'] = AppDependencyYamlData.new(attribute_id='error_repo', **error_repo)
216
+
154
217
  # Create a new AppInterfaceData object.
155
- return AppInterfaceYamlData(
156
- super(AppInterfaceYamlData, AppInterfaceYamlData).new(
157
- **kwargs
158
- )
218
+ data = AppInterfaceYamlData(dict(
219
+ **dependencies,
220
+ **kwargs),
221
+ strict=False,
159
222
  )
223
+
224
+ # Validate and return the new AppInterfaceData object.
225
+ data.validate()
226
+ return data
160
227
 
161
228
  # * method: map
162
229
  def map(self, **kwargs) -> AppInterface:
@@ -171,8 +238,23 @@ class AppInterfaceYamlData(AppInterface, DataObject):
171
238
  :rtype: AppInterface
172
239
  '''
173
240
 
241
+ # Format and map the dependencies.
242
+ dependencies = [
243
+ self.app_context.map(),
244
+ self.container_context.map(),
245
+ self.feature_context.map(),
246
+ self.error_context.map(),
247
+ self.feature_repo.map(),
248
+ self.container_repo.map(),
249
+ self.error_repo.map(),
250
+ ]
251
+
174
252
  # Map the app interface data.
175
- return super().map(AppInterface, **kwargs)
253
+ return super().map(AppInterface,
254
+ dependencies=dependencies,
255
+ **self.to_primitive('to_model'),
256
+ **kwargs
257
+ )
176
258
 
177
259
 
178
260
  # ** data: app_repository_configuration_yaml_data
tiferet/data/container.py CHANGED
@@ -36,7 +36,7 @@ class ContainerDependencyYamlData(ContainerDependency, DataObject):
36
36
  parameters = DictType(
37
37
  StringType,
38
38
  default={},
39
- serialize_name='params',
39
+ serialized_name='params',
40
40
  deserialize_from=['params'],
41
41
  metadata=dict(
42
42
  description='The parameters need to now account for new data names in the YAML format.'
@@ -117,7 +117,7 @@ class ContainerAttributeYamlData(ContainerAttribute, DataObject):
117
117
  dependencies = DictType(
118
118
  ModelType(ContainerDependencyYamlData),
119
119
  default=[],
120
- serialize_name='deps',
120
+ serialized_name='deps',
121
121
  deserialize_from=['deps', 'dependencies'],
122
122
  metadata=dict(
123
123
  description='The dependencies are now a key-value pair keyed by the flags.'
tiferet/domain/app.py CHANGED
@@ -33,7 +33,7 @@ class AppDependency(ModuleDependency):
33
33
  # Create and return a new AppDependency object.
34
34
  return super(AppDependency, AppDependency).new(
35
35
  AppDependency,
36
- **kwargs
36
+ **kwargs,
37
37
  )
38
38
 
39
39
  # ** model: app_interface
@@ -73,96 +73,13 @@ class AppInterface(Entity):
73
73
  ),
74
74
  )
75
75
 
76
- # * attribute: app_context
77
- app_context = ModelType(
78
- AppDependency,
79
- required=True,
80
- metadata=dict(
81
- description='The application context dependency.'
82
- ),
83
- )
84
-
85
- # * attribute: feature_context
86
- feature_context = ModelType(
87
- AppDependency,
88
- required=True,
89
- default=AppDependency.new(
90
- attribute_id='feature_context',
91
- module_path='tiferet.contexts.feature',
92
- class_name='FeatureContext',
93
- ),
94
- metadata=dict(
95
- description='The feature context dependency.'
96
- ),
97
- )
98
-
99
- # * attribute: container_context
100
- container_context = ModelType(
101
- AppDependency,
102
- required=True,
103
- default=AppDependency.new(
104
- attribute_id='container_context',
105
- module_path='tiferet.contexts.container',
106
- class_name='ContainerContext',
107
- ),
108
- metadata=dict(
109
- description='The container context dependency.'
110
- ),
111
- )
112
-
113
- # * attribute: error_context
114
- error_context = ModelType(
115
- AppDependency,
116
- required=True,
117
- default=AppDependency.new(
118
- attribute_id='error_context',
119
- module_path='tiferet.contexts.error',
120
- class_name='ErrorContext',
121
- ),
122
- metadata=dict(
123
- description='The error context dependency.'
124
- ),
125
- )
126
-
127
- # * attribute: feature_repo
128
- feature_repo = ModelType(
129
- AppDependency,
130
- required=True,
131
- default=AppDependency.new(
132
- attribute_id='feature_repo',
133
- module_path='tiferet.repos.feature',
134
- class_name='FeatureRepository',
135
- ),
136
- metadata=dict(
137
- description='The feature repository dependency.'
138
- ),
139
- )
140
-
141
- # * attribute: container_repo
142
- container_repo = ModelType(
143
- AppDependency,
144
- required=True,
145
- default=AppDependency.new(
146
- attribute_id='container_repo',
147
- module_path='tiferet.repos.container',
148
- class_name='ContainerRepository',
149
- ),
150
- metadata=dict(
151
- description='The container repository dependency.'
152
- ),
153
- )
154
-
155
- # * attribute: error_repo
156
- error_repo = ModelType(
157
- AppDependency,
76
+ # * attribute: dependencies
77
+ dependencies = ListType(
78
+ ModelType(AppDependency),
158
79
  required=True,
159
- default=AppDependency.new(
160
- attribute_id='error_repo',
161
- module_path='tiferet.repos.error',
162
- class_name='ErrorRepository',
163
- ),
80
+ default=[],
164
81
  metadata=dict(
165
- description='The error repository dependency.'
82
+ description='The application interface dependencies.'
166
83
  ),
167
84
  )
168
85
 
@@ -197,26 +114,6 @@ class AppInterface(Entity):
197
114
  **kwargs
198
115
  )
199
116
 
200
- # * method: list_dependencies
201
- def get_dependencies(self) -> list:
202
- '''
203
- Lists the dependencies for the application interface.
204
-
205
- :return: The list of dependencies for the application interface.
206
- :rtype: list
207
- '''
208
-
209
- # Return the list of dependencies for the application interface.
210
- return [
211
- self.app_context,
212
- self.feature_context,
213
- self.container_context,
214
- self.error_context,
215
- self.feature_repo,
216
- self.container_repo,
217
- self.error_repo,
218
- ]
219
-
220
117
 
221
118
  # ** model: app_repository_configuration
222
119
  class AppRepositoryConfiguration(ModuleDependency):
@@ -266,9 +163,9 @@ class AppRepositoryConfiguration(ModuleDependency):
266
163
  '''
267
164
 
268
165
  # Create and return a new AppRepositoryConfiguration object.
269
- return super(AppRepositoryConfiguration, AppRepositoryConfiguration).new(
270
- AppRepositoryConfiguration,
271
- **kwargs
166
+ return AppRepositoryConfiguration(
167
+ super(AppRepositoryConfiguration, AppRepositoryConfiguration).new(**kwargs),
168
+ strict=False,
272
169
  )
273
170
 
274
171
 
tiferet/domain/core.py CHANGED
@@ -159,7 +159,7 @@ class DataObject(Model):
159
159
 
160
160
 
161
161
  # ** model: module_dependency
162
- class ModuleDependency(Model):
162
+ class ModuleDependency(ValueObject):
163
163
  '''
164
164
  A module dependency.
165
165
  '''
@@ -172,28 +172,10 @@ class ModuleDependency(Model):
172
172
  )
173
173
  )
174
174
 
175
- # ** attribute: class_name
175
+ # * attribute: class_name
176
176
  class_name = StringType(
177
177
  required=True,
178
178
  metadata=dict(
179
179
  description='The class name.'
180
180
  )
181
181
  )
182
-
183
- # * method: new
184
- @staticmethod
185
- def new(**kwargs) -> 'ModuleDependency':
186
- '''
187
- Initializes a new ModuleDependency object.
188
-
189
- :param kwargs: Additional keyword arguments.
190
- :type kwargs: dict
191
- :return: A new ModuleDependency object.
192
- :rtype: ModuleDependency
193
- '''
194
-
195
- # Create a new ModuleDependency object.
196
- return super(ModuleDependency, ModuleDependency).new(
197
- ModuleDependency,
198
- **kwargs
199
- )
tiferet/repos/app.py CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # ** app
4
4
  from ..domain.app import AppInterface
5
- from ..data.app import AppInterfaceData
5
+ from ..data.app import AppInterfaceYamlData
6
6
  from ..clients import yaml as yaml_client
7
7
 
8
8
 
@@ -72,9 +72,10 @@ class YamlProxy(object):
72
72
  interfaces = yaml_client.load(
73
73
  self.config_file,
74
74
  create_data=lambda data: [
75
- AppInterfaceData.new(
75
+ AppInterfaceYamlData.new(
76
+ id=interface_id,
76
77
  **record
77
- ).map() for record in data],
78
+ ).map() for interface_id, record in data.items()],
78
79
  start_node=lambda data: data.get('interfaces'))
79
80
 
80
81
  # Return the list of app interface objects.
@@ -94,7 +95,7 @@ class YamlProxy(object):
94
95
  # Load the app interface data from the yaml configuration file.
95
96
  _data: AppInterface = yaml_client.load(
96
97
  self.config_file,
97
- create_data=lambda data: AppInterfaceData.new (
98
+ create_data=lambda data: AppInterfaceYamlData.new (
98
99
  id=id, **data),
99
100
  start_node=lambda data: data.get('interfaces').get(id))
100
101
 
@@ -1,4 +1 @@
1
- from . import cli as cli_service
2
- from . import container as container_service
3
- from . import object as object_service
4
- from . import sync as sync_service
1
+ from . import container as container_service
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tiferet
3
- Version: 1.0.0a3
3
+ Version: 1.0.0a5
4
4
  Summary: A multi-purpose application framework embodying beauty in form.
5
5
  Home-page: https://github.com/greatstrength/app
6
6
  Download-URL: https://github.com/greatstrength/app
@@ -1,5 +1,5 @@
1
- tiferet/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- tiferet/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
1
+ tiferet/__init__.py,sha256=XtrOOpLk8fjC_CY-UZFmzYQ6Q9mL73D_6scuWpEJXZU,23
2
+ tiferet/clients/__init__.py,sha256=hSa_PgXM2jw9iVRrJH_SQUlSVISK-T4tTfgRKnXKkzA,33
3
3
  tiferet/clients/yaml.py,sha256=-Eo8PX2oPpVxv1c-cpkNOrGhxx9T7XPYoAyGi1DxMi4,2454
4
4
  tiferet/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  tiferet/commands/container.py,sha256=L2IKJqEbRglw_LC144oYAkARr2Rixj8IFuC6Ro1jAqA,1789
@@ -7,34 +7,33 @@ tiferet/commands/error.py,sha256=ixMYH0yrEWlMAVGDSRke3IGoWaOShfmiXntrUC2b3wY,573
7
7
  tiferet/commands/feature.py,sha256=tXa-MDf14ByIJqwQFeSUu2QLUjHPdsyvFNhj1XeaQVk,2507
8
8
  tiferet/configs/__init__.py,sha256=NfT6XFNcJznOLXjMuNmj3XeaOPVWwbc-N4kVWaVjuD0,845
9
9
  tiferet/configs/app.py,sha256=XMBbwHS2y_Wm-scxVJ2mcAtBy0cRj5e0WLbi1F3R1Q4,299
10
- tiferet/contexts/__init__.py,sha256=0HzyDBIyyF8fZ0gOXekzfzHWVkbLFUx9eLLzuooEzFs,63
10
+ tiferet/contexts/__init__.py,sha256=6ElZETwHoWC-gUEm0XWnXbV_-liIgLGByGh62DO4AY8,140
11
11
  tiferet/contexts/app.py,sha256=MPRFu3ut7DOmc3i3PqLR96ymvWMShW6BUbY9eG8i6Eg,3296
12
12
  tiferet/contexts/container.py,sha256=zGCGm1lF0mI6AmEa9WK-N_Gwyv1oHSqUCOmLnkqvFyc,4871
13
- tiferet/contexts/env.py,sha256=bbvZzDy075SuKL2ZIfDEE5yD1Hbk-4XLGe4eC_tT8e8,3080
13
+ tiferet/contexts/env.py,sha256=Hhbv3sqmcVd61ck_5Uq8WWV171vaKIpIRTggeIdIrZ8,3253
14
14
  tiferet/contexts/error.py,sha256=VO3Wgkmf5bdK6LoT0xhQn1WeSAVulQwUhvBAsoUPd1c,2503
15
15
  tiferet/contexts/feature.py,sha256=u7wEhdfTLeWKIv5i2nzBcu4cAcVkm6iqNNznczPmHjc,2293
16
16
  tiferet/contexts/request.py,sha256=TOECa0V1wKuNGCYFIRKxwsZVpLtP0FS_Nm96DaEVsWU,2726
17
17
  tiferet/data/__init__.py,sha256=ts3bkFftArKTgUJj7q65Sob4fC6jOqfYNxm6cqjFr_w,74
18
- tiferet/data/app.py,sha256=8kv7tDJUjl70bqdpiMXXs6e89zDQIvtlDSOq42iyyX0,6312
19
- tiferet/data/container.py,sha256=jTQlT4D-lLC_QLNAmMara6O78g667GXk1LU_EyuX_HU,5180
18
+ tiferet/data/app.py,sha256=jZ-4fUTU-FPyaihMlmxVnSsRabcAX5ay56WbRsnKwds,9675
19
+ tiferet/data/container.py,sha256=DMrw-jXTRgRAuxf8zmIftHwQkN9tBxBKj4pmcS7ZpB4,5182
20
20
  tiferet/data/error.py,sha256=lfGO3SjtsxSv6d7iKDeVw3vXfocCk29g4-uwC3jnaig,2377
21
21
  tiferet/data/feature.py,sha256=s_aqVYhH7VKzXpWM3d-uvSv3_r8A0LgObv3Agg-CKoc,3697
22
22
  tiferet/domain/__init__.py,sha256=uC1lHXzRnpoHqfgPcUraea5F_T1Nsx0wBau0paslsQg,146
23
- tiferet/domain/app.py,sha256=2iEjj74o_VJt2kHwJLgQkGrDtFywyWjX4fUF0meYSOQ,8528
23
+ tiferet/domain/app.py,sha256=I3nFat5a73mlNvaBsTy_kIYVcv8F2mUN8MGbCxyxwtg,5640
24
24
  tiferet/domain/container.py,sha256=Kw_xNn5_tWghcx3Dl_vPEdwZ2b8u23ZpbgMQ_bkUKaw,3666
25
- tiferet/domain/core.py,sha256=a1nJvH7bCqP_JvGrkMDClH8nef2L3WHpmTV6ksmdZ4c,4600
25
+ tiferet/domain/core.py,sha256=iNL5w71FQjbNICSMTZnxFAqWl6b0Cj9V94vBM6NU03Y,4112
26
26
  tiferet/domain/error.py,sha256=myUpdB4rgmbVBwIP8Pa88uastTSjPFGqrSwqR9C-VYg,3371
27
27
  tiferet/domain/feature.py,sha256=RhedOKb8nG1D0J9b_aPVtJc_rQjLXwOpwpIsmzrH21o,4552
28
28
  tiferet/repos/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
- tiferet/repos/app.py,sha256=VptevFxeST5slbk_em7dazXgz5U8f_XLDsGdM0Gq3qE,2696
29
+ tiferet/repos/app.py,sha256=0mPPScHy29YIoqYCkTffX3r9OgxvTlGikmfKNV1Yy4M,2767
30
30
  tiferet/repos/container.py,sha256=2Medggn4BZrelnZ-cDZfFFwHaDB80R7iFJ5OF-6E62g,4811
31
31
  tiferet/repos/error.py,sha256=c3Bs2QTktMuJWGSRF8rKeTN5vFEsaOycUdYD7QSIDEc,4224
32
32
  tiferet/repos/feature.py,sha256=uR4s-n28J4WCO4Npi6AzOxk5R9I6HuUMHDzoK1Xo_80,4361
33
- tiferet/services/__init__.py,sha256=CIyUCm2oFrhZvCLPCPz3UG-eghdkIBgqayxoOr-QrdE,151
34
- tiferet/services/cli.py,sha256=aqrn7kxqe2xTJWBSs5hDiyD0ND50mPVDIJf_C87YgRk,5364
33
+ tiferet/services/__init__.py,sha256=rwaCBwIfhqLkdXage-Q0hl_Ou7MAlGVW1Bg555uAUD8,44
35
34
  tiferet/services/container.py,sha256=yZU09pziCMz74UIRqiM_gHNqNE4Hml555WEuNoJlEDA,1048
36
- tiferet-1.0.0a3.dist-info/LICENSE,sha256=e8_GutFM0sxbRlgUaeVsGvJ5uE-KvruLApOzIoHy_zU,1513
37
- tiferet-1.0.0a3.dist-info/METADATA,sha256=xdrIL_XTH5CnPm0xX4_evmcTPRaTbZspqtKONmEqTZQ,422
38
- tiferet-1.0.0a3.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
39
- tiferet-1.0.0a3.dist-info/top_level.txt,sha256=g19Qw0j_VxPw-fgPF1TMPwbtHjnEhNQs0fa69wJZ6IM,8
40
- tiferet-1.0.0a3.dist-info/RECORD,,
35
+ tiferet-1.0.0a5.dist-info/LICENSE,sha256=e8_GutFM0sxbRlgUaeVsGvJ5uE-KvruLApOzIoHy_zU,1513
36
+ tiferet-1.0.0a5.dist-info/METADATA,sha256=R9SuKQafnfLIYmKLp8-ek9IC4jchvX0XpuOfXD8ZE1U,422
37
+ tiferet-1.0.0a5.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
38
+ tiferet-1.0.0a5.dist-info/top_level.txt,sha256=g19Qw0j_VxPw-fgPF1TMPwbtHjnEhNQs0fa69wJZ6IM,8
39
+ tiferet-1.0.0a5.dist-info/RECORD,,
tiferet/services/cli.py DELETED
@@ -1,186 +0,0 @@
1
- from typing import List, Dict, Any
2
- import argparse
3
-
4
- from ..contexts.request import RequestContext
5
- from ..domain.cli import CliInterface
6
- from ..domain.cli import CliArgument
7
-
8
-
9
- def create_argument_data(cli_argument: CliArgument):
10
-
11
- # List fields to be excluded.
12
- exclude_fields = ['name_or_flags', 'arg_type', 'to_data']
13
-
14
- # Exclude unneeded fields if the argument contains an action.
15
- if cli_argument.action:
16
- exclude_fields.append('nargs')
17
- exclude_fields.append('type')
18
- exclude_fields.append('choices')
19
-
20
- # Set the data type for the argument.
21
- if cli_argument.type == 'str':
22
- data_type = str
23
- elif cli_argument.type == 'int':
24
- data_type = int
25
- elif cli_argument.type == 'float':
26
- data_type = float
27
-
28
- # For each name or flag in the argument,
29
- for name in cli_argument.name_or_flags:
30
-
31
- # If the name or flag is a positional argument,
32
- if not name.startswith('--'):
33
-
34
- # Remove the required field.
35
- exclude_fields.append('required')
36
-
37
- # Assemble the argument data.
38
- argument_data = cli_argument.to_primitive()
39
-
40
- # Set the data type.
41
- argument_data['type'] = data_type
42
-
43
- # For each field in the excluded fields,
44
- for field in exclude_fields:
45
-
46
- # Remove the field from the argument data if it is present.
47
- try:
48
- del argument_data[field]
49
- except KeyError:
50
- pass
51
-
52
- # Return the argument data.
53
- return argument_data
54
-
55
-
56
- def create_headers(data: dict):
57
- headers = dict(
58
- group_id=data.pop('group'),
59
- command_id=data.pop('command'),
60
- )
61
- headers['id'] = f"{headers['group_id']}.{headers['command_id']}".replace(
62
- '-', '_')
63
- return headers
64
-
65
-
66
- def create_cli_parser(cli_interface: CliInterface):
67
-
68
- # Format commands into a dictionary lookup by group id.
69
- commands = {}
70
- for command in cli_interface.commands:
71
- group_id = command.group_id
72
- if group_id not in commands:
73
- commands[group_id] = []
74
- commands[group_id].append(command)
75
-
76
- # Create parser.
77
- parser = argparse.ArgumentParser()
78
-
79
- # Add command subparsers
80
- command_subparsers = parser.add_subparsers(dest='group')
81
- for group_id, commands in commands.items():
82
- group_name = group_id.replace('_', '-')
83
- command_subparser = command_subparsers.add_parser(
84
- group_name)
85
- subcommand_subparsers = command_subparser.add_subparsers(
86
- dest='command')
87
- for command in commands:
88
- command_name = command.id.split('.')[-1].replace('_', '-')
89
- subcommand_subparser = subcommand_subparsers.add_parser(
90
- command_name)
91
- for argument in command.arguments:
92
- subcommand_subparser.add_argument(
93
- *argument.name_or_flags, **create_argument_data(argument))
94
- for argument in cli_interface.parent_arguments:
95
- subcommand_subparser.add_argument(
96
- *argument.name_or_flags, **create_argument_data(argument))
97
-
98
- return parser
99
-
100
-
101
- def create_request(request: argparse.Namespace, cli_interface: CliInterface, **kwargs) -> RequestContext:
102
-
103
- # Convert argparse.Namespace to dictionary.
104
- data = vars(request)
105
-
106
- # Create header values.
107
- headers = create_headers(data)
108
-
109
- # Get the command from the CLI interface.
110
- command = cli_interface.get_command(**headers)
111
-
112
- # Create map of arguments to their data attribute names.
113
- argument_map = {arg.get_name(): arg for arg in command.arguments}
114
-
115
- # Map the data to the request context.
116
- for key, value in data.items():
117
- if value is None:
118
- continue
119
- argument = argument_map.get(key)
120
- data[key] = map_object_input(value, argument)
121
-
122
- # Create request context.
123
- return RequestContext(
124
- feature_id=command.feature_id,
125
- data=data,
126
- headers=headers,
127
- **headers,
128
- **kwargs
129
- )
130
-
131
-
132
- def map_object_input(data: Any, argument: CliArgument):
133
-
134
- # If the argument is not input to data,
135
- if not argument.to_data:
136
-
137
- # Return the data.
138
- return data
139
-
140
- # If the argument is a dictionary,
141
- if argument.nargs:
142
-
143
- # If the argument is a list, split the data by the delimiter.
144
- result = {}
145
-
146
- # For each item in the data, split the item into key and value.
147
- for item in data:
148
-
149
- # Split the item into key and value.
150
- key, value = item.split('=')
151
-
152
- # Add the key and value to the result.
153
- result[key] = value
154
-
155
- # Return result.
156
- return result
157
-
158
- # If the argument is an object list,
159
- if argument.action == 'append':
160
-
161
- # Create a list to store the result.
162
- result = []
163
-
164
- # For each row object in the data,
165
- for row in data:
166
-
167
- # Create an object to store the key value pairs.
168
- obj = {}
169
-
170
- # Split the row by the delimiter.
171
- items = row.split(';')
172
-
173
- # For each item in the row,
174
- for item in items:
175
-
176
- # Split the item into key and value.
177
- key, value = item.split('=')
178
-
179
- # Add the key and value to the object.
180
- obj[key] = value
181
-
182
- # Add the object to the result.
183
- result.append(obj)
184
-
185
- # Return result.
186
- return result