def load_configuration(): """Loads the configuration for the bibsort.cfg file into the database""" config_file = cfg.get('CFG_SORTER_CONFIGURATION', pkg_resources.resource_filename( 'invenio.legacy.bibsort', 'bibsort.cfg')) write_message('Reading config data from: %s' % (config_file, )) config = ConfigParser.ConfigParser() try: config.readfp(open(config_file)) except StandardError as err: write_message("Cannot find configuration file: %s" \ %config_file, stream=sys.stderr) return False to_insert = [] for section in config.sections(): try: name = config.get(section, "name") definition = config.get(section, "definition") washer = config.get(section, "washer") except (ConfigParser.NoOptionError, StandardError) as err: write_message("For each sort_field you need to define at least \ the name, the washer and the definition. \ [error: %s]" %err, stream=sys.stderr) return False to_insert.append((name, definition, washer)) # all the values were correctly read from the config file truncate_table("bsrMETHOD") write_message('Old data has been deleted from bsrMETHOD table', verbose=5) for row in to_insert: run_sql("""INSERT INTO "bsrMETHOD"(name, definition, washer) VALUES (%s, %s, %s)""", (row[0], row[1], row[2])) write_message('Method %s has been inserted into bsrMETHOD table' \ %row[0], verbose=5) return True
def delete_rnk(rnkID, table=""): """Deletes all data for the given rank method rnkID - delete all data in the tables associated with ranking and this id """ try: res = run_sql("""DELETE FROM "rnkMETHOD" WHERE id=%s""" % rnkID) res = run_sql( """DELETE FROM "rnkMETHODNAME" WHERE "id_rnkMETHOD"=%s""" % rnkID) res = run_sql( """DELETE FROM "collection_rnkMETHOD" WHERE "id_rnkMETHOD"=%s""" % rnkID) res = run_sql( """DELETE FROM rnkMETHODDATA WHERE "id_rnkMETHOD"=%s""" % rnkID) if table: res = truncate_table(table) table_name = "%sR" % table[:-1] ret = truncate_table(table_name) return (1, "") except StandardError as e: return (0, e)
def empty_self_cites_tables(): """ This will empty all the self-cites tables The purpose is to rebuild the tables from scratch in case there is problem with them: inconsitencies, corruption,... """ truncate_table("rnkSELFCITES") truncate_table("rnkEXTENDEDAUTHORS") truncate_table("rnkRECORDSCACHE")