mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-19 09:08:47 +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 psutil import ZombieProcess
|
||||||
|
|
||||||
from ..conf import settings
|
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, \
|
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
|
SHELL_LOGGER_BINARY_FILENAME, SHELL_LOGGER_DB_FILENAME, SHELL_LOGGER_DB_ENV_VAR
|
||||||
from ..logs import warn, debug
|
from ..logs import warn, debug
|
||||||
@ -40,8 +41,9 @@ def print_alias(known_args):
|
|||||||
def print_experimental_shell_history(known_args):
|
def print_experimental_shell_history(known_args):
|
||||||
settings.init(known_args)
|
settings.init(known_args)
|
||||||
|
|
||||||
filename_suffix = sys.platform
|
filename_suffix = get_shell_logger_bname_from_sys()
|
||||||
client_release = 'https://www.dropbox.com/s/m0jqp8i4c6woko5/client?dl=1'
|
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)
|
binary_path = '{}/{}'.format(settings.data_dir, SHELL_LOGGER_BINARY_FILENAME)
|
||||||
db_path = '{}/{}'.format(settings.data_dir, SHELL_LOGGER_DB_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,
|
proc = subprocess.Popen([binary_path, '-mode', 'configure'], stdout=subprocess.PIPE,
|
||||||
env=my_env)
|
env=my_env)
|
||||||
print(''.join([line.decode() for line in proc.stdout.readlines()]))
|
print(''.join([line.decode() for line in proc.stdout.readlines()]))
|
||||||
|
# TODO seems like daemon returns something, so redirect stdout so eval doesn't hang
|
||||||
try:
|
subprocess.Popen(["{} -mode daemon &".format(binary_path)], shell=True,
|
||||||
# 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,
|
env={SHELL_LOGGER_SOCKET_ENV_VAR: SHELL_LOGGER_SOCKET_PATH,
|
||||||
SHELL_LOGGER_DB_ENV_VAR: db_path})
|
SHELL_LOGGER_DB_ENV_VAR: db_path}, stdout=2)
|
||||||
except ZombieProcess as e:
|
|
||||||
warn("Zombie process is running. Please kill the running process " % e)
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,10 +16,8 @@ def get_new_command(command):
|
|||||||
sock.connect(SHELL_LOGGER_SOCKET_PATH)
|
sock.connect(SHELL_LOGGER_SOCKET_PATH)
|
||||||
sock.send(command.script.encode())
|
sock.send(command.script.encode())
|
||||||
number_of_strings = int.from_bytes(sock.recv(1), sys.byteorder)
|
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):
|
for i in range(number_of_strings):
|
||||||
length_of_string = int.from_bytes(sock.recv(1), sys.byteorder)
|
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())
|
list_of_commands.append(sock.recv(length_of_string).decode())
|
||||||
finally:
|
finally:
|
||||||
sock.close()
|
sock.close()
|
||||||
|
@ -5,3 +5,14 @@ if sys.platform == 'win32':
|
|||||||
from .win32 import * # noqa: F401,F403
|
from .win32 import * # noqa: F401,F403
|
||||||
else:
|
else:
|
||||||
from .unix import * # noqa: F401,F403
|
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