Skip to content
This repository was archived by the owner on May 28, 2022. It is now read-only.

Commit e89c8c7

Browse files
Updates to endpoint arguments, and some WIP implementation.
1 parent fbfdd5a commit e89c8c7

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

Diff for: src/freeseer/frontend/controller/configuration.py

+39-20
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import signal
2626

27-
from flask import Blueprint
27+
from flask import Blueprint, request
2828
from freeseer import settings, logging
2929
from freeseer.framework.plugin import PluginManager
3030
from freeseer.frontend.controller.server import http_response, ServerError
@@ -49,12 +49,15 @@ def configure_configuration():
4949
Runs on first call to server.
5050
"""
5151
signal.signal(signal.SIGINT, teardown_configuration)
52-
configuration.profile = settings.profile_manager.get()
53-
configuration.config = configuration.profile.get_config('freeseer.conf',
54-
settings.FreeseerConfig,
55-
storage_args=['Global'],
56-
read_only=True)
57-
configuration.plugin_manager = PluginManager(configuration.profile)
52+
#configuration.plugin_manager = PluginManager(configuration.profile)
53+
54+
55+
def load_configuration(profile):
56+
"""
57+
Returns the configuration for a given profile.
58+
"""
59+
profile = settings.profile_manager.get(profile)
60+
return profile.get_config('freeseer.conf', settings.FreeseerConfig, storage_args=['Global'], read_only=False)
5861

5962

6063
def teardown_configuration(signum, frame):
@@ -73,45 +76,58 @@ def teardown_configuration(signum, frame):
7376
def list_profiles():
7477
"""
7578
List available configuration profiles.
79+
80+
TODO: add a method to the ProfileManager class to list existing profiles.
7681
"""
7782
raise ServerError('unimplemented')
7883

7984

80-
@configuration.route('/profiles/:profile', methods=['GET'])
85+
@configuration.route('/profiles/<string:profile>', methods=['GET'])
8186
@http_response(200)
8287
def view_profile(profile):
8388
"""
8489
View the configuration profile specified by :profile.
8590
"""
86-
raise ServerError('unimplemented')
91+
configuration = load_configuration(profile)
92+
return {'profile_configuration': configuration.values}
8793

8894

8995
@configuration.route('/profiles/', methods=['POST'])
9096
@http_response(200)
9197
def create_profile():
9298
"""
9399
Create new profile under 'name' specified in request arg.
100+
101+
TODO: add a method to ProfileManager to explicitly create new profiles.
94102
"""
103+
profile_name = request.form['name']
95104
raise ServerError('unimplemented')
96105

97106

98-
@configuration.route('/profiles/:profile', methods=['DELETE'])
107+
@configuration.route('/profiles/<string:profile>', methods=['DELETE'])
99108
@http_response(200)
100109
def delete_profile(profile):
101110
"""
102111
Delete the profile specified by :profile.
112+
113+
TODO: implement delete profile in ProfileManager.
103114
"""
104115
raise ServerError('unimplemented')
105116

106117

107-
@configuration.route('/profiles/:profile', methods=['PATCH'])
118+
@configuration.route('/profiles/<string:profile>', methods=['PATCH'])
108119
@http_response(200)
109120
def modify_profile(profile):
110121
"""
111122
Modify the profile specified by :profile.
112123
"""
124+
configuration = load_configuration(profile)
125+
changes = request.form
126+
127+
configuration.save()
113128
raise ServerError('unimplemented')
114129

130+
115131
#
116132
# End Profile Endpoints
117133
#
@@ -121,7 +137,7 @@ def modify_profile(profile):
121137
#
122138

123139

124-
@configuration.route('/profiles/:profile/general', methods=['GET'])
140+
@configuration.route('/profiles/<string:profile>/general', methods=['GET'])
125141
@http_response(200)
126142
def view_general_configuration(profile):
127143
"""
@@ -132,14 +148,15 @@ def view_general_configuration(profile):
132148
'auto_hide': configuration.config.auto_hide, }
133149

134150

135-
@configuration.route('/profiles/:profile/general', methods=['PATCH'])
151+
@configuration.route('/profiles/<string:profile>/general', methods=['PATCH'])
136152
@http_response(200)
137153
def modify_general_configuration(profile):
138154
"""
139155
Modifies the general configuration for the given :profile.
140156
"""
141157
raise ServerError('unimplemented')
142158

159+
143160
#
144161
# General Configuration Endpoints
145162
#
@@ -149,7 +166,7 @@ def modify_general_configuration(profile):
149166
#
150167

151168

152-
@configuration.route('/profiles/:profile/recording', methods=['GET'])
169+
@configuration.route('/profiles/<string:profile>/recording', methods=['GET'])
153170
@http_response(200)
154171
def view_recording_configuration():
155172
"""
@@ -164,13 +181,15 @@ def view_recording_configuration():
164181
'videomixer': configuration.config.videomixer, }
165182

166183

167-
@configuration.route('/profiles/:profile/recording', methods=['PATCH'])
184+
@configuration.route('/profiles/<string:profile>/recording', methods=['PATCH'])
168185
@http_response(200)
169186
def put_recording_configuration():
170187
"""
171188
Modifies the recording configuration for the given :profile.
172189
"""
173190
raise ServerError('unimplemented')
191+
192+
174193
#
175194
# End recording configuration endpoints.
176195
#
@@ -179,7 +198,7 @@ def put_recording_configuration():
179198
#
180199
# Plugin Category endpoints.
181200
#
182-
@configuration.route('/profiles/:profile/recording/<string:category>', methods=['GET'])
201+
@configuration.route('/profiles/<string:profile>/recording/<string:category>', methods=['GET'])
183202
@http_response(200)
184203
def list_plugin_category(profile, category):
185204
"""
@@ -195,7 +214,7 @@ def list_plugin_category(profile, category):
195214
#
196215
# Plugin endpoints.
197216
#
198-
@configuration.route('/profiles/:profile/recording/<string:category>/<string:plugin>', methods=['GET'])
217+
@configuration.route('/profiles/<string:profile>/recording/<string:category>/<string:plugin>', methods=['GET'])
199218
@http_response(200)
200219
def list_plugin_instances(profile, category, plugin):
201220
"""
@@ -204,7 +223,7 @@ def list_plugin_instances(profile, category, plugin):
204223
raise ServerError('unimplemented')
205224

206225

207-
@configuration.route('/profiles/:profile/recording/<string:category>/<string:plugin>/:id', methods=['GET'])
226+
@configuration.route('/profiles/<string:profile>/recording/<string:category>/<string:plugin>/:id', methods=['GET'])
208227
@http_response(200)
209228
def view_plugin_instance(profile, category, plugin, id):
210229
"""
@@ -213,7 +232,7 @@ def view_plugin_instance(profile, category, plugin, id):
213232
raise ServerError('unimplemented')
214233

215234

216-
@configuration.route('/profiles/:profile/recording/<string:category>/<string:plugin>', methods=['POST'])
235+
@configuration.route('/profiles/<string:profile>/recording/<string:category>/<string:plugin>', methods=['POST'])
217236
@http_response(200)
218237
def create_plugin_instance(profile, category, plugin):
219238
"""
@@ -222,7 +241,7 @@ def create_plugin_instance(profile, category, plugin):
222241
raise ServerError('unimplemented')
223242

224243

225-
@configuration.route('/profiles/:profile/recording/<string:category>/<string:plugin/:id>', methods=['PATCH'])
244+
@configuration.route('/profiles/<string:profile>/recording/<string:category>/<string:plugin>/:id', methods=['PATCH'])
226245
@http_response(200)
227246
def modify_plugin_instance(profile, category, plugin, id):
228247
"""

0 commit comments

Comments
 (0)