;; license.el -- Pamhyr ;; Copyright (C) 2023-2024 INRAE ;; ;; 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 . ;; -*- coding: utf-8 -*- (defun pamhyr-current-filename () (car (last (file-name-split (buffer-file-name))))) (defun pamhyr-insert-license () (interactive) (let ((filename (pamhyr-current-filename))) (insert (format "# %s -- Pamhyr # Copyright (C) 2024 INRAE # # 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 . # -*- coding: utf-8 -*- " filename)))) (defun pamhyr-update-license () (interactive) (let ((pos (point))) (goto-char (point-min)) (while (re-search-forward "Copyright (C) 2023 INRAE" nil t) (replace-match "Copyright (C) 2023-2024 INRAE")) (goto-char pos))) (defun pamhyr-root-dir-rec-aux (dir) (if (or (equal dir "") (equal dir "/") (equal dir nil)) nil (let ((ndir (directory-file-name (file-name-directory dir)))) (if (file-directory-p (concat ndir "/.git")) ndir (pamhyr-root-dir-rec-aux ndir))))) (defun pamhyr-root-dir () (pamhyr-root-dir-rec-aux (buffer-file-name))) (defun pamhyr--update-license (file) (message (format "Update: %s" file)) (let ((buffer (find-file file))) (with-current-buffer buffer (pamhyr-update-license) (save-buffer)) ;(kill-buffer buffer) )) (defun pamhyr--insert-license (file) (message (format "License: %s" file)) (let ((buffer (find-file file))) (with-current-buffer buffer (goto-char (point-min)) (pamhyr-insert-license) (save-buffer)) ;(kill-buffer buffer) )) (defun pamhyr-update-all-license () (interactive) (let* ((root (pamhyr-root-dir)) (files-with-copyright (split-string (shell-command-to-string (format "git -C '%s' grep -e 'Copyright (C)'|cut -d ':' -f 1|uniq|grep [.]py" root)) "\n")) (files (split-string (shell-command-to-string (format "git -C '%s' ls-files | grep [.]py" root)))) (files-without-copyright (seq-filter (lambda (file) (not (member file files-with-copyright))) files))) (message (format "%s" files-with-copyright)) (mapcar 'pamhyr--update-license (mapcar (lambda (file) (concat root "/" file)) files-with-copyright)) (message (format "%s" files-without-copyright)) (mapcar 'pamhyr--insert-license (mapcar (lambda (file) (concat root "/" file)) files-without-copyright))))