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

Run pylint.

parent 445fd4aa
""" """
import os
import re
def index():
"""Main Controller to run the application.
"""
url = URL('plugin_dbui', 'index', args=request.args, vars=request.vars)
url = URL("plugin_dbui", "index", args=request.args, vars=request.vars)
return redirect(url)
def user():
return 'hello you hit the default/user controller'
\ No newline at end of file
return "hello you hit the default/user controller"
......@@ -15,22 +15,19 @@
"""
import json
import os
import plugin_dbui as dbui
from gluon.tools import PluginManager
API = """
Dbui.csvUrl = '/%s/plugin_dbui/csv';
Dbui.csvUrl = "/%s/plugin_dbui/csv";
Dbui.config = %s;
Dbui.debug = %s;
Dbui.latex2pdfUrl = '/%s/plugin_dbui/latex2pdf.pdf';
Dbui.name = '%s';
Dbui.latex2pdfUrl = "/%s/plugin_dbui/latex2pdf.pdf";
Dbui.name = "%s";
Dbui.REMOTE_API = {
'url': '/%s/plugin_dbui/call',
'type': 'remoting',
'actions': %s
"url": "/%s/plugin_dbui/call",
"type": "remoting",
"actions": %s
};"""
......@@ -38,7 +35,7 @@ def about():
fn = os.path.join("applications",
request.application,
PluginManager("dbui").dbui.app_about)
return open(fn, 'rb').read()
return open(fn, "rb").read()
def call():
......@@ -59,10 +56,11 @@ def csv():
is_foreign_field,
is_table_with_foreign_fields)
tablename = request.vars['tableName']
tablename = request.vars["tableName"]
response.headers['Content-Type'] = contenttype('.csv')
response.headers['Content-Disposition'] = 'attachment; filename=%s.csv;' % tablename
headers = response.headers
headers["Content-Type"] = contenttype(".csv")
headers["Content-Disposition"] = "attachment; filename=%s.csv;" % tablename
table = db[tablename]
query = table.id > 0
......@@ -95,9 +93,9 @@ def dbui_conf():
the plugin dbui: application name, store definition,...
"""
from gluon.contrib import simplejson as json
from plugin_dbui import (DBUI,
get_all_tables,
JSONEncoder,
to_jsonstore,
to_model,
to_treeNodes,
......@@ -108,7 +106,7 @@ def dbui_conf():
# build the dictionary required by Ext.direct
# containing the definition of the remote procedure
for (k, f) in directSvc.procedures.iteritems():
action, method = k.split('.')
action, method = k.split(".")
if action == DBUI:
nargs = f.func_code.co_argcount
......@@ -118,42 +116,42 @@ def dbui_conf():
if action not in di:
di[action] = []
di[action].append({'name': method, 'len': nargs})
di[action].append({"name": method, "len": nargs})
# the definition of the models
config = {'models': {},
'stores': {},
'treeNodes': [],
'viewport': None}
config = {"models": {},
"stores": {},
"treeNodes": [],
"viewport": None}
for table in get_all_tables(db):
config['models'][table._tablename] = to_model(table)
config["models"][table._tablename] = to_model(table)
# the stores configuration (static, for each table,...)
# NOTE: the interface require a store for all tables including alias.
# The only way to extract them is to scan the attributes list of
# the DAL since the method db.tables() or any variant return
# tables but not the alias one
config['stores'].update(PluginManager("dbui").dbui.static_stores)
config["stores"].update(PluginManager("dbui").dbui.static_stores)
for table in get_all_tables(db):
cfg = to_jsonstore(table)
config['stores'][cfg['storeId']] = cfg
config["stores"][cfg["storeId"]] = cfg
# the tree nodes configuration for the TreeStore
config['treeNodes'] = to_treeNodes()
config["treeNodes"] = to_treeNodes()
# the viewport configuration
config['viewport'] = to_viewport()
config["viewport"] = to_viewport()
# debug mode
debug = 'false'
if 'debug' in request.vars:
debug = 'true'
debug = "false"
if "debug" in request.vars:
debug = "true"
# fill the javascript template
app = request.application
script = API % (app,
json.dumps(config, cls=dbui.JSONEncoder),
json.dumps(config, cls=JSONEncoder),
debug,
app,
app,
......@@ -161,7 +159,7 @@ def dbui_conf():
json.dumps(di))
# return the response as a javascript
response.headers['Content-Type'] = 'text/javascript'
response.headers["Content-Type"] = "text/javascript"
return script
......@@ -175,6 +173,12 @@ def documentations_table():
"""
from plugin_dbui import get_reference_paths, Store
def path_exists(x):
return x and os.path.exists(os.path.join(apath, x))
def f(x):
return x.replace("static/", "")
plugin = PluginManager("dbui").dbui
# alias
......@@ -186,62 +190,71 @@ def documentations_table():
apath, lpath = get_reference_paths()
path_exists = lambda x: x and os.path.exists(os.path.join(apath, x))
f = lambda x: x.replace("static/", "")
# documentation of the application
userdoc = ""
path_db_schema = plugin.app_db_schema
if path_exists(path_db_schema):
userdoc = a % (URL('static', f(path_db_schema)), T("Data base scheme"))
userdoc = a % (URL("static", f(path_db_schema)), T("Data base scheme"))
pydoc = ""
path_html_api = plugin.app_html_api
if path_exists(path_html_api):
pydoc = a % (URL('static', f(path_html_api)), trPy)
pydoc = a % (URL("static", f(path_html_api)), trPy)
jsdoc = ""
path_html_jsduck = plugin.app_html_jsduck
if path_exists(path_html_jsduck):
jsdoc = a % (URL('static', f(path_html_jsduck)), trJS)
jsdoc = a % (URL("static", f(path_html_jsduck)), trJS)
# configuration of the Ext.data.Store for the documentation
cfg = Store()
cfg.fields = [dict(name='code', type='string'),
dict(name='developer', type='string'),
dict(name='python', type='string'),
dict(name='javascript', type='string')]
r1 = dict(code=request.application,
developer=userdoc,
python=pydoc,
javascript=jsdoc)
r2 = dict(code=a % ("https://marprod.in2p3.fr/plugin_dbui_book", "plugin_dbui"),
developer=a % (URL('static', 'plugin_dbui/docs/reference/index.html'), trDev),
python=a % (URL('static', 'plugin_dbui/docs/api/index.html'), trPy),
javascript=a % (URL('static', 'plugin_dbui/docs/jsduck/index.html'), trJS))
r3 = dict(code=a % ("http://web2py.com/", "Web2py"),
developer=a % ("http://web2py.com/book", trDev),
python=a % ("http://web2py.readthedocs.org/en/latest/", trPy),
javascript="")
r4 = dict(code=a % ("http://www.sencha.com/products/extjs/", "Ext JS"),
developer="",
python="",
javascript=a % ("http://docs.sencha.com/extjs/6.0.1-classic/", trJS))
r5 = dict(code=a % ("http://www.mathjax.org/", "MathJax"),
developer="",
python="",
javascript=a % ("http://docs.mathjax.org/", trJS))
r6 = dict(code=a % ("http://ace.c9.io/#nav=about", "Ace"),
developer="",
python="",
javascript=a % ("http://ace.c9.io/#nav=api", trJS))
cfg.fields = [
dict(name="code", type="string"),
dict(name="developer", type="string"),
dict(name="python", type="string"),
dict(name="javascript", type="string")]
r1 = dict(
code=request.application,
developer=userdoc,
python=pydoc,
javascript=jsdoc)
r2 = dict(
code=a % ("https://marprod.in2p3.fr/plugin_dbui_book", "plugin_dbui"),
developer=a %
(URL("static", "plugin_dbui/docs/reference/index.html"), trDev),
python=a % (URL("static", "plugin_dbui/docs/api/index.html"), trPy),
javascript=a %
(URL("static", "plugin_dbui/docs/jsduck/index.html"), trJS))
r3 = dict(
code=a % ("http://web2py.com/", "Web2py"),
developer=a % ("http://web2py.com/book", trDev),
python=a % ("http://web2py.readthedocs.org/en/latest/", trPy),
javascript="")
r4 = dict(
code=a % ("http://www.sencha.com/products/extjs/", "Ext JS"),
developer="",
python="",
javascript=a % ("http://docs.sencha.com/extjs/6.0.1-classic/", trJS))
r5 = dict(
code=a % ("http://www.mathjax.org/", "MathJax"),
developer="",
python="",
javascript=a % ("http://docs.mathjax.org/", trJS))
r6 = dict(
code=a % ("http://ace.c9.io/#nav=about", "Ace"),
developer="",
python="",
javascript=a % ("http://ace.c9.io/#nav=api", trJS))
cfg.data = [r1, r2, r3, r4, r5, r6]
......@@ -249,33 +262,38 @@ def documentations_table():
# configuration of the Ext.data.Store for the source code
cfg = Store()
cfg.fields = [dict(name='code', type='string'),
dict(name='source', type='string')]
cfg.fields = [
dict(name="code", type="string"),
dict(name="source", type="string")]
src = ""
if plugin.app_git:
src = "<em>git clone %s</em>" % plugin.app_git
r1 = dict(code=request.application,
source=src)
r1 = dict(code=request.application, source=src)
r2 = dict(code="plugin_dbui",
source="<em>git clone https://gitlab.in2p3.fr/w2pext/"
"plugin_dbui.git</em>")
r2 = dict(
code="plugin_dbui",
source="<em>git clone https://gitlab.in2p3.fr/w2pext/"
"plugin_dbui.git</em>")
r3 = dict(code="Web2py",
source="<em>git clone https://github.com/web2py/web2py.git</em>")
r3 = dict(
code="Web2py",
source="<em>git clone https://github.com/web2py/web2py.git</em>")
r4 = dict(code="Ext JS",
source="<em>Download from the Ext JS web site. </em><br>"
"<em>It is also available in the local directory: "
"%s/static/plugin_extjs/src</em>" % request.application)
r4 = dict(
code="Ext JS",
source="<em>Download from the Ext JS web site. </em><br>"
"<em>It is also available in the local directory: "
"%s/static/plugin_extjs/src</em>" % request.application)
r5 = dict(code="MathJax",
source="<em>git clone http://github.com/mathjax/MathJax</em>")
r5 = dict(
code="MathJax",
source="<em>git clone http://github.com/mathjax/MathJax</em>")
r6 = dict(code="Ace",
source="<em>git clone git://github.com/ajaxorg/ace.git</em>")
r6 = dict(
code="Ace",
source="<em>git clone git://github.com/ajaxorg/ace.git</em>")
cfg.data = [r1, r2, r3, r4, r5, r6]
......@@ -340,34 +358,34 @@ def index():
# css
for plg in plugins_paths:
path =plugins_paths[plg]["css"]
if path is not None:
lst.extend(get_file_paths(path, ext='.css'))
path = plugins_paths[plg]["css"]
if path is not None:
lst.extend(get_file_paths(path, ext=".css"))
lst.extend(get_file_paths(plugin.app_css, ext='.css'))
lst.extend(get_file_paths(plugin.app_css, ext=".css"))
# javascript libraries
# depend on the debug mode either minified or full version
key = ("debug" if is_debug else "libmin")
for plg in plugins_paths:
path =plugins_paths[plg][key]
if path is not None:
path = plugins_paths[plg][key]
if path is not None:
if plg == "extjs":
lst.extend(get_file_paths(path, ext='.js', alpha=False))
lst.extend(get_file_paths(path, ext=".js", alpha=False))
else:
lst.extend(get_file_paths(path, ext='.js'))
lst.extend(get_file_paths(path, ext=".js"))
path = (plugin.app_debug if is_debug else plugin.app_libmin)
lst.extend(get_file_paths(path, ext='.js'))
lst.extend(get_file_paths(path, ext=".js"))
# language
for plg in plugins_paths:
path =plugins_paths[plg]["lg"]
if path is not None:
lst.extend(get_file_paths(path, ext='.js'))
path = plugins_paths[plg]["lg"]
if path is not None:
lst.extend(get_file_paths(path, ext=".js"))
lst.extend(get_file_paths(plugin.app_lg, ext='.js'))
lst.extend(get_file_paths(plugin.app_lg, ext=".js"))
# URL for dbui configuration script
path = (plugin.dbui_conf_debug if is_debug else plugin.dbui_conf)
......@@ -388,7 +406,7 @@ def index():
'<link rel="stylesheet" type="text/css" href="%s"/>\n\t\t' % el
else:
fwlib += \
'<script type="text/javascript" src="%s"></script>\n\t\t' %el
'<script type="text/javascript" src="%s"></script>\n\t\t' % el
return dict(fwlib=fwlib)
......@@ -406,32 +424,32 @@ def latex2pdf():
# create the latex file in the private directory
cwd = os.getcwd()
os.chdir(os.path.join(request.folder, 'private'))
os.chdir(os.path.join(request.folder, "private"))
fn = str(uuid4())
fi = open('%s.tex' % fn, 'wb')
fi = open("%s.tex" % fn, "wb")
fi.write(latex_string)
fi.close()
# convert the latex file into pdf
# run latex twice for longtable, ...
cmd = ['pdflatex', '-interaction', 'nonstopmode', '%s.tex' % fn]
cmd = ["pdflatex", "-interaction", "nonstopmode", "%s.tex" % fn]
call(cmd, stdout=TemporaryFile())
call(cmd, stdout=TemporaryFile())
# clean latex processing
for ext in ('aux', 'log', 'tex'):
f = '%s.%s' % (fn, ext)
for ext in ("aux", "log", "tex"):
f = "%s.%s" % (fn, ext)
if os.path.exists(f):
os.remove(f)
# dummy pdf if latex processing failed
pdf = '%s.pdf' % fn
pdf = "%s.pdf" % fn
if not os.path.exists(pdf):
return 'Empty PDF file since LaTeX processing failed.'
return "Empty PDF file since LaTeX processing failed."
# copy the pdf file into a string an clean
fi = open(pdf, 'rb')
fi = open(pdf, "rb")
pdf_string = fi.read()
fi.close()
......@@ -451,14 +469,14 @@ def versions():
"""Return the versions of the different part of the code.
"""
from plugin_dbui import get_versions, Store
from plugin_dbui import get_versions, JSONEncoder, Store
# the configuration for the Ext.data.Store
cfg = Store()
cfg.fields = [dict(name='code', type='string'),
dict(name='version', type='string')]
cfg.fields = [dict(name="code", type="string"),
dict(name="version", type="string")]
cfg.data = get_versions()
return dict(cfg_store=json.dumps(cfg, cls=dbui.JSONEncoder))
return dict(cfg_store=json.dumps(cfg, cls=JSONEncoder))
......@@ -4,17 +4,16 @@
setup the connection to the databases
"""
#-------------------------------------------------------------------------------
# ............................................................................
#
# sqlite database
#
#-------------------------------------------------------------------------------
db = DAL('sqlite://storage.sqlite', lazy_tables=True, migrate=True)
#-------------------------------------------------------------------------------
# ............................................................................
#
# virtual database
#
#-------------------------------------------------------------------------------
virtdb = DAL(None)
......@@ -8,7 +8,7 @@ from callbacks import country_delete, country_insert, country_update
from datetime import datetime
from gluon.tools import PluginManager
#.............................................................................
# ............................................................................
#
# Language
#
......@@ -17,7 +17,7 @@ T.set_current_languages("en", "en-gb", "en-us") # mother tongue
T.force("fr-fr") # user language
T.lazy = True # no immediate translation
#.............................................................................
# ............................................................................
#
# Configure plugin_dbui
#
......@@ -46,7 +46,7 @@ plg_dbui.initialise_ui()
directSvc = plg_dbui.start_directSvc()
#.............................................................................
# ............................................................................
#
# Constants
#
......@@ -55,7 +55,7 @@ undef = T(dbui.UNDEF)
undef_id = dbui.UNDEF_ID
year = datetime.now().year
#.............................................................................
# ............................................................................
#
# Common configuration for forms and grids
#
......
......@@ -11,11 +11,11 @@ Panel = dbui.Panel
PanelWithUrlSelector = dbui.to_panelWithUrlSelector
Window = dbui.Window
#-------------------------------------------------------------------------------
# ............................................................................
#
# APPLICATION (preference, CAS, ...)
#
#-------------------------------------------------------------------------------
appNode = Node(T('Application'))
# appNode.add_child(T('preferences'), to_grid('preferences'))
......@@ -30,11 +30,11 @@ prefLeaf = Window(closable=True,
appNode.add_child(T('preferences'), prefLeaf)
#-------------------------------------------------------------------------------
# ............................................................................
#
# FORM
#
#-------------------------------------------------------------------------------
formNode = Node(T('Forms'))
for tablename in ('categories', 'harvesters', 'publications', 'new_fields'):
......@@ -46,19 +46,19 @@ for tablename in ('categories', 'harvesters', 'publications', 'new_fields'):
formNode.add_child(T(tablename), leaf)
#-------------------------------------------------------------------------------
# ............................................................................
#
# GRID
#
#-------------------------------------------------------------------------------
gridNode = Node(T('Tables'))
gridNode.add_children(db.tables, func=to_grid)
#-------------------------------------------------------------------------------
# ............................................................................
#
# HELP
#
#-------------------------------------------------------------------------------
plugin = PluginManager("dbui").dbui
loader = dict(autoLoad=True,
......@@ -98,11 +98,11 @@ helpNode.add_child(T('documentations (table)'), docLeafTable)
helpNode.add_child(T('documentations (list)'), docLeafList)
helpNode.add_child(T('versions'), versionLeaf)
#-------------------------------------------------------------------------------
# ............................................................................
#
# REPORT
#
#-------------------------------------------------------------------------------
leaf_1 = Panel(html="salut ma poule")
leaf_2 = PanelWithUrlSelector(virtdb.foo1,
......@@ -125,11 +125,11 @@ reportNode.add_child(T('report_2'), leaf_2)
reportNode.add_child(T('report_3'), leaf_3)
reportNode.add_child(T('report_4'), leaf_4)
#-------------------------------------------------------------------------------
# ............................................................................
#
# VIEWPORT
#
#-------------------------------------------------------------------------------
nodes = [helpNode,
appNode,
formNode,
......
......@@ -9,7 +9,7 @@ def country_delete(s):
"""Inhibit delete.
"""
countries = current.globalenv['db']["countries"]
countries = current.globalenv["db"]["countries"]
countries[CALLBACK_ERRORS] = "Can't delete a country."
return True
......@@ -18,7 +18,7 @@ def country_insert(f):
"""Inhibit insert.
"""
countries = current.globalenv['db']["countries"]
countries = current.globalenv["db"]["countries"]
countries[CALLBACK_ERRORS] = "Can't insert a new Country."
return True
......@@ -27,6 +27,6 @@ def country_update(s, f):
"""Inhibit update.
"""
countries = current.globalenv['db']["countries"]
countries = current.globalenv["db"]["countries"]
countries[CALLBACK_ERRORS] = "Cant't update a Country."
return True
......@@ -27,7 +27,7 @@ def INHIBIT_DELETE_UNDEF(setrows):
return False