def save(filename=ConfigPath):
    """Saves this module's changed attributes to INI configuration."""
    default_values = defaults()
    parser = configparser.RawConfigParser()
    parser.optionxform = str # Force case-sensitivity on names
    try:
        save_types = basestring, int, float, tuple, list, dict, type(None)
        for k, v in sorted(globals().items()):
            if not isinstance(v, save_types) or k.startswith("_") \
            or default_values.get(k, parser) == v: continue # for k, v
            try: parser.set("DEFAULT", k, json.dumps(v))
            except Exception: pass
        if parser.defaults():
            with open(filename, "wb") as f:
                f.write("# %s %s configuration written on %s.\n" % (Title, Version,
                        datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
                parser.write(f)
        else: # Nothing to write: delete configuration file
            try: os.unlink(filename)
            except Exception: pass
    except Exception:
        logging.warn("Error writing config to %s.", filename, exc_info=True)
def save ( filename = ConfigPath ) : default_values = defaults ( ) parser = configparser . RawConfigParser ( ) parser . optionxform = str try : save_types = basestring , int , float , tuple , list , dict , type ( None ) for k , v in sorted ( globals ( ) . items ( ) ) : if not isinstance ( v , save_types ) or k . startswith ( "_" ) or default_values . get ( k , parser ) == v : continue try : parser . set ( "DEFAULT" , k , json . dumps ( v ) ) except Exception : pass if parser . defaults ( ) : with open ( filename , "wb" ) as f : f . write ( "# %s %s configuration written on %s.\n" % ( Title , Version , datetime . datetime . now ( ) . strftime ( "%Y-%m-%d %H:%M:%S" ) ) ) parser . write ( f ) else : try : os . unlink ( filename ) except Exception : pass except Exception : logging . warn ( "Error writing config to %s." , filename , exc_info = True )
Saves this module's changed attributes to INI configuration.