def set_home_currency(curr): Globals.HOME_CURRENCY = curr config = SafeConfigParser() config.read(Globals.INI_FILE) if not config.has_section("defaults"): config.add_section("defaults") config.set("defaults", "home_currency", curr) if not os.path.isdir(os.path.dirname(Globals.INI_FILE)): os.makedirs(os.path.dirname(Globals.INI_FILE)) with open(Globals.INI_FILE, "w") as fp: config.write(fp)
def get_home_currency(): if Globals.HOME_CURRENCY is None: config = SafeConfigParser() config.read(Globals.INI_FILE) if config.has_section("defaults") and config.has_option( "defaults", "home_currency"): hc = config.get("defaults", "home_currency") else: hc = guess_home_currency() if hc: set_home_currency(hc) Globals.HOME_CURRENCY = hc return Globals.HOME_CURRENCY