Skip to content

Commit

Permalink
remove custom base_dir i.e. the base workspace dir always uses the de…
Browse files Browse the repository at this point in the history
…fault workspace dir
  • Loading branch information
hans-permana committed Feb 10, 2017
1 parent 62c5f1a commit 90278de
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
14 changes: 5 additions & 9 deletions dedop/ui/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@


class Workspace:
def __init__(self, base_dir, name, is_current=True):
assert base_dir
def __init__(self, workspace_dir, name, is_current=True):
assert workspace_dir
assert name
self._base_dir = base_dir
self._workspace_dir = workspace_dir
self._name = name
self._is_current = is_current

@property
def base_dir(self) -> str:
return self._base_dir

@property
def name(self) -> str:
return self._name
Expand All @@ -25,7 +21,7 @@ def is_current(self) -> bool:

@property
def workspace_dir(self) -> str:
return self.get_workspace_dir(self.base_dir, self._name)
return self._workspace_dir

@classmethod
def get_workspace_dir(cls, base_dir, name) -> str:
Expand Down Expand Up @@ -61,7 +57,7 @@ def from_json_dict(cls, json_dict):
return Workspace(base_dir, workspace_name, is_current=is_current)

def to_json_dict(self):
return OrderedDict([('workspace_dir', self.base_dir),
return OrderedDict([('workspace_dir', self.workspace_dir),
('name', self.name),
('is_current', self.is_current),
])
Expand Down
14 changes: 7 additions & 7 deletions dedop/ui/workspace_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,24 @@ def set_current_workspace_name(self, workspace_name: str):
def workspace_exists(self, workspace_name) -> bool:
return os.path.exists(self.get_workspace_path(workspace_name))

def create_workspace(self, workspace_root_dir: str, workspace_name: str) -> Workspace:
def create_workspace(self, workspace_name: str) -> Workspace:
"""
:param workspace_root_dir: workspace base directory eg. ~/.dedop/workspaces
:param workspace_name: new workspace name
:raise: WorkspaceError: when workspace already exists
"""
if not workspace_name:
raise WorkspaceError('no workspace name is specified')
workspace_dir = self.get_workspace_path(workspace_root_dir, workspace_name)
workspace_dir = self.get_workspace_path(workspace_name)
if os.path.isdir(workspace_dir) and os.listdir(workspace_dir):
raise WorkspaceError('workspace "%s" already exists' % workspace_name)
self._ensure_dir_exists(workspace_dir)
return Workspace(workspace_dir, workspace_name)

def delete_workspace(self, workspace_name: str):
"""
:param workspace_name: workspace name
:raise: WorkspaceError
:param workspace_root_dir: workspace base directory eg. ~/.dedop/workspaces
:param workspace_name: workspace name to be deleted
:raise: WorkspaceError: thrown when workspace not found or cannot delete the workspace
"""
self._assert_workspace_exists(workspace_name)
dir_path = self.get_workspace_path(workspace_name)
Expand Down Expand Up @@ -305,8 +305,8 @@ def get_input_paths(self, workspace_name: str):
return [self.get_inputs_path(workspace_name, name) for name in
self.get_input_names(workspace_name)]

def get_workspace_path(self, workspace_base_dir, workspace_name, *paths):
return os.path.join(workspace_base_dir if workspace_base_dir else self._workspaces_dir, workspace_name, *paths)
def get_workspace_path(self, workspace_name, *paths):
return os.path.join(self._workspaces_dir, workspace_name, *paths)

def get_config_path(self, workspace_name, config_name, *paths):
return self.get_workspace_path(workspace_name, _CONFIGS_DIR_NAME, config_name, *paths)
Expand Down
8 changes: 6 additions & 2 deletions dedop/webapi/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def test_action(self, param1: str) -> dict:
"arg": param1
}

def new_workspace(self, workspace_name, base_dir=DEFAULT_WORKSPACE_PATH) -> dict:
workspace = self.workspace_manager.create_workspace(base_dir, workspace_name)
def new_workspace(self, workspace_name) -> dict:
workspace = self.workspace_manager.create_workspace(workspace_name)
return workspace.to_json_dict()

def delete_workspace(self, workspace_name) -> dict():
workspace = self.workspace_manager.delete_workspace(workspace_name)
return workspace.to_json_dict()

0 comments on commit 90278de

Please sign in to comment.