@@ -56,6 +56,10 @@ def mask_last(value, n=4):
5656 return value [:- n ] + '*' * n if len (value ) > n else '*' * len (value )
5757
5858
59+ def is_read_only (path : os .PathLike ) -> bool :
60+ return not os .access (path , os .W_OK )
61+
62+
5963route_settings .add_app_template_filter (mask_last , name = 'mask_last' )
6064
6165
@@ -134,7 +138,10 @@ def settings():
134138 arm_path = arm_path ,
135139 media_path = media_path ,
136140 drives = drives ,
137- form_drive = form_drive )
141+ form_drive = form_drive ,
142+ ripper_read_only = is_read_only (cfg .arm_config_path ),
143+ apprise_read_only = is_read_only (cfg .apprise_config_path ),
144+ abcde_read_only = is_read_only (cfg .abcde_config_path ))
138145
139146
140147def check_hw_transcode_support ():
@@ -185,16 +192,19 @@ def save_settings():
185192 # Build the new arm.yaml with updated values from the user
186193 arm_cfg = ui_utils .build_arm_cfg (request .form .to_dict (), comments )
187194 # Save updated arm.yaml
188- with open (cfg .arm_config_path , "w" ) as settings_file :
189- settings_file .write (arm_cfg )
190- settings_file .close ()
191- success = True
192- importlib .reload (cfg )
193- # Set the ARM Log level to the config
194- app .logger .info (f"Setting log level to: { cfg .arm_config ['LOGLEVEL' ]} " )
195- app .logger .setLevel (cfg .arm_config ['LOGLEVEL' ])
195+ try :
196+ with open (cfg .arm_config_path , "w" ) as settings_file :
197+ settings_file .write (arm_cfg )
198+ settings_file .close ()
199+ success = True
200+ importlib .reload (cfg )
201+ # Set the ARM Log level to the config
202+ app .logger .info (f"Setting log level to: { cfg .arm_config ['LOGLEVEL' ]} " )
203+ app .logger .setLevel (cfg .arm_config ['LOGLEVEL' ])
204+ except OSError as e :
205+ # arm.yaml is read-only
206+ app .logger .error (f"{ cfg .arm_config_path } is read-only" , exc_info = e )
196207
197- # If we get to here there was no post data
198208 return {'success' : success , 'settings' : cfg .arm_config , 'form' : 'arm ripper settings' }
199209
200210
@@ -246,12 +256,15 @@ def save_abcde():
246256 # Windows machines can put \r\n instead of \n newlines, which corrupts the config file
247257 clean_abcde_str = '\n ' .join (abcde_cfg_str .splitlines ())
248258 # Save updated abcde.conf
249- with open (cfg .abcde_config_path , "w" ) as abcde_file :
250- abcde_file .write (clean_abcde_str )
251- abcde_file .close ()
252- success = True
253- # Update the abcde config
254- cfg .abcde_config = clean_abcde_str
259+ try :
260+ with open (cfg .abcde_config_path , "w" ) as abcde_file :
261+ abcde_file .write (clean_abcde_str )
262+ abcde_file .close ()
263+ success = True
264+ # Update the abcde config
265+ cfg .abcde_config = clean_abcde_str
266+ except OSError as e :
267+ app .logger .error (f"{ cfg .abcde_config_path } is read-only" , exc_info = e )
255268
256269 # If we get to here, there was no post-data
257270 return {'success' : success ,
@@ -273,11 +286,14 @@ def save_apprise_cfg():
273286 # Save updated apprise.yaml
274287 # Build the new arm.yaml with updated values from the user
275288 apprise_cfg = ui_utils .build_apprise_cfg (request .form .to_dict ())
276- with open (cfg .apprise_config_path , "w" ) as settings_file :
277- settings_file .write (apprise_cfg )
278- settings_file .close ()
279- success = True
280- importlib .reload (cfg )
289+ try :
290+ with open (cfg .apprise_config_path , "w" ) as settings_file :
291+ settings_file .write (apprise_cfg )
292+ settings_file .close ()
293+ success = True
294+ importlib .reload (cfg )
295+ except OSError as e :
296+ app .logger .error (f"{ cfg .apprise_config_path } is read-only" , exc_info = e )
281297 # If we get to here there was no post data
282298 return {'success' : success , 'settings' : cfg .apprise_config , 'form' : 'Apprise config' }
283299
0 commit comments