12
12
- drive_eject [GET]
13
13
- drive_remove [GET]
14
14
- testapprise [GET]
15
+ - updateCPU [GET]
15
16
"""
16
17
import platform
17
18
import importlib
22
23
from flask_login import login_required , \
23
24
current_user , login_user , UserMixin , logout_user # noqa: F401
24
25
from flask import render_template , request , flash , \
25
- redirect , Blueprint , session
26
+ redirect , Blueprint , session , url_for
26
27
27
28
import arm .ui .utils as ui_utils
28
29
from arm .ui import app , db
40
41
template_folder = 'templates' ,
41
42
static_folder = '../static' )
42
43
43
- # Page definitions
44
- page_settings = "settings/settings.html"
45
- redirect_settings = "/settings"
46
-
47
44
48
45
@route_settings .route ('/settings' )
49
46
@login_required
@@ -54,7 +51,6 @@ def settings():
54
51
Overview - allows the user to update the all configs of A.R.M without
55
52
needing to open a text editor
56
53
"""
57
- global page_settings
58
54
59
55
# stats for info page
60
56
failed_rips = Job .query .filter_by (status = "fail" ).count ()
@@ -88,11 +84,9 @@ def settings():
88
84
# ARM UI config
89
85
armui_cfg = ui_utils .arm_db_cfg ()
90
86
91
- # System details in class server
87
+ # Get system details from Server Info and Config
92
88
server = SystemInfo .query .filter_by (id = "1" ).first ()
93
89
serverutil = ServerUtil ()
94
-
95
- # System details in class server
96
90
arm_path = cfg .arm_config ['TRANSCODE_PATH' ]
97
91
media_path = cfg .arm_config ['COMPLETED_PATH' ]
98
92
@@ -106,7 +100,7 @@ def settings():
106
100
107
101
session ["page_title" ] = "Settings"
108
102
109
- return render_template (page_settings ,
103
+ return render_template ("settings/settings.html" ,
110
104
settings = cfg .arm_config ,
111
105
ui_settings = armui_cfg ,
112
106
stats = stats ,
@@ -222,7 +216,7 @@ def save_abcde():
222
216
"""
223
217
Page - save_abcde_settings
224
218
Method - POST
225
- Overview - Save 'abcde Config' page settings to database. Not a user page
219
+ Overview - Save 'abcde Config' page settings to the database. Not a user page
226
220
"""
227
221
success = False
228
222
abcde_cfg_str = ""
@@ -241,7 +235,9 @@ def save_abcde():
241
235
cfg .abcde_config = clean_abcde_str
242
236
243
237
# If we get to here, there was no post-data
244
- return {'success' : success , 'settings' : clean_abcde_str , 'form' : 'abcde config' }
238
+ return {'success' : success ,
239
+ 'settings' : clean_abcde_str ,
240
+ 'form' : 'abcde config' }
245
241
246
242
247
243
@route_settings .route ('/save_apprise_cfg' , methods = ['POST' ])
@@ -275,8 +271,6 @@ def server_info():
275
271
Method - POST
276
272
Overview - Save 'System Info' page settings to database. Not a user page
277
273
"""
278
- global redirect_settings
279
-
280
274
# System Drives (CD/DVD/Blueray drives)
281
275
form_drive = SystemInfoDrives (request .form )
282
276
if request .method == 'POST' and form_drive .validate ():
@@ -291,12 +285,12 @@ def server_info():
291
285
drive .drive_mode = str (form_drive .drive_mode .data ).strip ()
292
286
db .session .commit ()
293
287
flash (f"Updated Drive { drive .mount } details" , "success" )
294
- # Return to systeminfo page (refresh page)
295
- return redirect (redirect_settings )
288
+ # Return to the systeminfo page (refresh page)
289
+ return redirect (url_for ( 'route_settings.settings' ) )
296
290
else :
297
291
flash ("Error: Unable to update drive details" , "error" )
298
292
# Return for GET
299
- return redirect (redirect_settings )
293
+ return redirect (url_for ( 'route_settings.settings' ) )
300
294
301
295
302
296
@route_settings .route ('/systemdrivescan' )
@@ -306,24 +300,22 @@ def system_drive_scan():
306
300
Method - GET
307
301
Overview - Scan for the system drives and update the database.
308
302
"""
309
- global redirect_settings
310
303
# Update to scan for changes to the ripper system
311
304
new_count = DriveUtils .drives_update ()
312
305
flash (f"ARM found { new_count } new drives" , "success" )
313
- return redirect (redirect_settings )
306
+ return redirect (url_for ( 'route_settings.settings' ) )
314
307
315
308
316
309
@route_settings .route ('/drive/eject/<eject_id>' )
317
310
@login_required
318
311
def drive_eject (eject_id ):
319
312
"""
320
- Server System - change state of CD/DVD/BluRay drive - toggle eject
313
+ Server System - change state of CD/DVD/BluRay drive - toggle eject status
321
314
"""
322
- global redirect_settings
323
315
drive = SystemDrives .query .filter_by (drive_id = eject_id ).first ()
324
316
drive .open_close ()
325
317
db .session .commit ()
326
- return redirect (redirect_settings )
318
+ return redirect (url_for ( 'route_settings.settings' ) )
327
319
328
320
329
321
@route_settings .route ('/drive/remove/<remove_id>' )
@@ -332,7 +324,6 @@ def drive_remove(remove_id):
332
324
"""
333
325
Server System - remove a drive from the ARM UI
334
326
"""
335
- global redirect_settings
336
327
try :
337
328
app .logger .debug (f"Removing drive { remove_id } " )
338
329
drive = SystemDrives .query .filter_by (drive_id = remove_id ).first ()
@@ -343,7 +334,7 @@ def drive_remove(remove_id):
343
334
except Exception as e :
344
335
app .logger .error (f"Drive removal encountered an error: { e } " )
345
336
flash ("Drive unable to be removed, check logs for error" , "error" )
346
- return redirect (redirect_settings )
337
+ return redirect (url_for ( 'route_settings.settings' ) )
347
338
348
339
349
340
@route_settings .route ('/drive/manual/<manual_id>' )
@@ -390,11 +381,41 @@ def testapprise():
390
381
Method - GET
391
382
Overview - Send a test notification to Apprise.
392
383
"""
393
- global redirect_settings
394
384
# Send a sample notification
395
385
message = "This is a notification by the ARM-Notification Test!"
396
386
if cfg .arm_config ["UI_BASE_URL" ] and cfg .arm_config ["WEBSERVER_PORT" ]:
397
387
message = message + f" Server URL: http://{ cfg .arm_config ['UI_BASE_URL' ]} :{ cfg .arm_config ['WEBSERVER_PORT' ]} "
398
388
ripper_utils .notify (None , "ARM notification" , message )
399
389
flash ("Test notification sent " , "success" )
400
- return redirect (redirect_settings )
390
+ return redirect (url_for ('route_settings.settings' ))
391
+
392
+
393
+ @route_settings .route ('/updatecpu' )
394
+ def update_cpu ():
395
+ """
396
+ Update system CPU information
397
+ """
398
+ # Get current system information from database
399
+ current_system = SystemInfo .query .first ()
400
+ # Query system for new information
401
+ new_system = SystemInfo ()
402
+
403
+ app .logger .debug ("****** System Information ******" )
404
+ if current_system is not None :
405
+ app .logger .debug (f"Name old [{ current_system .name } ] new [{ new_system .name } ]" )
406
+ app .logger .debug (f"Name old [{ current_system .cpu } ] new [{ new_system .cpu } ]" )
407
+ current_system .name = new_system .name
408
+ current_system .cpu = new_system .cpu
409
+ db .session .add (current_system )
410
+
411
+ else :
412
+ app .logger .debug (f"Name old [] new [{ new_system .name } ]" )
413
+ app .logger .debug (f"Name old [] new [{ new_system .cpu } ]" )
414
+ db .session .add (new_system )
415
+
416
+ app .logger .debug ("****** End System Information ******" )
417
+ app .logger .info (f"Updated CPU Details with new info - { new_system .name } - { new_system .cpu } " )
418
+
419
+ db .session .commit ()
420
+
421
+ return redirect (url_for ('route_settings.settings' ))
0 commit comments