@ -29,8 +29,51 @@ class Config:
logger . info ( " Using {} as config " . format ( self . config_path ) )
yaml . YAML ( ) . allow_duplicate_keys = True
try : self . data , ind , bsi = yaml . util . load_yaml_guess_indent ( open ( self . config_path ) )
except yaml . scanner . ScannerError as e : raise Failed ( " YAML Error: {} " . format ( str ( e ) . replace ( " \n " , " \n | \t " ) ) )
try :
new_config , ind , bsi = yaml . util . load_yaml_guess_indent ( open ( self . config_path ) )
def replace_attr ( all_data , attr , par ) :
if " settings " not in all_data :
all_data [ " settings " ] = { }
if par in all_data and all_data [ par ] and attr in all_data [ par ] and attr not in all_data [ " settings " ] :
all_data [ " settings " ] [ attr ] = all_data [ par ] [ attr ]
del all_data [ par ] [ attr ]
if " libraries " not in new_config :
new_config [ " libraries " ] = { }
if " settings " not in new_config :
new_config [ " settings " ] = { }
if " tmdb " not in new_config :
new_config [ " tmdb " ] = { }
replace_attr ( new_config , " cache " , " cache " )
replace_attr ( new_config , " cache_expiration " , " cache " )
del new_config [ " cache " ]
replace_attr ( new_config , " asset_directory " , " plex " )
replace_attr ( new_config , " sync_mode " , " plex " )
replace_attr ( new_config , " show_unmanaged " , " plex " )
replace_attr ( new_config , " show_filtered " , " plex " )
replace_attr ( new_config , " show_missing " , " plex " )
replace_attr ( new_config , " save_missing " , " plex " )
if new_config [ " libraries " ] :
for library in new_config [ " libraries " ] :
if " plex " in new_config [ " libraries " ] [ library ] :
replace_attr ( new_config [ " libraries " ] [ library ] , " asset_directory " , " plex " )
replace_attr ( new_config [ " libraries " ] [ library ] , " sync_mode " , " plex " )
replace_attr ( new_config [ " libraries " ] [ library ] , " show_unmanaged " , " plex " )
replace_attr ( new_config [ " libraries " ] [ library ] , " show_filtered " , " plex " )
replace_attr ( new_config [ " libraries " ] [ library ] , " show_missing " , " plex " )
replace_attr ( new_config [ " libraries " ] [ library ] , " save_missing " , " plex " )
new_config [ " libraries " ] = new_config . pop ( " libraries " )
new_config [ " settings " ] = new_config . pop ( " settings " )
new_config [ " plex " ] = new_config . pop ( " plex " )
new_config [ " tmdb " ] = new_config . pop ( " tmdb " )
new_config [ " tautulli " ] = new_config . pop ( " tautulli " )
new_config [ " radarr " ] = new_config . pop ( " radarr " )
new_config [ " sonarr " ] = new_config . pop ( " sonarr " )
new_config [ " trakt " ] = new_config . pop ( " trakt " )
new_config [ " mal " ] = new_config . pop ( " mal " )
yaml . round_trip_dump ( new_config , open ( self . config_path , " w " ) , indent = ind , block_seq_indent = bsi )
self . data = new_config
except yaml . scanner . ScannerError as e :
raise Failed ( " YAML Error: {} " . format ( str ( e ) . replace ( " \n " , " \n | \t " ) ) )
def check_for_attribute ( data , attribute , parent = None , test_list = None , options = " " , default = None , do_print = True , default_is_none = False , req_default = False , var_type = " str " , throw = False , save = True ) :
message = " "
@ -67,7 +110,7 @@ class Config:
else : message = " Path {} does not exist " . format ( os . path . abspath ( data [ attribute ] ) )
elif var_type == " list " : return util . get_list ( data [ attribute ] )
elif var_type == " listpath " :
temp_list = [ path for path in util . get_list ( data [ attribute ] ) if os . path . exists ( os . path . abspath ( path ) ) ]
temp_list = [ path for path in util . get_list ( data [ attribute ] , split = True ) if os . path . exists ( os . path . abspath ( path ) ) ]
if len ( temp_list ) > 0 : return temp_list
else : message = " No Paths exist "
elif var_type == " lowerlist " : return util . get_list ( data [ attribute ] , lower = True )
@ -94,51 +137,6 @@ class Config:
return default
self . general = { }
if " settings " not in self . data :
new_config , ind , bsi = yaml . util . load_yaml_guess_indent ( open ( self . config_path ) )
def replace_attr ( all_data , attr , par ) :
if " settings " not in all_data :
all_data [ " settings " ] = { }
if par in all_data and all_data [ par ] and attr in all_data [ par ] and attr not in all_data [ " settings " ] :
all_data [ " settings " ] [ attr ] = all_data [ par ] [ attr ]
del all_data [ par ] [ attr ]
if " libraries " not in new_config :
new_config [ " libraries " ] = { }
if " settings " not in new_config :
new_config [ " settings " ] = { }
if " tmdb " not in new_config :
new_config [ " tmdb " ] = { }
replace_attr ( new_config , " cache " , " cache " )
replace_attr ( new_config , " cache_expiration " , " cache " )
del new_config [ " cache " ]
replace_attr ( new_config , " asset_directory " , " plex " )
replace_attr ( new_config , " sync_mode " , " plex " )
replace_attr ( new_config , " show_unmanaged " , " plex " )
replace_attr ( new_config , " show_filtered " , " plex " )
replace_attr ( new_config , " show_missing " , " plex " )
replace_attr ( new_config , " save_missing " , " plex " )
if new_config [ " libraries " ] :
for library in new_config [ " libraries " ] :
if " plex " in new_config [ " libraries " ] [ library ] :
replace_attr ( new_config [ " libraries " ] [ library ] , " asset_directory " , " plex " )
replace_attr ( new_config [ " libraries " ] [ library ] , " sync_mode " , " plex " )
replace_attr ( new_config [ " libraries " ] [ library ] , " show_unmanaged " , " plex " )
replace_attr ( new_config [ " libraries " ] [ library ] , " show_filtered " , " plex " )
replace_attr ( new_config [ " libraries " ] [ library ] , " show_missing " , " plex " )
replace_attr ( new_config [ " libraries " ] [ library ] , " save_missing " , " plex " )
new_config [ " libraries " ] = new_config . pop ( " libraries " )
new_config [ " settings " ] = new_config . pop ( " settings " )
new_config [ " plex " ] = new_config . pop ( " plex " )
new_config [ " tmdb " ] = new_config . pop ( " tmdb " )
new_config [ " tautulli " ] = new_config . pop ( " tautulli " )
new_config [ " radarr " ] = new_config . pop ( " radarr " )
new_config [ " sonarr " ] = new_config . pop ( " sonarr " )
new_config [ " trakt " ] = new_config . pop ( " trakt " )
new_config [ " mal " ] = new_config . pop ( " mal " )
yaml . round_trip_dump ( new_config , open ( self . config_path , " w " ) , indent = ind , block_seq_indent = bsi )
self . general [ " cache " ] = check_for_attribute ( self . data , " cache " , parent = " settings " , options = " true (Create a cache to store ids) \n false (Do not create a cache to store ids) " , var_type = " bool " , default = True )
self . general [ " cache_expiration " ] = check_for_attribute ( self . data , " cache_expiration " , parent = " settings " , var_type = " int " , default = 60 )
if self . general [ " cache " ] :