diff --git a/MANIFEST.in b/MANIFEST.in index 736f405..484349f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,8 +2,8 @@ include LICENSE include README.md include pyproject.toml -include jupyterlab_ros_server/jupyterlab_ros_server.json +include jupyter_ros_server/jupyter_ros_server.json -graft jupyterlab_ros_server/static -graft jupyterlab_ros_server/public -graft jupyterlab_ros_server/labextension \ No newline at end of file +graft jupyter_ros_server/static +graft jupyter_ros_server/public +graft jupyter_ros_server/labextension \ No newline at end of file diff --git a/js/schema/settings.json b/js/schema/settings.json index 07ca227..bde71c7 100644 --- a/js/schema/settings.json +++ b/js/schema/settings.json @@ -14,6 +14,12 @@ "title": "Master launch file", "description": "Absolute path of your launch file to initialize ROS master.\nKeep it empty to use the default one.", "default": "" + }, + "workspaces": { + "type": "string", + "title": "Workspace Paths", + "description": "Absolute paths to the workspaces separated by colons.\nExample:\n/home/jovyan/ws1:/home/jovyan/ws2:/home/jovyan/ws3\nKeep it empty to use load the workspaces sourced before jupyter lab was started.", + "default": "" } } } \ No newline at end of file diff --git a/js/src/settings/index.ts b/js/src/settings/index.ts index 4456220..983ede2 100644 --- a/js/src/settings/index.ts +++ b/js/src/settings/index.ts @@ -64,9 +64,10 @@ export const settings: JupyterFrontEndPlugin = { const loadSetting = (setting: ISettingRegistry.ISettings): void => { const env = setting.get('env').composite as string; const master = setting.get('master').composite as string; + const workspaces = setting.get('workspaces').composite as string; - if ( env != "" || master != "" ) { - const msg = { method: 'PUT', body: JSON.stringify({ env, master }) }; + if ( env != "" || master != "" || workspaces != "" ) { + const msg = { method: 'PUT', body: JSON.stringify({ env, master, workspaces }) }; ServerConnection.makeRequest(url, msg, server) .then( resp => {}) diff --git a/jupyter_ros_server/_version.py b/jupyter_ros_server/_version.py index 77648b6..984fc57 100644 --- a/jupyter_ros_server/_version.py +++ b/jupyter_ros_server/_version.py @@ -1 +1 @@ -__version__ = "0.2.1" \ No newline at end of file +__version__ = "0.2.2" \ No newline at end of file diff --git a/jupyter_ros_server/api/pkgs.py b/jupyter_ros_server/api/pkgs.py index 7615566..c8319fa 100644 --- a/jupyter_ros_server/api/pkgs.py +++ b/jupyter_ros_server/api/pkgs.py @@ -8,14 +8,32 @@ import rospkg -from ..lib import getEnv, getMaster, save +from ..lib import getEnv, getMaster, save, getWorkspaces, ROS_PACKAGE_PATH + + + class Pkgs(IPythonHandler): - rospack = rospkg.RosPack() + + def get_wsl(): + current_workspace = getWorkspaces() + current_workspace_list = current_workspace.split(':') if ":" in current_workspace else [current_workspace] + current_workspace_list = [ws.strip() for ws in current_workspace_list if len(ws.strip()) > 0] + if ROS_PACKAGE_PATH not in current_workspace_list: + current_workspace_list.append(ROS_PACKAGE_PATH) + return current_workspace_list + + startup_ws = get_wsl() + rospack = rospkg.RosPack(startup_ws) @tornado.web.authenticated def get(self, *args, **kwargs): cls = self.__class__ + current_workspace_list = cls.get_wsl() + if current_workspace_list != cls.startup_ws: + cls.rospack = rospkg.RosPack(current_workspace_list) + cls.startup_ws = current_workspace_list + print("[PKGS] : ws updated: ", " | ".join(cls.startup_ws)) if not args: self.write("Error - no argument supplied") @@ -24,8 +42,8 @@ def get(self, *args, **kwargs): print("[PKGS] get:", args[0]) + argslist = args[0].split('/') - package = argslist[0] file = '/'.join(argslist[1:]) path = "" diff --git a/jupyter_ros_server/api/setting.py b/jupyter_ros_server/api/setting.py index b1e76b8..5350a3f 100644 --- a/jupyter_ros_server/api/setting.py +++ b/jupyter_ros_server/api/setting.py @@ -3,16 +3,17 @@ import tornado from notebook.base.handlers import APIHandler -from ..lib import getEnv, getMaster, save +from ..lib import getEnv, getMaster, getWorkspaces, save class Setting(APIHandler): @tornado.web.authenticated def get(self): - self.finish(json.dumps( { 'env': getEnv(), 'master': getMaster() } )) + self.finish(json.dumps( { 'env': getEnv(), 'master': getMaster(), 'workspaces' : getWorkspaces()} )) @tornado.web.authenticated def put(self): msg = self.get_json_body() - save(msg['env'], msg['master']) + save(msg['env'], msg['master'], msg['workspaces']) + print(msg) self.finish() diff --git a/jupyter_ros_server/lib/settings.py b/jupyter_ros_server/lib/settings.py index f266a74..87c39c1 100644 --- a/jupyter_ros_server/lib/settings.py +++ b/jupyter_ros_server/lib/settings.py @@ -1,10 +1,13 @@ -from os import path +from os import path,environ import json +from tkinter import W ROOT = path.dirname(path.dirname(__file__)) PUBLIC = path.join(ROOT, 'public') SETTINGS = path.join(ROOT, 'static/settings.json') MASTER = path.join(ROOT, 'static/roslab.launch') +ROS_PACKAGE_PATH = environ.get("ROS_PACKAGE_PATH", default="").strip() + def getEnv(): try: @@ -12,32 +15,44 @@ def getEnv(): data = json.load(settings) except Exception : - data = { "env": "", "master": "" } + data = { "env": "", "master": "", "workspaces": ""} return data['env'] +def getWorkspaces(): + try: + with open(SETTINGS) as settings: + data = json.load(settings) + + except Exception : + data = { "env": "", "master": "", "workspaces": ""} + + return data['workspaces'] if data['workspaces'] != "" else ROS_PACKAGE_PATH + + def getMaster(): try: with open(SETTINGS) as settings: data = json.load(settings) except Exception : - data = { "env": "", "master": "" } + data = { "env": "", "master": "", "workspaces": ""} return data['master'] if data['master'] != "" else MASTER -def save(env, master): +def save(env, master, workspaces): try: with open(SETTINGS, 'r') as settings: data = json.load(settings) except Exception : - data = { "env": "", "master": "" } + data = { "env": "", "master": "" , "workspaces": ""} data['env'] = env data['master'] = master + data['workspaces'] = workspaces with open(SETTINGS, 'w+') as settings: json.dump(data, settings) -save("", "") \ No newline at end of file +save("", "", ROS_PACKAGE_PATH) \ No newline at end of file diff --git a/jupyter_ros_server/static/settings.json b/jupyter_ros_server/static/settings.json index 582a41d..fb90e34 100644 --- a/jupyter_ros_server/static/settings.json +++ b/jupyter_ros_server/static/settings.json @@ -1 +1 @@ -{"env": "", "master": ""} \ No newline at end of file +{"env": "", "master": "", "workspaces": ""} \ No newline at end of file diff --git a/setup.py b/setup.py index 1f5c724..c234341 100644 --- a/setup.py +++ b/setup.py @@ -63,7 +63,11 @@ 'license': "BSD-3-Clause", 'url': "https://github.com/RoboStack/jupyterlab-ros", 'include_package_data': True, - 'packages': find_packages(), + 'packages': find_packages( + where=HERE, + include=["*"], + exclude=[], + ), 'cmdclass': cmdclass, 'install_requires': [ 'rosbridge-library',