Commit 4711bb8a authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Merge branch '2-duplicate-entries' into 'master'

2 duplicate entries

Closes #2.

See merge request !3
parents 8756dfff b52a0024
# -*- 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)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" NAME
run -- run a script using the application model
run -- run a script using the application model
SYNOPSIS
run [options] script.py
DESCRIPTION
run the script in the web2py context when the
run the script in the web2py context when the
application model is instantiated.
OPTIONS
-a, --application
Name of the application
-h, --help
Display the help and exit.
EXAMPLE
> cd ... myapp/scripts
> ./run myscript.py
AUTHOR
R. Le Gac
"""
if __name__ == "__main__":
import os
import subprocess
import sys
from argparse import ArgumentParser
APP = os.getcwd().split(os.sep)[-2]
WEB2PY_DIR = '../../web2py'
WEB2PY = os.path.join(WEB2PY_DIR, 'web2py.py')
# command line options
parser = ArgumentParser()
parser.add_argument('script',
PARSER = ArgumentParser()
PARSER.add_argument('-a', '--app',
default=APP,
dest='application',
help='the name of the application.')
PARSER.add_argument('script',
help='the name of the script to be run.')
parser.add_argument('args',
PARSER.add_argument('args',
nargs='*',
help='the arguments for the script.')
args = parser.parse_args()
# run the script in the track_publication context
script_path = os.path.join(os.getcwd(), args.script)
cmd = [WEB2PY,
ARGS = PARSER.parse_args()
# run the script in the application context
CMD = [WEB2PY,
'--no-banner',
'--shell', APP,
'--shell', ARGS.application,
'--import_models',
'--run', script_path]
if args.args:
cmd.append('--args')
cmd.extend(args.args)
return_code = subprocess.call(cmd)
'--run', os.path.join(os.getcwd(), ARGS.script)]
if ARGS.args:
CMD.append('--ARGS')
CMD.extend(ARGS.args)
RETURN_CODE = subprocess.call(CMD)
# exit
sys.exit(return_code)
sys.exit(RETURN_CODE)
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