From: Michael Albinus Date: Wed, 29 May 2024 16:29:52 +0000 (+0200) Subject: Add Tramp distrobox method X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=cb6cf95e39f90f96acc93574ecbeb1d08594cadd;p=emacs.git Add Tramp distrobox method * doc/misc/tramp.texi (Inline methods) : Add. * etc/NEWS: Mention Tramp distrobox method. * lisp/net/tramp-container.el (tramp-distrobox-program): New defcustom. (tramp-distrobox-method): New defconst. (tramp-distrobox--completion-function) (tramp-enable-distrobox-method): New defuns. (Bug#71200) (tramp-docker-method, tramp-dockercp-method) (tramp-podman-method, tramp-podmancp-method) (tramp-kubernetes-method, tramp-flatpak-method) (tramp-apptainer-method, tramp-nspawn-method): Adapt docstring. * test/lisp/net/tramp-tests.el (tramp--test-box-p): Rename from `tramp--test-toolbox-p'. Add distrobox. Adapt callees. (cherry picked from commit 17c23a46c3d834e7dc9f153e86a51242b3867b74) --- diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi index 05403956ff9..9d53de1a41e 100644 --- a/doc/misc/tramp.texi +++ b/doc/misc/tramp.texi @@ -1005,15 +1005,19 @@ in a pod is used. This method does not support user names. @item @option{toolbox} +@item @option{distrobox} @cindex method @option{toolbox} @cindex @option{toolbox} method +@cindex method @option{distrobox} +@cindex @option{distrobox} method -Integration of Toolbox system containers. The host name may be either -a container's name or ID, as returned by @samp{toolbox list -c}. -Without a host name, the default Toolbox container for the host will -be used. +Integration of Toolbox or Distrobox system containers, respectively. +The host name may be either a container's name or ID, as returned by +@samp{toolbox list -c} or @samp{distrobox list}. Without a host name, +the default Toolbox container for the host will be used. There is no +such default for Distrobox. -This is an optional method, @pxref{Optional methods}. It does not +These are optional methods, @pxref{Optional methods}. They do not support user names. @item @option{flatpak} diff --git a/etc/NEWS b/etc/NEWS index 3efd5612f07..c9c9def537d 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1166,7 +1166,7 @@ mode line. 'header' will display in the header line; +++ *** New user option 'which-func-update-delay'. This replaces the user option 'idle-update-delay', which was previously -used to control the delay before `which-function-mode` updated its +used to control the delay before 'which-function-mode' updated its display. The user option 'idle-update-delay', which was only used by Which Function mode, is now obsolete. @@ -1195,10 +1195,11 @@ These are the external methods counterparts of "docker" and "podman". +++ *** New optional connection methods for containers. -Tere are new optional connection methods "toolbox", "flatpak", -"apptainer" and "nspawn". They allow accessing system containers -provided by Toolbox, sandboxes provided by Flatpak, instances managed by -Apptainer, or accessing systemd-based light-weight containers.. +There are new optional connection methods "toolbox", "distrobox", +"flatpak", "apptainer" and "nspawn". They allow accessing system +containers provided by Toolbox or Distrobox, sandboxes provided by +Flatpak, instances managed by Apptainer, or accessing systemd-based +light-weight containers.. +++ *** Connection method "kubernetes" supports now optional container name. @@ -2196,7 +2197,7 @@ and 'closure' is the common parent type of 'interpreted-function' and 'byte-code-function'. Those new types come with the associated new predicates 'closurep' and -`interpreted-function-p' as well as a new constructor +'interpreted-function-p' as well as a new constructor 'make-interpreted-closure'. ** New function 'help-fns-function-name'. diff --git a/lisp/net/tramp-container.el b/lisp/net/tramp-container.el index 2886e25d16b..cc1d9f457cc 100644 --- a/lisp/net/tramp-container.el +++ b/lisp/net/tramp-container.el @@ -76,6 +76,17 @@ ;; ;; ;; +;; Open a file on an existing Distrobox container: +;; +;; C-x C-f /distrobox:CONTAINER:/path/to/file +;; +;; Where: +;; CONTAINER is the container to connect to. +;; +;; If the container is not running, it is started. +;; +;; +;; ;; Open a file on a running Flatpak sandbox: ;; ;; C-x C-f /flatpak:SANDBOX:/path/to/file @@ -153,6 +164,14 @@ If it is nil, the default context will be used." :type '(choice (const "toolbox") (string))) +;;;###tramp-autoload +(defcustom tramp-distrobox-program "distrobox" + "Name of the Distrobxx client program." + :group 'tramp + :version "30.1" + :type '(choice (const "distrobox") + (string))) + ;;;###tramp-autoload (defcustom tramp-flatpak-program "flatpak" "Name of the Flatpak client program." @@ -178,41 +197,45 @@ If it is nil, the default context will be used." ;;;###tramp-autoload (defconst tramp-docker-method "docker" - "Tramp method name to use to connect to Docker containers.") + "Tramp method name to connect to Docker containers.") ;;;###tramp-autoload (defconst tramp-dockercp-method "dockercp" - "Tramp method name to use to connect to Docker containers. + "Tramp method name to connect to Docker containers. This is for out-of-band connections.") ;;;###tramp-autoload (defconst tramp-podman-method "podman" - "Tramp method name to use to connect to Podman containers.") + "Tramp method name to connect to Podman containers.") ;;;###tramp-autoload (defconst tramp-podmancp-method "podmancp" - "Tramp method name to use to connect to Podman containers. + "Tramp method name to connect to Podman containers. This is for out-of-band connections.") ;;;###tramp-autoload (defconst tramp-kubernetes-method "kubernetes" - "Tramp method name to use to connect to Kubernetes containers.") + "Tramp method name to connect to Kubernetes containers.") ;;;###tramp-autoload (defconst tramp-toolbox-method "toolbox" - "Tramp method name to use to connect to Toolbox containers.") + "Tramp method name to connect to Toolbox containers.") + +;;;###tramp-autoload +(defconst tramp-distrobox-method "distrobox" + "Tramp method name to connect to Distrobox containers.") ;;;###tramp-autoload (defconst tramp-flatpak-method "flatpak" - "Tramp method name to use to connect to Flatpak sandboxes.") + "Tramp method name to connect to Flatpak sandboxes.") ;;;###tramp-autoload (defconst tramp-apptainer-method "apptainer" - "Tramp method name to use to connect to Apptainer instances.") + "Tramp method name to connect to Apptainer instances.") ;;;###tramp-autoload (defconst tramp-nspawn-method "nspawn" - "Tramp method name to use to connect to systemd-nspawn containers.") + "Tramp method name to connect to systemd-nspawn containers.") ;;;###tramp-autoload (defmacro tramp-skeleton-completion-function (method &rest body) @@ -381,6 +404,7 @@ see its function help for a description of the format." (when-let ((raw-list (shell-command-to-string (concat program " list -c"))) ;; Ignore header line. (lines (cdr (split-string raw-list "\n" 'omit))) + ;; We do not show container IDs. (names (tramp-compat-seq-keep (lambda (line) (when (string-match @@ -391,6 +415,28 @@ see its function help for a description of the format." lines))) (mapcar (lambda (name) (list nil name)) names)))) +;;;###tramp-autoload +(defun tramp-distrobox--completion-function (method) + "List Distrobox containers available for connection. + +This function is used by `tramp-set-completion-function', please +see its function help for a description of the format." + (tramp-skeleton-completion-function method + (when-let ((raw-list (shell-command-to-string (concat program " list"))) + ;; Ignore header line. + (lines (cdr (split-string raw-list "\n" 'omit))) + ;; We do not show container IDs. + (names (tramp-compat-seq-keep + (lambda (line) + (when (string-match + (rx bol (1+ (not space)) + (1+ space) "|" (1+ space) + (group (1+ (not space))) space) + line) + (match-string 1 line))) + lines))) + (mapcar (lambda (name) (list nil name)) names)))) + ;;;###tramp-autoload (defun tramp-flatpak--completion-function (method) "List Flatpak sandboxes available for connection. @@ -595,6 +641,26 @@ see its function help for a description of the format." tramp-toolbox-method `((tramp-toolbox--completion-function ,tramp-toolbox-method)))) +;;;###tramp-autoload +(defun tramp-enable-distrobox-method () + "Enable connection to Distrobox containers." + (add-to-list 'tramp-methods + `(,tramp-distrobox-method + (tramp-login-program ,tramp-distrobox-program) + (tramp-login-args (("enter") + ("-n" "%h") + ("--" "%l"))) + ;(tramp-direct-async (,tramp-default-remote-shell "-c")) + (tramp-remote-shell ,tramp-default-remote-shell) + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")))) + + (add-to-list 'tramp-completion-multi-hop-methods tramp-distrobox-method) + + (tramp-set-completion-function + tramp-distrobox-method + `((tramp-distrobox--completion-function ,tramp-distrobox-method)))) + ;;;###tramp-autoload (defun tramp-enable-flatpak-method () "Enable connection to Flatpak sandboxes." diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 474bb4c350c..6f66352c453 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -6762,6 +6762,13 @@ This is used in tests which we don't want to tag (not (and (tramp--test-adb-p) (string-match-p (rx multibyte) default-directory))))) +(defun tramp--test-box-p () + "Check, whether the toolbox or distrobox method is used. +This does not support `tramp-test45-asynchronous-requests'." + (string-match-p + (rx bol (| "toolbox" "distrobox") eol) + (file-remote-p ert-remote-temporary-file-directory 'method))) + (defun tramp--test-container-p () "Check, whether a container method is used. This does not support some special file names." @@ -6912,12 +6919,6 @@ This does not support special file names." (string-equal "telnet" (file-remote-p ert-remote-temporary-file-directory 'method))) -(defun tramp--test-toolbox-p () - "Check, whether the toolbox method is used. -This does not support `tramp-test45-asynchronous-requests'." - (string-equal - "toolbox" (file-remote-p ert-remote-temporary-file-directory 'method))) - (defun tramp--test-windows-nt-p () "Check, whether the locale host runs MS Windows." (eq system-type 'windows-nt)) @@ -7406,7 +7407,7 @@ process sentinels. They shall not disturb each other." (skip-unless (not (tramp--test-container-p))) (skip-unless (not (tramp--test-sshfs-p))) (skip-unless (not (tramp--test-telnet-p))) - (skip-unless (not (tramp--test-toolbox-p))) + (skip-unless (not (tramp--test-box-p))) (skip-unless (not (tramp--test-windows-nt-p))) (with-timeout