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

Merge branch 'master' into 'production'

Release 1.0.1

See merge request !47
parents 62d993bf 0ca6d35d
...@@ -16,8 +16,10 @@ ...@@ -16,8 +16,10 @@
import json import json
import os import os
from gluon.tools import PluginManager from gluon.tools import PluginManager
API = """ API = """
Dbui.csvUrl = "/%s/plugin_dbui/csv"; Dbui.csvUrl = "/%s/plugin_dbui/csv";
Dbui.config = %s; Dbui.config = %s;
...@@ -32,10 +34,13 @@ Dbui.REMOTE_API = { ...@@ -32,10 +34,13 @@ Dbui.REMOTE_API = {
def about(): def about():
fn = os.path.join("applications", from pathlib import Path
request.application,
PluginManager("dbui").dbui.app_about) path = Path("applications",
return open(fn, "rb").read() request.application,
PluginManager("dbui").dbui.app_about)
return path.read_text()
def call(): def call():
...@@ -171,40 +176,45 @@ def documentations_table(): ...@@ -171,40 +176,45 @@ def documentations_table():
configuration for the documentation and for the source code. configuration for the documentation and for the source code.
""" """
from plugin_dbui import get_reference_paths, Store from pathlib import Path
from plugin_dbui import Store
def path_exists(x): # alias
return x and os.path.exists(os.path.join(apath, x)) a = '<a href="{}" target="_blank">{}</a>'
application = request.application
def f(x):
return x.replace("static/", "")
plugin = PluginManager("dbui").dbui plugin = PluginManager("dbui").dbui
# alias trDb = T("Data base scheme")
a = '<a href="%s" target="_blank">%s</a>'
trDev = T("Documentation for developers") trDev = T("Documentation for developers")
trJS = T("Javascript API") trJS = T("Javascript API")
trPy = T("Python API") trPy = T("Python API")
apath, lpath = get_reference_paths() # main paths
apath = Path("applications", application)
static = apath / "static"
# documentation of the application # documentation of the application
userdoc = "" userdoc = ""
path_db_schema = plugin.app_db_schema if plugin.app_db_schema is not None:
if path_exists(path_db_schema): path_db_schema = apath / plugin.app_db_schema
userdoc = a % (URL("static", f(path_db_schema)), T("Data base scheme")) if path_db_schema.exists():
fpath = str(path_db_schema.relative_to(static))
userdoc = a.format(URL("static", fpath), trDb)
pydoc = "" pydoc = ""
path_html_api = plugin.app_html_api if plugin.app_html_api is not None:
if path_exists(path_html_api): path_html_api = apath / plugin.app_html_api
pydoc = a % (URL("static", f(path_html_api)), trPy) if path_html_api.exists():
fpath = str(path_html_api.relative_to(static))
pydoc = a.format(URL("static", fpath), trPy)
jsdoc = "" jsdoc = ""
path_html_jsduck = plugin.app_html_jsduck if plugin.app_html_jsduck is not None:
if path_exists(path_html_jsduck): path_html_jsduck = apath / plugin.app_html_jsduck
jsdoc = a % (URL("static", f(path_html_jsduck)), trJS) if path_html_jsduck.exists():
fpath = str(path_html_jsduck.relative_to(static))
jsdoc = a.format(URL("static", fpath), trJS)
# configuration of the Ext.data.Store for the documentation # configuration of the Ext.data.Store for the documentation
cfg = Store() cfg = Store()
...@@ -222,39 +232,42 @@ def documentations_table(): ...@@ -222,39 +232,42 @@ def documentations_table():
javascript=jsdoc) javascript=jsdoc)
r2 = dict( r2 = dict(
code=a % ("https://marprod.in2p3.fr/plugin_dbui_book", "plugin_dbui"), code=a.format(
"https://marprod.in2p3.fr/plugin_dbui_book", "plugin_dbui"),
developer=a % developer=a.format(
(URL("static", "plugin_dbui/docs/reference/index.html"), trDev), URL("static", "plugin_dbui/docs/reference/index.html"), trDev),
python=a % (URL("static", "plugin_dbui/docs/api/index.html"), trPy), python=a.format(
URL("static", "plugin_dbui/docs/api/index.html"), trPy),
javascript=a % javascript=a.format(
(URL("static", "plugin_dbui/docs/jsduck/index.html"), trJS)) URL("static", "plugin_dbui/docs/jsduck/index.html"), trJS))
r3 = dict( r3 = dict(
code=a % ("http://web2py.com/", "Web2py"), code=a.format("http://web2py.com/", "Web2py"),
developer=a % ("http://web2py.com/book", trDev), developer=a.format("http://web2py.com/book", trDev),
python=a % ("http://web2py.readthedocs.org/en/latest/", trPy), python=a.format("http://web2py.readthedocs.org/en/latest/", trPy),
javascript="") javascript="")
r4 = dict( r4 = dict(
code=a % ("http://www.sencha.com/products/extjs/", "Ext JS"), code=a.format("http://www.sencha.com/products/extjs/", "Ext JS"),
developer="", developer="",
python="", python="",
javascript=a % ("http://docs.sencha.com/extjs/6.0.1-classic/", trJS)) javascript=a.format(
"http://docs.sencha.com/extjs/6.0.1-classic/", trJS))
r5 = dict( r5 = dict(
code=a % ("http://www.mathjax.org/", "MathJax"), code=a.format("http://www.mathjax.org/", "MathJax"),
developer="", developer="",
python="", python="",
javascript=a % ("http://docs.mathjax.org/", trJS)) javascript=a.format("http://docs.mathjax.org/", trJS))
r6 = dict( r6 = dict(
code=a % ("http://ace.c9.io/#nav=about", "Ace"), code=a.format("http://ace.c9.io/#nav=about", "Ace"),
developer="", developer="",
python="", python="",
javascript=a % ("http://ace.c9.io/#nav=api", trJS)) javascript=a.format("http://ace.c9.io/#nav=api", trJS))
cfg.data = [r1, r2, r3, r4, r5, r6] cfg.data = [r1, r2, r3, r4, r5, r6]
...@@ -268,7 +281,7 @@ def documentations_table(): ...@@ -268,7 +281,7 @@ def documentations_table():
src = "" src = ""
if plugin.app_git: if plugin.app_git:
src = "<em>git clone %s</em>" % plugin.app_git src = f"<em>git clone {plugin.app_git}</em>"
r1 = dict(code=request.application, source=src) r1 = dict(code=request.application, source=src)
...@@ -285,7 +298,7 @@ def documentations_table(): ...@@ -285,7 +298,7 @@ def documentations_table():
code="Ext JS", code="Ext JS",
source="<em>Download from the Ext JS web site. </em><br>" source="<em>Download from the Ext JS web site. </em><br>"
"<em>It is also available in the local directory: " "<em>It is also available in the local directory: "
"%s/static/plugin_extjs/src</em>" % request.application) f"{request.application}/static/plugin_extjs/src</em>")
r5 = dict( r5 = dict(
code="MathJax", code="MathJax",
......
""" a series of helper functions """ a series of helper functions
""" """
import os
import re import re
import subprocess
from .constant import INLINE_ALERT from .constant import INLINE_ALERT
...@@ -294,33 +292,37 @@ def get_file_paths(path, ext=None, alpha=True): ...@@ -294,33 +292,37 @@ def get_file_paths(path, ext=None, alpha=True):
alpha (bool): sort the paths in alphabetic order alpha (bool): sort the paths in alphabetic order
Returns: Returns:
list: list or string:
local paths for all selected files. * paths for all selected files,
* absolute path with respect to application
* for example: /myapp/static/myapp-min.js
""" """
li = []
if path is None: if path is None:
return li return []
server_path, client_path = get_reference_paths() lst = []
application = current.request.application
app_path = Path("applications", application)
for el in as_list(path): for el in as_list(path):
p = os.path.join(server_path, el) p = app_path / el
if os.path.isfile(p): if p.is_file():
if ext and (not el.endswith(ext)): if (ext is not None) and (p.suffix != ext):
continue continue
li.append(os.path.join(client_path, el)) lst.append(Path("/", application, el))
elif os.path.isdir(p): elif p.is_dir():
for filename in os.listdir(p): for pfile in p.iterdir():
pfile = os.path.join(el, filename) new_path = str(pfile.relative_to(app_path))
li.extend(get_file_paths(pfile, ext, alpha)) lst.extend(get_file_paths(new_path, ext, alpha))
lst = [str(el) for el in lst]
if alpha: if alpha:
li.sort() lst.sort()
return li return lst
def get_foreign_field(field): def get_foreign_field(field):
...@@ -449,18 +451,20 @@ def get_plugin_path(plugin_name): ...@@ -449,18 +451,20 @@ def get_plugin_path(plugin_name):
Returns: Returns:
str: str:
* the path of the first directory starting with ``plugin_name``. * the path of the first directory starting with ``plugin_name``.
* the local path is relative to the application directory. * absolute path with respect to application
* for example: /myapp/static/plugin_foo
* ``None`` if the plugin is not found. * ``None`` if the plugin is not found.
""" """
server_path, client_path = get_reference_paths() application = current.request.application
app_path = Path("applications", application)
# look for the full name of the plugin directory # look for the full name of the plugin directory
p_static = os.path.join(server_path, "static") p_static = app_path / "static"
for el in os.listdir(p_static): for el in p_static.iterdir():
if os.path.isdir(os.path.join(p_static, el)): if el.is_dir():
if el.startswith(plugin_name): if el.name == plugin_name:
return os.path.join(client_path, "static", el) return str(Path("/", application, "static", plugin_name))
# Nothing found # Nothing found
return None return None
...@@ -479,10 +483,12 @@ def get_reference_paths(): ...@@ -479,10 +483,12 @@ def get_reference_paths():
``("applications/myapp", "/myapp")`` ``("applications/myapp", "/myapp")``
""" """
server_path = os.path.join("applications", current.request.application) application = current.request.application
client_path = os.path.join(os.path.sep, current.request.application)
return (server_path, client_path) server_path = Path("applications", application)
client_path = Path("/", application)
return (str(server_path), str(client_path))
def get_set_field(field): def get_set_field(field):
...@@ -535,32 +541,32 @@ def get_script_path(plugin): ...@@ -535,32 +541,32 @@ def get_script_path(plugin):
Returns: Returns:
str: str:
the local path of the script file relative to the * absolute path with respect to the application
application directory. * for example /myapp/blabla.
""" """
server_path, client_path = get_reference_paths() application = current.request.application
app_path = Path("applications", application)
# script name specifies in the URL # script name specifies in the URL
if "script" in current.request.vars: if "script" in current.request.vars:
script = current.request.vars.script script = current.request.vars.script
if not script.endswith(".js"): if not script.endswith(".js"):
script = "%s.js" % script script = f"{script}.js"
pdir = os.path.join(server_path, plugin.app_script_dir)
if script not in os.listdir(pdir): pscript = app_path / plugin.app_script_dir / script
raise HTTP(500, 'Request script "%s" does not exist !!!' % script) if not pscript.exists():
raise HTTP(500, f"Request script '{script}' does not exist !!!")
return os.path.join(client_path, plugin.app_script_dir, script) return str(Path("/", application, plugin.app_script_dir, script))
# default script for the application # default script for the application
if plugin.app_script: if plugin.app_script:
return os.path.join(client_path, plugin.app_script) return str(Path("/", application, plugin.app_script))
# default script for the plugin # default script for the plugin
return os.path.join(client_path, plugin.dbui_script) return str(Path("/", application, plugin.dbui_script))
def get_store_id(name): def get_store_id(name):
...@@ -586,94 +592,96 @@ def get_versions(): ...@@ -586,94 +592,96 @@ def get_versions():
and its version identifier. The keys are ``code`` and ``version`` and its version identifier. The keys are ``code`` and ``version``
""" """
ope = os.path.exists app_path = Path("applications", current.request.application)
opj = os.path.join lst, T = [], current.T
server_path, client_path = get_reference_paths() not_install = T("not install")
T = current.T
# ........................................................................
# matplotlib library #
# Python third parties matplotlib, pandas, ...
#
try: try:
import matplotlib import matplotlib
mpl = matplotlib.__version__ ver = matplotlib.__version__
except ImportError: except ImportError:
mpl = T("not install") ver = not_install
lst.append(dict(code="matplotlib", version=ver))
# pandas library
try: try:
import pandas import pandas
pnd = pandas.__version__ ver = pandas.__version__
except ImportError: except ImportError:
pnd = T("not install") ver = not_install
# plugin ace lst.append(dict(code="pandas", version=ver))
ace = T("not install")
path = Path(server_path, "static", "plugin_ace")
if path.exists():
ace = T("install")
# plugin dbui # ........................................................................
path = Path(server_path, "static", "plugin_dbui", VERSION) #
if path.exists(): # plugin(s)
dbui = path.read_text() #
for plg in ("plugin_ace", "plugin_dbui", "plugin_event"):
ver = not_install
path = app_path / "static" / plg / VERSION
if path.exists():
ver = path.read_text()
elif Path(app_path, "static", plg).exists():
ver = T("install")
lst.append(dict(code=plg, version=ver))
# plugin Ext JS # plugin Ext JS
extjs = T("not install") ver = not_install
path = Path(server_path, "static", "plugin_extjs", "version.properties") path = app_path / "static" / "plugin_extjs" / "version.properties"
if path.exists(): if path.exists():
data = path.read_text() data = path.read_text()
mtch = re.search(r"version.release=(\d+(\.\d+)*)", data) mtch = re.search(r"version.release=(\d+(\.\d+)*)", data)
if mtch: if mtch:
extjs = mtch.group(1) ver = mtch.group(1)
lst.append(dict(code="plugin_extjs", version=ver))
# plugin mathjax # plugin mathjax
mathjax = T("not install") ver = not_install
path = Path(server_path, "static", "plugin_mathjax", "MathJax.js") path = app_path / "static" / "plugin_mathjax" / "MathJax.js"
if path.exists(): if path.exists():
data = path.read_text() data = path.read_text()
mtch = re.search(r'MathJax.version="(\d+(\.\d+)*)";', data) mtch = re.search(r'MathJax.version="(\d+(\.\d+)*)";', data)
if mtch: if mtch:
mathjax = mtch.group(1) ver = mtch.group(1)
lst.append(dict(code="plugin_mathjax", version=ver))
# ........................................................................
#
# web2py # web2py
web2py = "" #
val = current.request.env.web2py_version ver, val = "", current.request.env.web2py_version
if isinstance(val, str): if isinstance(val, str):
mtch = re.match("\d+\.\d+\.\d+", val) mtch = re.match("\d+\.\d+\.\d+", val)
if mtch: if mtch:
web2py = mtch.group() ver = mtch.group()
elif isinstance(val, (tuple, list)): elif isinstance(val, (tuple, list)):
li = [str(plg) for plg in val if isinstance(plg, int)] li = [str(plg) for plg in val if isinstance(plg, int)]
web2py = ".".join(li) ver = ".".join(li)
# version of the application
myapp = T("unknown")
path = Path(server_path, VERSION)
if path.exists():
myapp = path.read_text()
elif Path(GIT).exists(): lst.append(dict(code="web2py", version=ver))
ref_path = os.getcwd()
os.chdir(server_path)
myapp = subprocess.check_output(["git", "describe", "--tags"]) # ........................................................................
myapp = myapp.strip("\n") #
# application
ver = T("unknown")
path = app_path / VERSION
if path.exists():
ver = path.read_text()
os.chdir(ref_path) lst.append(dict(code=current.request.application, version=ver))
# prepare the output # prepare the output
li = [dict(code="web2py", version=web2py), lst.sort(key=lambda dct: dct["code"])
dict(code="plugin_dbui", version=dbui), return lst
dict(code="plugin_extjs", version=extjs),
dict(code="plugin_mathjax", version=mathjax),
dict(code="plugin_ace", version=ace),
dict(code="matplotlib", version=mpl),
dict(code="pandas", version=pnd),
dict(code=current.request.application, version=myapp)]
li.sort(key=lambda dct: dct["code"])
return li
def get_where_query(table): def get_where_query(table):
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
HEAD HEAD
1.0 (Dec 2019) 1.0.1 (Dec 2019)
- Require python 3.7 - Require python 3.7
- Requires web2py 2.18.3, matplotlib 3.1.1, pandas 0.25.2 or above. - Requires web2py 2.18.3, matplotlib 3.1.1, pandas 0.25.2 or above.
- Migration to building tool w2pext/utilities release 1.0. - Migration to building tool w2pext/utilities release 1.0.
......
1.0 1.0.1
\ No newline at end of file \ No newline at end of file