Skip to content

Commit

Permalink
Workspace Extension Functionality (#36)
Browse files Browse the repository at this point in the history
* Added Workspaces

* Version 0.2.2 -  Bug Fix
- Fixed recursion error for workspaces
- Fixed workspace description typo in settings
- Fixed viz-robotmodel.png not found

* Minor Changes
- Restored saved settings to default state
- Fixed typo in settings schema
- Removed unused import in Pkgs Module
  • Loading branch information
vkmb authored Sep 29, 2022
1 parent 8c8a1c5 commit e9aa5e4
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 21 deletions.
8 changes: 4 additions & 4 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
graft jupyter_ros_server/static
graft jupyter_ros_server/public
graft jupyter_ros_server/labextension
6 changes: 6 additions & 0 deletions js/schema/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""
}
}
}
5 changes: 3 additions & 2 deletions js/src/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ export const settings: JupyterFrontEndPlugin<void> = {
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 => {})
Expand Down
2 changes: 1 addition & 1 deletion jupyter_ros_server/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.1"
__version__ = "0.2.2"
24 changes: 21 additions & 3 deletions jupyter_ros_server/api/pkgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 = ""
Expand Down
7 changes: 4 additions & 3 deletions jupyter_ros_server/api/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
27 changes: 21 additions & 6 deletions jupyter_ros_server/lib/settings.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,58 @@
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:
with open(SETTINGS) as settings:
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("", "")
save("", "", ROS_PACKAGE_PATH)
2 changes: 1 addition & 1 deletion jupyter_ros_server/static/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"env": "", "master": ""}
{"env": "", "master": "", "workspaces": ""}
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit e9aa5e4

Please sign in to comment.