Commit 93aaa20b authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update helper to improve get_version.

parent 7dea306f
...@@ -20,6 +20,8 @@ from gluon.validators import (IS_DATE_IN_RANGE, ...@@ -20,6 +20,8 @@ from gluon.validators import (IS_DATE_IN_RANGE,
IS_INT_IN_RANGE, IS_INT_IN_RANGE,
IS_MATCH, IS_MATCH,
IS_LENGTH) IS_LENGTH)
from pathlib import Path
GIT = "/usr/bin/git" GIT = "/usr/bin/git"
REX_REFERENCE = re.compile("^reference (\w+)$") REX_REFERENCE = re.compile("^reference (\w+)$")
...@@ -605,64 +607,40 @@ def get_versions(): ...@@ -605,64 +607,40 @@ def get_versions():
# plugin ace # plugin ace
ace = T("not install") ace = T("not install")
path = opj(server_path, "static", "plugin_ace") path = Path(server_path, "static", "plugin_ace")
if ope(path): if path.exists():
ace = T("install") ace = T("install")
# plugin dbui # plugin dbui
fn = opj(server_path, "static", "plugin_dbui", "src", "Dbui.js") path = Path(server_path, "static", "plugin_dbui", VERSION)
with open(fn, "r") as fi: if path.exists():
s = fi.read() dbui = path.read_text()
m = re.search('(version: *")([\w\._-]*)(")', s)
dbui = m.group(2)
# plugin Ext JS # plugin Ext JS
extjs = T("not install") extjs = T("not install")
path = opj(server_path, "static", "plugin_extjs") path = Path(server_path, "static", "plugin_extjs", "version.properties")
if ope(path): if path.exists():
fn = opj(path, "version.properties") data = path.read_text()
mtch = re.search(r"version.release=(\d+(\.\d+)*)", data)
with open(fn, "r") as fi: if mtch:
s = fi.read() extjs = mtch.group(1)
m = re.search(r"version.release=(\d+(\.\d+)*)", s)
if m:
extjs = m.group(1)
# plugin mathjax # plugin mathjax
mathjax = T("not install") mathjax = T("not install")
path = opj(server_path, "static", "plugin_mathjax") path = Path(server_path, "static", "plugin_mathjax", "MathJax.js")
if ope(path): if path.exists():
fn = opj(server_path, data = path.read_text()
"static", mtch = re.search(r'MathJax.version="(\d+(\.\d+)*)";', data)
"plugin_mathjax", if mtch:
"MathJax.js") mathjax = mtch.group(1)
with open(fn, "r") as fi:
s = fi.read()
m = re.search(r'MathJax.version="(\d+(\.\d+)*)";', s)
if m:
mathjax = m.group(1)
# other plugins
plugins = []
stdplgs = ("plugin_ace", "plugin_dbui", "plugin_extjs", "plugin_mathjax")
for plg in os.listdir(opj(server_path, "static")):
if plg.startswith("plugin") and plg not in stdplgs:
path = opj(server_path, "static", plg, "VERSION")
if opj(path):
with open(opj(path)) as fi:
plugins.append(dict(code=plg, version=fi.read()))
else:
plugins.append(dict(code=plg, version=T("install")))
# web2py # web2py
web2py = "" web2py = ""
val = current.request.env.web2py_version val = current.request.env.web2py_version
if isinstance(val, str): if isinstance(val, str):
m = re.match("\d+\.\d+\.\d+", val) mtch = re.match("\d+\.\d+\.\d+", val)
if m: if mtch:
web2py = m.group() web2py = 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)]
...@@ -670,12 +648,11 @@ def get_versions(): ...@@ -670,12 +648,11 @@ def get_versions():
# version of the application # version of the application
myapp = T("unknown") myapp = T("unknown")
path = Path(server_path, VERSION)
if path.exists():
myapp = path.read_text()
if ope(VERSION): elif Path(GIT).exists():
with open(opj(server_path, VERSION)) as fi:
myapp = fi.read()
elif ope(GIT):
ref_path = os.getcwd() ref_path = os.getcwd()
os.chdir(server_path) os.chdir(server_path)
...@@ -694,7 +671,6 @@ def get_versions(): ...@@ -694,7 +671,6 @@ def get_versions():
dict(code="pandas", version=pnd), dict(code="pandas", version=pnd),
dict(code=current.request.application, version=myapp)] dict(code=current.request.application, version=myapp)]
li.extend(plugins)
li.sort(key=lambda dct: dct["code"]) li.sort(key=lambda dct: dct["code"])
return li return li
......
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