gnome.scm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017, 2019, 2021 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (guix import gnome)
  19. #:use-module (guix upstream)
  20. #:use-module (guix utils)
  21. #:use-module (guix packages)
  22. #:use-module (guix http-client)
  23. #:use-module (json)
  24. #:use-module (srfi srfi-1)
  25. #:use-module (srfi srfi-11)
  26. #:use-module (srfi srfi-34)
  27. #:use-module (web uri)
  28. #:use-module (ice-9 match)
  29. #:export (%gnome-updater))
  30. ;;; Commentary:
  31. ;;;
  32. ;;; This package provides not an actual importer but simply an updater for
  33. ;;; GNOME packages. It grabs package meta-data from 'cache.json' files
  34. ;;; available on ftp.gnome.org.
  35. ;;;
  36. ;;; Code:
  37. (define (jsonish->upstream-source name jsonish)
  38. "Return an <upstream-source> object for package NAME, using JSONISH as the
  39. source for metadata."
  40. (match jsonish
  41. ((version . dictionary)
  42. (upstream-source
  43. (package name)
  44. (version version)
  45. (urls (filter-map (lambda (extension)
  46. (match (assoc-ref dictionary extension)
  47. (#f
  48. #f)
  49. ((? string? relative-url)
  50. (string-append "mirror://gnome/sources/"
  51. name "/" relative-url))))
  52. '("tar.lz" "tar.xz" "tar.bz2" "tar.gz")))))))
  53. (define (latest-gnome-release package)
  54. "Return the latest release of PACKAGE, a GNOME package, or #f if it could
  55. not be determined."
  56. (define %not-dot
  57. (char-set-complement (char-set #\.)))
  58. (define (even-minor-version? version)
  59. (match (string-tokenize version %not-dot)
  60. (((= string->number major) (= string->number minor) . rest)
  61. (and minor (even? minor)))
  62. (((= string->number major) . _)
  63. ;; It should at last start with a digit.
  64. major)))
  65. (define upstream-name
  66. ;; Some packages like "NetworkManager" have camel-case names.
  67. (package-upstream-name package))
  68. (guard (c ((http-get-error? c)
  69. (if (= 404 (http-get-error-code c))
  70. #f
  71. (raise c))))
  72. (let* ((port (http-fetch/cached
  73. (string->uri (string-append
  74. "https://ftp.gnome.org/pub/gnome/sources/"
  75. upstream-name "/cache.json"))
  76. ;; ftp.gnome.org supports 'if-Modified-Since', so the local
  77. ;; cache can expire early.
  78. #:ttl (* 60 10)
  79. ;; Hide messages about URL redirects.
  80. #:log-port (%make-void-port "w")))
  81. (json (json->scm port)))
  82. (close-port port)
  83. (match json
  84. (#(4 releases _ ...)
  85. (let* ((releases (assoc-ref releases upstream-name))
  86. (latest (fold (match-lambda*
  87. (((key . value) result)
  88. (cond ((even-minor-version? key)
  89. (match result
  90. (#f
  91. (cons key value))
  92. ((newest . _)
  93. (if (version>? key newest)
  94. (cons key value)
  95. result))))
  96. (else
  97. result))))
  98. #f
  99. releases)))
  100. (and latest
  101. (jsonish->upstream-source upstream-name latest))))))))
  102. (define %gnome-updater
  103. (upstream-updater
  104. (name 'gnome)
  105. (description "Updater for GNOME packages")
  106. (pred (url-prefix-predicate "mirror://gnome/"))
  107. (latest latest-gnome-release)))