# -*- coding: utf-8 -*- """ NAME fix-country-0808 -- fix invalid country names SYNOPSIS fix-country [options] DESCRIPTION Before the limbra 0.8.8, the name of the country for a conference is defined by the user or by harvesters. As the result, the database contains a mixture of French and English name for country. In addition, some value are wrong. Starting with version 0.8.8, the database is populated with a list of countries, in English, coming from a geographical database. A standard user or an harvesters can no longer add a country in the database. The aim of this script, is to replace invalid name by the correct one and to remove bad ones. At the end of this process, the database should only contains official country names. OPTIONS EXAMPLE > cd ...limbra/scripts > ./run script fix-country-0808.py > ./run script -S limbra_cppm fix-country-0808.py AUTHOR R. Le Gac -- Nov 2014 """ if __name__ == "__main__": from callbacks import INHIBIT_PUBLICATION_UPDATE_ON_OK from countries import COUNTRIES from plugin_dbui import get_id, UNDEF_ID # unlock the publications update when the status is OK db.publications._before_update.remove(INHIBIT_PUBLICATION_UPDATE_ON_OK) # scan the database to find invalid countries for row in db(db.countries).select(): if row.country in COUNTRIES or row.id == UNDEF_ID: continue # replacement value for the country old_country = row.country new_country = raw_input("\nReplacement for '%s' [to skip CR]: " % old_country) if not new_country: continue # is the new value valid ? id_old = get_id(db.countries, country=old_country) id_new = get_id(db.countries, country=new_country) if not id_new: continue print "%s will be replaced by %s" % (old_country, new_country) rep = raw_input("Ok to continue [y/N]: ") if rep != "y": continue # modify publications for row in db(db.publications.id_countries==id_old).select(): print " - ", row.id, row.title db(db.publications.id==row.id).update(id_countries=id_new) db.commit() # delete the old value db(db.countries.id==id_old).delete() db.commit()