Skip to content

Commit

Permalink
Merge pull request #314 from doronz88/refactor/shell
Browse files Browse the repository at this point in the history
Refactor/shell
  • Loading branch information
doronz88 authored Nov 19, 2023
2 parents 1061986 + 18adcdc commit 02cb86e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/rpcclient/rpcclient/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def open(self, file: str, mode: str, access: int = 0o777) -> File:
'r+' - read and write. exception if file doesn't exist
'rw' - read and write. create if it doesn't exist. also truncate.
'w' - write only. create if it doesn't exist. also truncate.
'w+' - read and write. create if doesn't exist.
'w+' - read and write. create if it doesn't exist.
:param access: access mode as octal value
:return: a context manager file object
"""
Expand Down
10 changes: 9 additions & 1 deletion src/rpcclient/rpcclient/xonshrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import plistlib
import posixpath
import shutil
import sys
import tempfile
import time
Expand Down Expand Up @@ -204,7 +205,7 @@ def __init__(self):
* VolDown: ControlShiftDown
''')

def _register_arg_parse_alias(self, name: str, handler: Callable):
def _register_arg_parse_alias(self, name: str, handler: Union[Callable, str]):
handler = ArgParserAlias(func=handler, has_args=True, prog=name)
self._commands[name] = handler
if XSH.aliases.get(name):
Expand All @@ -228,6 +229,13 @@ def _rpc_connect(self):
"""
self.client = create_client(XSH.ctx['_create_socket_cb'])

# clear all host commands except for some useful ones
XSH.env['PATH'].clear()
for cmd in ['wc', 'grep', 'egrep', 'sed', 'awk', 'print', 'yes', 'cat']:
executable = shutil.which(cmd)
if executable is not None:
self._register_arg_parse_alias(cmd, executable)

# -- rpc
self._register_arg_parse_alias('rpc-disconnect', self._rpc_disconnect)
self._register_arg_parse_alias('rpc-which', self._rpc_which)
Expand Down

0 comments on commit 02cb86e

Please sign in to comment.