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

Merge branch 'master' into 'production'

Master

Release 0.5.1

* Maintenance release.
* Use the construct DBURIS.
* Add the script fix-duplicate.py to remove duplicate entries in the history table.

See merge request !4
parents b7e3c876 8a8daafe
......@@ -4,7 +4,7 @@
.pydevproject
*.pyc
.settings/
_db.py
_db*.py*
cache/
cron/
databases
......
......@@ -2,37 +2,37 @@
def documentations():
"""Main controller to give access to the documentation.
"""
return dict()
@auth.requires_login()
@auth.requires(True, requires_login=not request.is_local)
def index():
"""Main Controller to run the application launching the plugin dbui.
"""
# login procedure is active
if session.auth:
roles = session.auth.user_groups.values()
roles = session.auth.user_groups.values()
if roles:
session.role = roles[0]
else:
return 'The user role is not defined'
# no login procedure
# no login procedure
else:
session.role = ADMIN
if 'debug' in request.vars:
del request.vars['debug']
url = URL('plugin_dbui', 'debug', args=request.args, vars=request.vars)
else:
url = URL('plugin_dbui', 'index', args=request.args, vars=request.vars)
return redirect(url)
......
......@@ -3,7 +3,7 @@
setup the connection to the databases.
Define constants for the different role
"""
# Migration flags
MIGRATE = False
......@@ -19,7 +19,7 @@ ID_USER, USER, DEF_USER = 2, 'user', 'project leader,...'
#
#-------------------------------------------------------------------------------
try:
mysql = 'mysql://%s:%s@%s/%s' % (DB_USER, DB_PWD, DB_HOST, DATABASE)
mysql = DBURIS[request.application]
db = DAL(mysql, lazy_tables=False, migrate_enabled=MIGRATE, pool_size=10)
except:
raise HTTP(500, T("Can't access the MySQL database !!!"))
......
......@@ -7,7 +7,6 @@
if not db(db.events.id).count():
db.events.insert(id=undef_id,
event=undef,
category=undef,
definition=undef)
if not db(db.fundings.id).count():
......
# -*- 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)
......@@ -2,13 +2,16 @@
HEAD
0.5.0 (Apr 2015)
0.5.0 - 0.5.1 (May 2015)
- Major relealse non backward compatible
- Add the tables objects and object_categories for a more generic tool.
- List, Metric1D and 2D works with missing data. It appends when several
- List, Metric1D and 2D works with missing data. It appends when several
events are merged with different user data blocks.
- Re-enforce column configuration rules: xtype has always to be defined,
dataIndex is required with eval.
- Use the DBURIS construct.
- Add the script fix-duplicate.py to remove duplicate entries in the
history table.
0.4.5 (Mar 2015)
- Major release non-backward compatible.
......
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