Commit 08cd6fe9 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update helper to use Path in get_script_path and get_reference_paths.

parent 1412c378
""" a series of helper functions
"""
import os
import re
import subprocess
from .constant import INLINE_ALERT
......@@ -485,10 +483,12 @@ def get_reference_paths():
``("applications/myapp", "/myapp")``
"""
server_path = os.path.join("applications", current.request.application)
client_path = os.path.join(os.path.sep, current.request.application)
application = current.request.application
server_path = Path("applications", application)
client_path = Path("/", application)
return (server_path, client_path)
return (str(server_path), str(client_path))
def get_set_field(field):
......@@ -541,32 +541,32 @@ def get_script_path(plugin):
Returns:
str:
the local path of the script file relative to the
application directory.
* absolute path with respect to the application
* 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
if "script" in current.request.vars:
script = current.request.vars.script
if not script.endswith(".js"):
script = "%s.js" % script
pdir = os.path.join(server_path, plugin.app_script_dir)
script = f"{script}.js"
if script not in os.listdir(pdir):
raise HTTP(500, 'Request script "%s" does not exist !!!' % script)
pscript = app_path / plugin.app_script_dir / 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
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
return os.path.join(client_path, plugin.dbui_script)
return str(Path("/", application, plugin.dbui_script))
def get_store_id(name):
......
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