1212- drive_eject [GET]
1313- drive_remove [GET]
1414- testapprise [GET]
15+ - updateCPU [GET]
1516"""
1617import platform
1718import importlib
2223from flask_login import login_required , \
2324 current_user , login_user , UserMixin , logout_user # noqa: F401
2425from flask import render_template , request , flash , \
25- redirect , Blueprint , session
26+ redirect , Blueprint , session , url_for
2627
2728import arm .ui .utils as ui_utils
2829from arm .ui import app , db
4041 template_folder = 'templates' ,
4142 static_folder = '../static' )
4243
43- # Page definitions
44- page_settings = "settings/settings.html"
45- redirect_settings = "/settings"
46-
4744
4845@route_settings .route ('/settings' )
4946@login_required
@@ -54,7 +51,6 @@ def settings():
5451 Overview - allows the user to update the all configs of A.R.M without
5552 needing to open a text editor
5653 """
57- global page_settings
5854
5955 # stats for info page
6056 failed_rips = Job .query .filter_by (status = "fail" ).count ()
@@ -88,11 +84,9 @@ def settings():
8884 # ARM UI config
8985 armui_cfg = ui_utils .arm_db_cfg ()
9086
91- # System details in class server
87+ # Get system details from Server Info and Config
9288 server = SystemInfo .query .filter_by (id = "1" ).first ()
9389 serverutil = ServerUtil ()
94-
95- # System details in class server
9690 arm_path = cfg .arm_config ['TRANSCODE_PATH' ]
9791 media_path = cfg .arm_config ['COMPLETED_PATH' ]
9892
@@ -106,7 +100,7 @@ def settings():
106100
107101 session ["page_title" ] = "Settings"
108102
109- return render_template (page_settings ,
103+ return render_template ("settings/settings.html" ,
110104 settings = cfg .arm_config ,
111105 ui_settings = armui_cfg ,
112106 stats = stats ,
@@ -222,7 +216,7 @@ def save_abcde():
222216 """
223217 Page - save_abcde_settings
224218 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
226220 """
227221 success = False
228222 abcde_cfg_str = ""
@@ -241,7 +235,9 @@ def save_abcde():
241235 cfg .abcde_config = clean_abcde_str
242236
243237 # 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' }
245241
246242
247243@route_settings .route ('/save_apprise_cfg' , methods = ['POST' ])
@@ -275,8 +271,6 @@ def server_info():
275271 Method - POST
276272 Overview - Save 'System Info' page settings to database. Not a user page
277273 """
278- global redirect_settings
279-
280274 # System Drives (CD/DVD/Blueray drives)
281275 form_drive = SystemInfoDrives (request .form )
282276 if request .method == 'POST' and form_drive .validate ():
@@ -291,12 +285,12 @@ def server_info():
291285 drive .drive_mode = str (form_drive .drive_mode .data ).strip ()
292286 db .session .commit ()
293287 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' ) )
296290 else :
297291 flash ("Error: Unable to update drive details" , "error" )
298292 # Return for GET
299- return redirect (redirect_settings )
293+ return redirect (url_for ( 'route_settings.settings' ) )
300294
301295
302296@route_settings .route ('/systemdrivescan' )
@@ -306,24 +300,22 @@ def system_drive_scan():
306300 Method - GET
307301 Overview - Scan for the system drives and update the database.
308302 """
309- global redirect_settings
310303 # Update to scan for changes to the ripper system
311304 new_count = DriveUtils .drives_update ()
312305 flash (f"ARM found { new_count } new drives" , "success" )
313- return redirect (redirect_settings )
306+ return redirect (url_for ( 'route_settings.settings' ) )
314307
315308
316309@route_settings .route ('/drive/eject/<eject_id>' )
317310@login_required
318311def drive_eject (eject_id ):
319312 """
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
321314 """
322- global redirect_settings
323315 drive = SystemDrives .query .filter_by (drive_id = eject_id ).first ()
324316 drive .open_close ()
325317 db .session .commit ()
326- return redirect (redirect_settings )
318+ return redirect (url_for ( 'route_settings.settings' ) )
327319
328320
329321@route_settings .route ('/drive/remove/<remove_id>' )
@@ -332,7 +324,6 @@ def drive_remove(remove_id):
332324 """
333325 Server System - remove a drive from the ARM UI
334326 """
335- global redirect_settings
336327 try :
337328 app .logger .debug (f"Removing drive { remove_id } " )
338329 drive = SystemDrives .query .filter_by (drive_id = remove_id ).first ()
@@ -343,7 +334,7 @@ def drive_remove(remove_id):
343334 except Exception as e :
344335 app .logger .error (f"Drive removal encountered an error: { e } " )
345336 flash ("Drive unable to be removed, check logs for error" , "error" )
346- return redirect (redirect_settings )
337+ return redirect (url_for ( 'route_settings.settings' ) )
347338
348339
349340@route_settings .route ('/drive/manual/<manual_id>' )
@@ -390,11 +381,41 @@ def testapprise():
390381 Method - GET
391382 Overview - Send a test notification to Apprise.
392383 """
393- global redirect_settings
394384 # Send a sample notification
395385 message = "This is a notification by the ARM-Notification Test!"
396386 if cfg .arm_config ["UI_BASE_URL" ] and cfg .arm_config ["WEBSERVER_PORT" ]:
397387 message = message + f" Server URL: http://{ cfg .arm_config ['UI_BASE_URL' ]} :{ cfg .arm_config ['WEBSERVER_PORT' ]} "
398388 ripper_utils .notify (None , "ARM notification" , message )
399389 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