@synchronized(SAVE_CONFIG_LOCK)
def save_config(force=False):
 global CFG, database, modified
 if 0:
  assert isinstance(CFG, configobj.ConfigObj)
 if (not (modified or force)):
  return True
 for section in database:
  if (section in ('servers', 'categories', 'rss')):
   try:
    CFG[section]
   except KeyError:
    CFG[section] = {}
   for subsec in database[section]:
    if (section == 'servers'):
     subsec_mod = subsec.replace('[', '{').replace(']', '}')
    else:
     subsec_mod = subsec
    try:
     CFG[section][subsec_mod]
    except KeyError:
     CFG[section][subsec_mod] = {}
    items = database[section][subsec].get_dict()
    CFG[section][subsec_mod] = items
  else:
   for option in database[section]:
    (sec, kw) = database[section][option].ident()
    sec = sec[(-1)]
    try:
     CFG[sec]
    except KeyError:
     CFG[sec] = {}
    value = database[section][option]()
    if (type(value) == type(True)):
     CFG[sec][kw] = str(int(value))
    elif (type(value) == type(0)):
     CFG[sec][kw] = str(value)
    else:
     CFG[sec][kw] = value
 res = False
 filename = CFG.filename
 bakname = (filename + '.bak')
 if (not sabnzbd.misc.is_writable(filename)):
  logging.error(T('Cannot write to INI file %s'), filename)
  return res
 try:
  shutil.copyfile(filename, bakname)
  shutil.copymode(filename, bakname)
 except:
  logging.error(T('Cannot create backup file for %s'), bakname)
  logging.info('Traceback: ', exc_info=True)
  return res
 try:
  CFG.write()
  shutil.copymode(bakname, filename)
  modified = False
  res = True
 except:
  logging.error(T('Cannot write to INI file %s'), filename)
  logging.info('Traceback: ', exc_info=True)
  try:
   os.remove(filename)
  except:
   pass
  sabnzbd.misc.renamer(bakname, filename)
 return res

@ synchronized ( SAVE_CONFIG_LOCK ) def save_config ( force = False ) : global CFG , database , modified if 0 : assert isinstance ( CFG , configobj . ConfigObj ) if ( not ( modified or force ) ) : return True for section in database : if ( section in ( 'servers' , 'categories' , 'rss' ) ) : try : CFG [ section ] except KeyError : CFG [ section ] = { } for subsec in database [ section ] : if ( section == 'servers' ) : subsec_mod = subsec . replace ( '[' , '{' ) . replace ( ']' , '}' ) else : subsec_mod = subsec try : CFG [ section ] [ subsec_mod ] except KeyError : CFG [ section ] [ subsec_mod ] = { } items = database [ section ] [ subsec ] . get_dict ( ) CFG [ section ] [ subsec_mod ] = items else : for option in database [ section ] : ( sec , kw ) = database [ section ] [ option ] . ident ( ) sec = sec [ ( - 1 ) ] try : CFG [ sec ] except KeyError : CFG [ sec ] = { } value = database [ section ] [ option ] ( ) if ( type ( value ) == type ( True ) ) : CFG [ sec ] [ kw ] = str ( int ( value ) ) elif ( type ( value ) == type ( 0 ) ) : CFG [ sec ] [ kw ] = str ( value ) else : CFG [ sec ] [ kw ] = value res = False filename = CFG . filename bakname = ( filename + '.bak' ) if ( not sabnzbd . misc . is_writable ( filename ) ) : logging . error ( T ( 'Cannot write to INI file %s' ) , filename ) return res try : shutil . copyfile ( filename , bakname ) shutil . copymode ( filename , bakname ) except : logging . error ( T ( 'Cannot create backup file for %s' ) , bakname ) logging . info ( 'Traceback: ' , exc_info = True ) return res try : CFG . write ( ) shutil . copymode ( bakname , filename ) modified = False res = True except : logging . error ( T ( 'Cannot write to INI file %s' ) , filename ) logging . info ( 'Traceback: ' , exc_info = True ) try : os . remove ( filename ) except : pass sabnzbd . misc . renamer ( bakname , filename ) return res
convert a logical configuration to the haproxy version .