Commit eb274b13 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the scrip fix-duplicate.py.

It removes duplicate entries in the history table.
parent f888a0ae
# -*- coding: utf-8 -*-
""" NAME
fix-duplicate
SYNOPSIS
Look for duplicate entry in the history table and fix them.
DESCRIPTION
Look for duplicate entry in the history table.
Duplicate entries have the same event, team, project, people,
start date, end_date and data.
Once found the one with the highest id is removed.
OPTIONS
-h, --help
Display the help and exit.
EXAMPLE
> cd ...track_lhcbfrance/scripts
> ./run fix-duplicate
AUTHOR
R. Le Gac -- May 2015
"""
if __name__ == "__main__":
import re
import sys
from argparse import ArgumentParser
# command line options
parser = ArgumentParser()
args = parser.parse_args()
for row in db(db.history).select():
query = db.history.id_events == row.id_events
query = (query) & (db.history.id_teams == row.id_teams)
query = (query) & (db.history.id_projects == row.id_projects)
query = (query) & (db.history.id_people == row.id_people)
query = (query) & (db.history.id_people_categories == row.id_people_categories)
query = (query) & (db.history.start_date == row.start_date)
query = (query) & (db.history.end_date == row.end_date)
query = (query) & (db.history.data == row.data)
entries = db(query).count()
if entries == 1:
continue
li = []
for entry in db(query).select():
li.append(entry.id)
print "\nDuplicate entries", entries, "ids:", li
del li[0]
print "Delete", li
for i in li:
db(db.history.id == i).delete()
# commit and close
rep = raw_input("Commit change [n]?")
if rep.lower().startswith('y'):
db.commit()
print "database modified"
sys.exit(0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment