tramp-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Review wanted for method for accessing Mock chroots


From: Tim Landscheidt
Subject: Review wanted for method for accessing Mock chroots
Date: Tue, 27 Feb 2024 15:34:14 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux)

Hi,

I finally managed to polish up my TRAMP method for accessing
Mock (https://rpm-software-management.github.io/mock/)
chroots with a view to submitting it to ELPA and would like
to solicit some feedback.  (Copyright note will be amended
prior to submission.)

Is there anything blatantly wrong/not backward-compatible/
not foreward-compatible about it?  I saved on (customizable)
variables as it is hard to predict what other users might
want/need to change.  Any advice is appreciated.

TIA,
Tim
;;; mock-tramp.el --- TRAMP integration for Mock chroots  -*- lexical-binding: 
t; -*-

;; Copyright (C) 2024  Tim Landscheidt

;; Author: Tim Landscheidt <tim@tim-landscheidt.de>
;; Version: 1.0rc1
;; Package-Requires: ((tramp "2.7.1-pre"))
;; Keywords: comm, processes

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; This package provides a TRAMP method to access Mock chroots
;; (https://rpm-software-management.github.io/mock/).  For example,
;; after running "fedpkg mockbuild --no-cleanup-after", one can edit
;; the files in the chroot by visiting "/mock:default:/path/to/file"
;; and execute commands in this chroot with M-x shell-command RET.

;;; Code:

(require 'subr-x)
(require 'tramp)

(defgroup mock-tramp nil
  "TRAMP integration for Mock chroots."
  :prefix "mock-tramp-"
  :group 'applications
  :link '(emacs-commentary-link "mock-tramp"))

;;;###autoload
(defcustom mock-tramp-method "mock"
  "TRAMP method to connect to Mock chroots."
  :type 'string
  :group 'mock-tramp)

;;;###autoload
(defun mock-tramp--list-chroots (directory)
  "Return a list of chroots defined in DIRECTORY.

The list consists of (\"\" chroot) sublists suitable for TRAMP
completion."
  ;; Unfortunately, mock provides no machine-readable list of chroots,
  ;; therefore here the logic in mock/py/mockbuild/config.py and
  ;; mock/etc/bash_completion.d/mock needs to be duplicated.  An RFE
  ;; for such an option to mock is tracked at
  ;; https://github.com/rpm-software-management/mock/issues/1294.
  (if (file-directory-p directory)
      (seq-reduce
       (lambda (r filename)
         (if (not (and (string= directory "/etc/mock")
                       (member filename '("chroot-aliases.cfg"
                                          "site-defaults.cfg"))))
             (append (list (list nil (string-remove-suffix ".cfg" filename))) r)
           r))
       (directory-files directory nil "^.*\\.cfg$" t)
       '())))

;;;###autoload
(with-eval-after-load 'tramp
  (add-to-list 'tramp-methods
               `(,mock-tramp-method
                 (tramp-login-program "mock")
                 (tramp-login-args (("-r") ("%h")
                                    ("--shell"
                                     "--"
                                     "/usr/bin/env"
                                     "PROMPT_COMMAND="
                                     "/bin/sh"
                                     "-l")))
                 (tramp-remote-shell "/bin/sh")
                 (tramp-remote-shell-args ("-i" "-c"))))
  (tramp-set-completion-function
   mock-tramp-method
   '((mock-tramp--list-chroots "/etc/mock")
     (mock-tramp--list-chroots "~/.config/mock"))))

(provide 'mock-tramp)
;;; mock-tramp.el ends here

reply via email to

[Prev in Thread] Current Thread [Next in Thread]