gnome.scm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017, 2019 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. (_
  63. #t))) ;cross fingers
  64. (define upstream-name
  65. ;; Some packages like "NetworkManager" have camel-case names.
  66. (package-upstream-name package))
  67. (guard (c ((http-get-error? c)
  68. (if (= 404 (http-get-error-code c))
  69. #f
  70. (raise c))))
  71. (let* ((port (http-fetch/cached
  72. (string->uri (string-append
  73. "https://ftp.gnome.org/pub/gnome/sources/"
  74. upstream-name "/cache.json"))
  75. ;; ftp.gnome.org supports 'if-Modified-Since', so the local
  76. ;; cache can expire early.
  77. #:ttl (* 60 10)))
  78. (json (json->scm port)))
  79. (close-port port)
  80. (match json
  81. (#(4 releases _ ...)
  82. (let* ((releases (assoc-ref releases upstream-name))
  83. (latest (fold (match-lambda*
  84. (((key . value) result)
  85. (cond ((even-minor-version? key)
  86. (match result
  87. (#f
  88. (cons key value))
  89. ((newest . _)
  90. (if (version>? key newest)
  91. (cons key value)
  92. result))))
  93. (else
  94. result))))
  95. #f
  96. releases)))
  97. (and latest
  98. (jsonish->upstream-source upstream-name latest))))))))
  99. (define %gnome-updater
  100. (upstream-updater
  101. (name 'gnome)
  102. (description "Updater for GNOME packages")
  103. (pred (url-prefix-predicate "mirror://gnome/"))
  104. (latest latest-gnome-release)))