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