Skip to content

Commit

Permalink
new_workspace function is now available from the websocket call
Browse files Browse the repository at this point in the history
  • Loading branch information
hans-permana committed Feb 10, 2017
1 parent 6102204 commit 730ed1b
Show file tree
Hide file tree
Showing 7 changed files with 632 additions and 533 deletions.
2 changes: 1 addition & 1 deletion dedop/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from dedop.model.processor import BaseProcessor, ProcessorException
from dedop.proc.sar import L1BProcessor
from dedop.ui.workspace import WorkspaceError, WorkspaceManager
from dedop.ui.workspace_manager import WorkspaceError, WorkspaceManager
from dedop.util.config import DEFAULT_CONFIG_FILE, get_config_path, get_config_value
from dedop.util.monitor import Monitor
from dedop.version import __version__
Expand Down
1 change: 1 addition & 0 deletions dedop/conf/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

DEFAULT_DATA_DIR_NAME = '.dedop'
DEFAULT_DATA_PATH = os.path.join(os.path.expanduser('~'), DEFAULT_DATA_DIR_NAME)
DEFAULT_WORKSPACE_PATH = os.path.join(DEFAULT_DATA_PATH, 'workspaces')

#: allow a 100 ms period between two progress messages sent to the client
WEBAPI_PROGRESS_DEFER_PERIOD = 0.5
Expand Down
591 changes: 63 additions & 528 deletions dedop/ui/workspace.py

Large diffs are not rendered by default.

553 changes: 553 additions & 0 deletions dedop/ui/workspace_manager.py

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion dedop/webapi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from tornado.web import Application

from dedop.conf.defaults import WEBAPI_PROGRESS_DEFER_PERIOD, WEBAPI_LOG_FILE_PREFIX
from dedop.ui.workspace_manager import WorkspaceManager
from dedop.version import __version__
from dedop.webapi.websocket import WebSocketService

Expand All @@ -22,7 +23,7 @@ def get(self):


def service_factory(application):
return WebSocketService()
return WebSocketService(application.workspace_manager)


# All JSON REST responses should have same structure, namely a dictionary as follows:
Expand All @@ -40,6 +41,7 @@ def create_application():
(url_pattern('/app'), JsonRcpWebSocketHandler, dict(service_factory=service_factory,
report_defer_period=WEBAPI_PROGRESS_DEFER_PERIOD)),
])
application.workspace_manager = WorkspaceManager()
return application


Expand Down
12 changes: 10 additions & 2 deletions dedop/webapi/websocket.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from dedop.conf.defaults import DEFAULT_WORKSPACE_PATH
from dedop.ui.workspace_manager import WorkspaceManager


class WebSocketService:
"""
Object which implements Cate's server-side methods.
Expand All @@ -8,12 +12,16 @@ class WebSocketService:
:param: workspace_manager The current workspace manager.
"""

def __init__(self):
print("WebSocketService created")
def __init__(self, workspace_manager: WorkspaceManager):
self.workspace_manager = workspace_manager

def test_action(self, param1: str) -> dict:
return {
"status": "ok",
"content": "successful test",
"arg": param1
}

def new_workspace(self, workspace_name, base_dir=DEFAULT_WORKSPACE_PATH) -> dict:
workspace = self.workspace_manager.create_workspace(base_dir, workspace_name)
return workspace.to_json_dict()
2 changes: 1 addition & 1 deletion tests/cli/test_workspace.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os.path
from unittest import TestCase

from dedop.ui.workspace import WorkspaceManager, WorkspaceError
from dedop.ui.workspace_manager import WorkspaceManager, WorkspaceError
from dedop.util.monitor import ConsoleMonitor

TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), '..', '..', 'test_data')
Expand Down

0 comments on commit 730ed1b

Please sign in to comment.