Pamhyr2/tools/license.el

168 lines
5.7 KiB
EmacsLisp

;; 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 <https://www.gnu.org/licenses/>.
;; -*- 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 <https://www.gnu.org/licenses/>.
# -*- 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))
"\n"))
(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))))
(defvar pamhyr-mail-template "Bonjour,
La version @version de Pamhyr2 est disponible.
<NEWS>
---Change-logs-------------------@version---
@description
------------------------------------------
---Liens-utiles---------------------------
Télécharger cette version :
https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/releases/@version
La documentation (en anglais) :
https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/wikis/home
Rapporter un problème :
https://gitlab.irstea.fr/theophile.terraz/pamhyr/-/issues
ou directement par mail à :
<pierre-antoine.rouby@inrae.fr>
------------------------------------------
<FUTURE_WORK>
---/!\--Attention-------------------------
Pour les utilisateurs Windows : Certains antivirus peuvent détecter Pamhyr2 comme un virus, c'est un faux positif, le problème est connu et vient de l'exécutable généré par PyInstaller.
Nous n'avons pas encore de solution pour régler ce problème.
Si c'est votre cas, il faudra ajouter une exception dans votre antivirus si vous voulez utiliser Pamhyr2.
Sinon, il est aussi possible de passer par WSL et utiliser la version Linux sous Windows.
Rapport d'antivirus : <LINK_VIRUSTOTAL>
------------------------------------------
Bon weekend,
")
(require 'web)
(require 'json)
(defun pamhyr-release-mail (release)
(interactive "sRelease name: ")
(web-http-get
(lambda (httpc header my-data)
(let* ((data (json-read-from-string my-data))
(release (cdr (assoc 'tag_name data)))
(description (cdr (assoc 'description data))))
(let ((buffer (generate-new-buffer (format "* mail-%s *" release))))
(with-current-buffer buffer
(insert
(string-replace "@description" description
(string-replace "@version" release
pamhyr-mail-template)))
(set-buffer buffer)))))
:url (concat "https://gitlab.irstea.fr/api/v4/projects/2779/releases/" release)))