daemon: removed some unused Session functions and change to make proper use of set_user

This commit is contained in:
Blake Harnden 2022-03-08 15:50:19 -08:00
parent dde339cc46
commit 41db531e97
2 changed files with 9 additions and 61 deletions

View file

@ -248,13 +248,14 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
# clear previous state and setup for creation # clear previous state and setup for creation
session.clear() session.clear()
session.directory.mkdir(exist_ok=True)
if request.definition: if request.definition:
state = EventTypes.DEFINITION_STATE state = EventTypes.DEFINITION_STATE
else: else:
state = EventTypes.CONFIGURATION_STATE state = EventTypes.CONFIGURATION_STATE
session.directory.mkdir(exist_ok=True)
session.set_state(state) session.set_state(state)
session.user = request.session.user if request.session.user:
session.set_user(request.session.user)
# session options # session options
session.options.config_reset() session.options.config_reset()

View file

@ -618,26 +618,6 @@ class Session:
node.position.set_geo(lon, lat, alt) node.position.set_geo(lon, lat, alt)
self.sdt.edit_node(node, lon, lat, alt) self.sdt.edit_node(node, lon, lat, alt)
def start_mobility(self, node_ids: List[int] = None) -> None:
"""
Start mobility for the provided node ids.
:param node_ids: nodes to start mobility for
:return: nothing
"""
self.mobility.startup(node_ids)
def is_active(self) -> bool:
"""
Determine if this session is considered to be active.
(Runtime or Data collect states)
:return: True if active, False otherwise
"""
result = self.state in {EventTypes.RUNTIME_STATE, EventTypes.DATACOLLECT_STATE}
logger.info("session(%s) checking if active: %s", self.id, result)
return result
def open_xml(self, file_path: Path, start: bool = False) -> None: def open_xml(self, file_path: Path, start: bool = False) -> None:
""" """
Import a session from the EmulationScript XML format. Import a session from the EmulationScript XML format.
@ -732,23 +712,6 @@ class Session:
self.mobility.config_reset() self.mobility.config_reset()
self.link_colors.clear() self.link_colors.clear()
def start_events(self) -> None:
"""
Start event loop.
:return: nothing
"""
self.event_loop.run()
def mobility_event(self, event_data: EventData) -> None:
"""
Handle a mobility event.
:param event_data: event data to handle
:return: nothing
"""
self.mobility.handleevent(event_data)
def set_location(self, lat: float, lon: float, alt: float, scale: float) -> None: def set_location(self, lat: float, lon: float, alt: float, scale: float) -> None:
""" """
Set session geospatial location. Set session geospatial location.
@ -1025,21 +988,6 @@ class Session:
logger.exception("error reading environment file: %s", path) logger.exception("error reading environment file: %s", path)
return env return env
def set_thumbnail(self, thumb_file: Path) -> None:
"""
Set the thumbnail filename. Move files from /tmp to session dir.
:param thumb_file: tumbnail file to set for session
:return: nothing
"""
if not thumb_file.is_file():
logger.error("thumbnail file to set does not exist: %s", thumb_file)
self.thumbnail = None
return
dst_path = self.directory / thumb_file.name
shutil.copy(thumb_file, dst_path)
self.thumbnail = dst_path
def set_user(self, user: str) -> None: def set_user(self, user: str) -> None:
""" """
Set the username for this session. Update the permissions of the Set the username for this session. Update the permissions of the
@ -1048,14 +996,13 @@ class Session:
:param user: user to give write permissions to for the session directory :param user: user to give write permissions to for the session directory
:return: nothing :return: nothing
""" """
if user:
try:
uid = pwd.getpwnam(user).pw_uid
gid = self.directory.stat().st_gid
os.chown(self.directory, uid, gid)
except IOError:
logger.exception("failed to set permission on %s", self.directory)
self.user = user self.user = user
try:
uid = pwd.getpwnam(user).pw_uid
gid = self.directory.stat().st_gid
os.chown(self.directory, uid, gid)
except IOError:
logger.exception("failed to set permission on %s", self.directory)
def create_node( def create_node(
self, _class: Type[NT], start: bool, *args: Any, **kwargs: Any self, _class: Type[NT], start: bool, *args: Any, **kwargs: Any