mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-14 14:48:49 +00:00
Implement temporary fix to redirect stdout so daemon is running
This commit is contained in:
parent
72b6831485
commit
0ddcb15c96
@ -8,6 +8,7 @@ import psutil
|
||||
from psutil import ZombieProcess
|
||||
|
||||
from ..conf import settings
|
||||
from ..system import get_shell_logger_bname_from_sys
|
||||
from ..const import SHELL_LOGGER_SOCKET_ENV_VAR, SHELL_LOGGER_SOCKET_PATH, \
|
||||
SHELL_LOGGER_BINARY_FILENAME, SHELL_LOGGER_DB_FILENAME, SHELL_LOGGER_DB_ENV_VAR
|
||||
from ..logs import warn, debug
|
||||
@ -40,8 +41,9 @@ def print_alias(known_args):
|
||||
def print_experimental_shell_history(known_args):
|
||||
settings.init(known_args)
|
||||
|
||||
filename_suffix = sys.platform
|
||||
client_release = 'https://www.dropbox.com/s/m0jqp8i4c6woko5/client?dl=1'
|
||||
filename_suffix = get_shell_logger_bname_from_sys()
|
||||
client_release = 'https://github.com/nvbn/shell_logger/releases/download/0.1.0a1/shell_logger_{}'\
|
||||
.format(filename_suffix)
|
||||
binary_path = '{}/{}'.format(settings.data_dir, SHELL_LOGGER_BINARY_FILENAME)
|
||||
db_path = '{}/{}'.format(settings.data_dir, SHELL_LOGGER_DB_FILENAME)
|
||||
|
||||
@ -55,14 +57,9 @@ def print_experimental_shell_history(known_args):
|
||||
proc = subprocess.Popen([binary_path, '-mode', 'configure'], stdout=subprocess.PIPE,
|
||||
env=my_env)
|
||||
print(''.join([line.decode() for line in proc.stdout.readlines()]))
|
||||
|
||||
try:
|
||||
# If process is not running, start the process
|
||||
if SHELL_LOGGER_BINARY_FILENAME not in (p.name() for p in psutil.process_iter()):
|
||||
os.spawnve(os.P_NOWAIT, binary_path, [binary_path, '-mode', 'daemon'],
|
||||
env={SHELL_LOGGER_SOCKET_ENV_VAR: SHELL_LOGGER_SOCKET_PATH,
|
||||
SHELL_LOGGER_DB_ENV_VAR: db_path})
|
||||
except ZombieProcess as e:
|
||||
warn("Zombie process is running. Please kill the running process " % e)
|
||||
# TODO seems like daemon returns something, so redirect stdout so eval doesn't hang
|
||||
subprocess.Popen(["{} -mode daemon &".format(binary_path)], shell=True,
|
||||
env={SHELL_LOGGER_SOCKET_ENV_VAR: SHELL_LOGGER_SOCKET_PATH,
|
||||
SHELL_LOGGER_DB_ENV_VAR: db_path}, stdout=2)
|
||||
|
||||
|
||||
|
@ -16,10 +16,8 @@ def get_new_command(command):
|
||||
sock.connect(SHELL_LOGGER_SOCKET_PATH)
|
||||
sock.send(command.script.encode())
|
||||
number_of_strings = int.from_bytes(sock.recv(1), sys.byteorder)
|
||||
debug("Number of strings {}".format(number_of_strings))
|
||||
for i in range(number_of_strings):
|
||||
length_of_string = int.from_bytes(sock.recv(1), sys.byteorder)
|
||||
debug("Length {}".format(length_of_string))
|
||||
list_of_commands.append(sock.recv(length_of_string).decode())
|
||||
finally:
|
||||
sock.close()
|
||||
|
@ -5,3 +5,14 @@ if sys.platform == 'win32':
|
||||
from .win32 import * # noqa: F401,F403
|
||||
else:
|
||||
from .unix import * # noqa: F401,F403
|
||||
|
||||
|
||||
def get_shell_logger_bname_from_sys():
|
||||
"""Return the binary name associated with the current system"""
|
||||
platform = sys.platform
|
||||
if "darwin" in platform:
|
||||
return "darwin64"
|
||||
elif "linux" in platform:
|
||||
return "linux64"
|
||||
else:
|
||||
return "windows64.exe"
|
||||
|
Loading…
x
Reference in New Issue
Block a user