From 8e1de995c37d4ada205d9087f9191a40078a0ba8 Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Sun, 14 Feb 2021 17:08:40 +0000 Subject: [PATCH 1/4] fix: Use proper uid, improve socat error message --- code_connect.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/code_connect.py b/code_connect.py index 0828fec..413f624 100755 --- a/code_connect.py +++ b/code_connect.py @@ -2,11 +2,12 @@ # based on https://stackoverflow.com/a/60949722 -from pathlib import Path -import subprocess as sp -from typing import Iterable, List, Tuple import time +import subprocess as sp import os +import distutils.spawn +from typing import Iterable, List, Tuple +from pathlib import Path MAX_IDLE_TIME = 4 * 60 * 60 @@ -38,7 +39,15 @@ def next_open_socket(socks: Iterable[Path]) -> Path: 'Please make sure to connect to this machine with a standard VS Code remote SSH session before using this tool.' ) +def preflight_checks(): + if distutils.spawn.find_executable('socat') is None: + fail( + '"socat" not found in $PATH, but is required for code-connect' + ) + def main(shell: str = None, max_idle_time: int = MAX_IDLE_TIME): + preflight_checks() + # Determine shell for outputting the proper format if not shell: shell = os.getenv('SHELL', 'bash') @@ -62,9 +71,10 @@ def main(shell: str = None, max_idle_time: int = MAX_IDLE_TIME): code_binary = code_repo / 'bin' / 'code' - # List all possible sockets + # List all possible sockets for the current user # Some of these are obsolete and not listening - socks = sort_by_access_timestamp(Path('/run/user/1000/').glob('vscode-ipc-*.sock')) + uid = os.getuid() + socks = sort_by_access_timestamp(Path('/run/user/{}/'.format(uid)).glob('vscode-ipc-*.sock')) # Only consider the ones that were active N seconds ago now = time.time() From d6ec747a94022990aa569b4fc3eff141b0e4816c Mon Sep 17 00:00:00 2001 From: Christian Volkmann Date: Sun, 14 Feb 2021 20:24:44 +0100 Subject: [PATCH 2/4] docs(README): Requirements section --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 30e6e19..b3dfd1f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,12 @@ This utility enables you to call `code .` instead, just as you would in a WSL se ### Requirements -Requires Python 3 and a **Linux** machine you want to connect to. Tested under Python 3.8, but slightly lower should work fine. +- a **Linux machine** you want to run `code-connect` on +- **Python 3** - _tested under Python 3.8, but slightly older versions should work fine_ +- **socat** - used for pinging UNIX sockets + ```bash + apt-get install socat + ``` ### VS Code Server From f583ed444f058f82cfa977ec767fd1c015481020 Mon Sep 17 00:00:00 2001 From: Christian Volkmann Date: Sun, 14 Feb 2021 20:26:48 +0100 Subject: [PATCH 3/4] style: Minor formatting --- code_connect.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/code_connect.py b/code_connect.py index 413f624..2fd89d0 100755 --- a/code_connect.py +++ b/code_connect.py @@ -5,7 +5,7 @@ import time import subprocess as sp import os -import distutils.spawn +from distutils.spawn import find_executable from typing import Iterable, List, Tuple from pathlib import Path @@ -39,14 +39,14 @@ def next_open_socket(socks: Iterable[Path]) -> Path: 'Please make sure to connect to this machine with a standard VS Code remote SSH session before using this tool.' ) -def preflight_checks(): - if distutils.spawn.find_executable('socat') is None: +def check_for_binaries(): + if find_executable('socat') is None: fail( '"socat" not found in $PATH, but is required for code-connect' ) def main(shell: str = None, max_idle_time: int = MAX_IDLE_TIME): - preflight_checks() + check_for_binaries() # Determine shell for outputting the proper format if not shell: @@ -74,7 +74,7 @@ def main(shell: str = None, max_idle_time: int = MAX_IDLE_TIME): # List all possible sockets for the current user # Some of these are obsolete and not listening uid = os.getuid() - socks = sort_by_access_timestamp(Path('/run/user/{}/'.format(uid)).glob('vscode-ipc-*.sock')) + socks = sort_by_access_timestamp(Path(f'/run/user/{uid}/').glob('vscode-ipc-*.sock')) # Only consider the ones that were active N seconds ago now = time.time() From 14e4601b6201807d476fa580df614cb4fc11e4e6 Mon Sep 17 00:00:00 2001 From: Christian Volkmann Date: Sun, 14 Feb 2021 20:48:32 +0100 Subject: [PATCH 4/4] chore: Bump version, update changelog --- CHANGELOG.md | 9 ++++++++- VERSION | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c563fd..7627335 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.1.1] - 2021-02-14 + +### Fixed + +- Now raises an error when the `socat` binary cannot be found ([#1](https://github.com/chvolkmann/code-connect/pull/1)) + ## [0.1.0] - 2021-02-13 ### Added - Initial release of `code-connect` and the corresponding fish plugin -[unreleased]: https://github.com/chvolkmann/code-connect/compare/latest...HEAD +[unreleased]: https://github.com/chvolkmann/code-connect/compare/v0.1.1...HEAD +[0.1.1]: https://github.com/chvolkmann/code-connect/compare/v0.1.0...v0.1.1 [0.1.0]: https://github.com/chvolkmann/code-connect/releases/tag/v0.1.0 diff --git a/VERSION b/VERSION index 6c6aa7c..6da28dd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0 \ No newline at end of file +0.1.1 \ No newline at end of file