Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workspace Extension Functionality #36

Merged
merged 4 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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