grpc: added set session user call, updated mobility to look for files within new gui as well, fixed pygui issue when start session has a grpc exceptions, showing and empty error window
This commit is contained in:
parent
36123e7aa5
commit
6d4434bc12
7 changed files with 66 additions and 23 deletions
|
@ -414,6 +414,20 @@ class CoreGrpcClient:
|
||||||
request = core_pb2.SetSessionStateRequest(session_id=session_id, state=state)
|
request = core_pb2.SetSessionStateRequest(session_id=session_id, state=state)
|
||||||
return self.stub.SetSessionState(request)
|
return self.stub.SetSessionState(request)
|
||||||
|
|
||||||
|
def set_session_user(
|
||||||
|
self, session_id: int, user: str
|
||||||
|
) -> core_pb2.SetSessionUserResponse:
|
||||||
|
"""
|
||||||
|
Set session user, used for helping to find files without full paths.
|
||||||
|
|
||||||
|
:param session_id: id of session
|
||||||
|
:param user: user to set for session
|
||||||
|
:return: response with result of success or failure
|
||||||
|
:raises grpc.RpcError: when session doesn't exist
|
||||||
|
"""
|
||||||
|
request = core_pb2.SetSessionUserRequest(session_id=session_id, user=user)
|
||||||
|
return self.stub.SetSessionUser(request)
|
||||||
|
|
||||||
def add_session_server(
|
def add_session_server(
|
||||||
self, session_id: int, name: str, host: str
|
self, session_id: int, name: str, host: str
|
||||||
) -> core_pb2.AddSessionServerResponse:
|
) -> core_pb2.AddSessionServerResponse:
|
||||||
|
|
|
@ -448,6 +448,21 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
|
|
||||||
return core_pb2.SetSessionStateResponse(result=result)
|
return core_pb2.SetSessionStateResponse(result=result)
|
||||||
|
|
||||||
|
def SetSessionUser(
|
||||||
|
self, request: core_pb2.SetSessionUserRequest, context: ServicerContext
|
||||||
|
) -> core_pb2.SetSessionUserResponse:
|
||||||
|
"""
|
||||||
|
Sets the user for a session.
|
||||||
|
|
||||||
|
:param request: set session user request
|
||||||
|
:param context: context object
|
||||||
|
:return: set session user response
|
||||||
|
"""
|
||||||
|
logging.debug("set session user: %s", request)
|
||||||
|
session = self.get_session(request.session_id, context)
|
||||||
|
session.user = request.user
|
||||||
|
return core_pb2.SetSessionUserResponse(result=True)
|
||||||
|
|
||||||
def GetSessionOptions(
|
def GetSessionOptions(
|
||||||
self, request: core_pb2.GetSessionOptionsRequest, context: ServicerContext
|
self, request: core_pb2.GetSessionOptionsRequest, context: ServicerContext
|
||||||
) -> core_pb2.GetSessionOptionsResponse:
|
) -> core_pb2.GetSessionOptionsResponse:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Incorporate grpc into python tkinter GUI
|
Incorporate grpc into python tkinter GUI
|
||||||
"""
|
"""
|
||||||
|
import getpass
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
@ -71,6 +72,7 @@ class CoreClient:
|
||||||
self.default_services: Dict[NodeType, Set[str]] = {}
|
self.default_services: Dict[NodeType, Set[str]] = {}
|
||||||
self.emane_models: List[str] = []
|
self.emane_models: List[str] = []
|
||||||
self.observer: Optional[str] = None
|
self.observer: Optional[str] = None
|
||||||
|
self.user = getpass.getuser()
|
||||||
|
|
||||||
# loaded configuration data
|
# loaded configuration data
|
||||||
self.servers: Dict[str, CoreServer] = {}
|
self.servers: Dict[str, CoreServer] = {}
|
||||||
|
@ -289,6 +291,9 @@ class CoreClient:
|
||||||
self.session_id, self.handle_events
|
self.session_id, self.handle_events
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# set session user
|
||||||
|
self.client.set_session_user(self.session_id, self.user)
|
||||||
|
|
||||||
# get session service defaults
|
# get session service defaults
|
||||||
response = self.client.get_service_defaults(self.session_id)
|
response = self.client.get_service_defaults(self.session_id)
|
||||||
self.default_services = {
|
self.default_services = {
|
||||||
|
|
|
@ -188,7 +188,7 @@
|
||||||
<configuration name="error" value="0"/>
|
<configuration name="error" value="0"/>
|
||||||
</mobility_configuration>
|
</mobility_configuration>
|
||||||
<mobility_configuration node="10" model="ns2script">
|
<mobility_configuration node="10" model="ns2script">
|
||||||
<configuration name="file" value="/home/developer/.coretk/mobility/sample1.scen"/>
|
<configuration name="file" value="sample1.scen"/>
|
||||||
<configuration name="refresh_ms" value="50"/>
|
<configuration name="refresh_ms" value="50"/>
|
||||||
<configuration name="loop" value="1"/>
|
<configuration name="loop" value="1"/>
|
||||||
<configuration name="autostart" value="5"/>
|
<configuration name="autostart" value="5"/>
|
||||||
|
|
|
@ -305,7 +305,7 @@ class Toolbar(ttk.Frame):
|
||||||
self.set_runtime()
|
self.set_runtime()
|
||||||
self.app.core.set_metadata()
|
self.app.core.set_metadata()
|
||||||
self.app.core.show_mobility_players()
|
self.app.core.show_mobility_players()
|
||||||
else:
|
elif response.exceptions:
|
||||||
enable_buttons(self.design_frame, enabled=True)
|
enable_buttons(self.design_frame, enabled=True)
|
||||||
message = "\n".join(response.exceptions)
|
message = "\n".join(response.exceptions)
|
||||||
self.app.show_error("Start Session Error", message)
|
self.app.show_error("Start Session Error", message)
|
||||||
|
|
|
@ -5,10 +5,10 @@ mobility.py: mobility helpers for moving nodes and calculating wireless range.
|
||||||
import heapq
|
import heapq
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
import os
|
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from functools import total_ordering
|
from functools import total_ordering
|
||||||
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Tuple
|
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Tuple
|
||||||
|
|
||||||
from core import utils
|
from core import utils
|
||||||
|
@ -1030,30 +1030,28 @@ class Ns2ScriptedMobility(WayPointMobility):
|
||||||
def findfile(self, file_name: str) -> str:
|
def findfile(self, file_name: str) -> str:
|
||||||
"""
|
"""
|
||||||
Locate a script file. If the specified file doesn't exist, look in the
|
Locate a script file. If the specified file doesn't exist, look in the
|
||||||
same directory as the scenario file, or in the default
|
same directory as the scenario file, or in gui directories.
|
||||||
configs directory (~/.core/configs). This allows for sample files without
|
|
||||||
absolute path names.
|
|
||||||
|
|
||||||
:param file_name: file name to find
|
:param file_name: file name to find
|
||||||
:return: absolute path to the file
|
:return: absolute path to the file
|
||||||
|
:raises CoreError: when file is not found
|
||||||
"""
|
"""
|
||||||
if os.path.exists(file_name):
|
file_path = Path(file_name).expanduser()
|
||||||
return file_name
|
if file_path.exists():
|
||||||
|
return str(file_path)
|
||||||
if self.session.file_name is not None:
|
if self.session.file_name:
|
||||||
d = os.path.dirname(self.session.file_name)
|
file_path = Path(self.session.file_name).parent / file_name
|
||||||
sessfn = os.path.join(d, file_name)
|
if file_path.exists():
|
||||||
if os.path.exists(sessfn):
|
return str(file_path)
|
||||||
return sessfn
|
if self.session.user:
|
||||||
|
user_path = Path(f"~{self.session.user}").expanduser()
|
||||||
if self.session.user is not None:
|
file_path = user_path / ".core" / "configs" / file_name
|
||||||
userfn = os.path.join(
|
if file_path.exists():
|
||||||
"/home", self.session.user, ".core", "configs", file_name
|
return str(file_path)
|
||||||
)
|
file_path = user_path / ".coregui" / "mobility" / file_name
|
||||||
if os.path.exists(userfn):
|
if file_path.exists():
|
||||||
return userfn
|
return str(file_path)
|
||||||
|
raise CoreError(f"invalid file: {file_name}")
|
||||||
return file_name
|
|
||||||
|
|
||||||
def parsemap(self, mapstr: str) -> None:
|
def parsemap(self, mapstr: str) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -39,6 +39,8 @@ service CoreApi {
|
||||||
}
|
}
|
||||||
rpc SetSessionState (SetSessionStateRequest) returns (SetSessionStateResponse) {
|
rpc SetSessionState (SetSessionStateRequest) returns (SetSessionStateResponse) {
|
||||||
}
|
}
|
||||||
|
rpc SetSessionUser (SetSessionUserRequest) returns (SetSessionUserResponse) {
|
||||||
|
}
|
||||||
rpc AddSessionServer (AddSessionServerRequest) returns (AddSessionServerResponse) {
|
rpc AddSessionServer (AddSessionServerRequest) returns (AddSessionServerResponse) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,6 +299,15 @@ message SetSessionStateResponse {
|
||||||
bool result = 1;
|
bool result = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message SetSessionUserRequest {
|
||||||
|
int32 session_id = 1;
|
||||||
|
string user = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SetSessionUserResponse {
|
||||||
|
bool result = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message AddSessionServerRequest {
|
message AddSessionServerRequest {
|
||||||
int32 session_id = 1;
|
int32 session_id = 1;
|
||||||
string name = 2;
|
string name = 2;
|
||||||
|
|
Loading…
Reference in a new issue