1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
| | ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2024 Nicolas Graves <ngraves@ngraves.fr>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix 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.
;;;
;;; GNU Guix 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 GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (guix import libreoffice)
#:use-module (web client)
#:use-module (sxml match)
#:use-module (sxml simple)
#:use-module (guix i18n)
#:use-module (guix diagnostics)
#:use-module (guix packages)
#:use-module (guix upstream)
#:use-module (guix utils)
#:use-module (ice-9 textual-ports)
#:use-module (srfi srfi-26)
#:use-module (srfi srfi-71)
#:export (%libreoffice-updater))
(define archive-prefix
"https://downloadarchive.documentfoundation.org/libreoffice/old/")
(define libreoffice-latest-url (string-append archive-prefix "latest/src/"))
(define (libreoffice-latest-version)
(let* ((response port (http-get libreoffice-latest-url
#:streaming? #t))
(content (get-string-all port))
;; xml->sxml is not flexible enough for html.
;; For instance, <img> tags don't have closing </img>.
;; This trick preprocesses html to extract all <a> tags in
;; a <body> wrapper, which sxml-match can handle well.
(xml (xml->sxml
(string-append
"<body><"
(string-join
(filter (cute string-prefix? "a " <>)
(string-split content #\<))
"</a><")
"></a></body>")
#:trim-whitespace? #t)))
(sxml-match
xml
((*TOP*
(body
(a (@ (href "?C=N;O=D")) "Name")
(a (@ (href "?C=M;O=A")) "Last modified")
(a (@ (href "?C=S;O=A")) "Size")
(a (@ (href "/libreoffice/old/latest/")) "Parent Directory")
(a (@ (href ,link)) ,name)
. ,rest))
(if (and (string-prefix? "libreoffice-" name)
(string-suffix? ".tar.xz" name))
(string-drop
(string-drop-right name (string-length ".tar.xz"))
(string-length "libreoffice-"))
(raise
(formatted-message (G_ "Could not extract version from '~a'")
name)))))))
(define* (latest-release package #:key (version #f))
"Return an <upstream-source> for the latest-release of PACKAGE."
(let* ((name (package-name package))
(version (or version (libreoffice-latest-version))))
(upstream-source
(package name)
(version version)
(urls (list
(string-append
archive-prefix version "/src/libreoffice-" version ".tar.xz")
(string-append
"https://download.documentfoundation.org/libreoffice/src/"
(version-prefix version 3) "/libreoffice-" version ".tar.xz"))))))
(define (libreoffice-package? package)
"Return true if PACKAGE is LibreOffice."
(string=? (package-name package) "libreoffice"))
(define %libreoffice-updater
(upstream-updater
(name 'libreoffice)
(description "Updater for Libreoffice package")
(pred libreoffice-package?)
(import latest-release)))
;; libreoffice.scm ends here.
|