;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2019 Efraim Flashner ;;; Copyright © 2019 Tobias Geerinckx-Rice ;;; ;;; 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 . (define-module (gnu packages perl6) #:use-module ((guix licenses) #:prefix license:) #:use-module (guix download) #:use-module (guix git-download) #:use-module (guix packages) #:use-module (guix build-s
aboutsummaryrefslogtreecommitdiff
blob: 01171e253f910d7f46d617ce9145b615787aa544 (about) (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
;;;
;;; 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 (gnu installer newt locale)
  #:use-module (gnu installer locale)
  #:use-module (gnu installer steps)
  #:use-module (gnu installer newt page)
  #:use-module (guix i18n)
  #:use-module (newt)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:use-module (srfi srfi-34)
  #:use-module (srfi srfi-35)
  #:use-module (ice-9 match)
  #:export (run-locale-page))

(define (run-language-page languages language->text)
  (define result
    (run-listbox-selection-page
     #:title (G_ "Locale language")
     #:info-text (G_ "Choose the language to use for the \
installation process and for the installed system.")
     #:info-textbox-width 70
     #:listbox-items languages
     #:listbox-item->text language->text
     #:sort-listbox-items? #f
     #:button-text (G_ "Exit")
     #:button-callback-procedure
     (lambda _
       (abort-to-prompt 'installer-step 'abort))))

  ;; Immediately install the chosen language so that the territory page that
  ;; comes after (optionally) is displayed in the chosen language.
  (setenv "LANGUAGE" result)

  result)

(define (run-territory-page territories territory->text)
  (let ((title (G_ "Locale location")))
    (run-listbox-selection-page
     #:title title
     #:info-text (G_ "Choose a territory for this language.")
     #:listbox-items territories
     #:listbox-item->text territory->text
     #:button-text (G_ "Back")
     #:button-callback-procedure
     (lambda _
       (abort-to-prompt 'installer-step 'abort)))))

(define (run-codeset-page codesets)
  (let ((title (G_ "Locale codeset")))
    (run-listbox-selection-page
     #:title title
     #:info-text (G_ "Choose the locale encoding.")
     #:listbox-items codesets
     #:listbox-item->text identity
     #:listbox-default-item "UTF-8"
     #:button-text (G_ "Back")
     #:button-callback-procedure
     (lambda _
       (abort-to-prompt 'installer-step 'abort)))))

(define (run-modifier-page modifiers modifier->text)
  (let ((title (G_ "Locale modifier")))
    (run-listbox-selection-page
     #:title title
     #:info-text (G_ "Choose your locale's modifier. The most frequent \
modifier is euro. It indicates that you want to use Euro as the currency \
symbol.")
     #:listbox-items modifiers
     #:listbox-item->text modifier->text
     #:button-text (G_ "Back")
     #:button-callback-procedure
     (lambda _
       (abort-to-prompt 'installer-step 'abort)))))

(define* (run-locale-page #:key
                          supported-locales
                          iso639-languages
                          iso3166-territories)
  "Run a page asking the user to select a locale language and possibly
territory, codeset and modifier. Use SUPPORTED-LOCALES as the list of glibc
available locales. ISO639-LANGUAGES is an association list associating a
locale code to a locale name. ISO3166-TERRITORIES is an association list
associating a territory code with a territory name. The formatted locale, under
glibc format is returned."

  (define (break-on-locale-found locales)
    "Break to the installer step if LOCALES contains exactly one
element."
    (and (= (length locales) 1)
         (abort-to-prompt 'installer-step 'break)))

  (define (filter-locales locales result)
    "Filter the list of locale records LOCALES using the RESULT returned by
the installer-steps defined below."
    (filter
     (lambda (locale)
       (and-map identity
                `(,(string=? (locale-language locale)
                             (result-step result 'language))
                  ,@(if (result-step-done? result 'territory)
                        (list (equal? (locale-territory locale)
                                      (result-step result 'territory)))
                        '())
                  ,@(if (result-step-done? result 'codeset)
                        (list (equal? (locale-codeset locale)
                                      (result-step result 'codeset)))
                        '())
                  ,@(if (result-step-done? result 'modifier)
                        (list (equal? (locale-modifier locale)
                                      (result-step result 'modifier)))
                        '()))))
     locales))

  (define (result->locale-string locales result)
    "Supposing that LOCALES contains exactly one locale record, turn it into a
glibc locale string and return it."
    (match (filter-locales locales result)
      ((locale)
       (locale->locale-string locale))))

  (define (sort-languages languages)
    "Extract some languages from LANGUAGES list and place them ahead."
    (let* ((first-languages '("en"))
           (other-languages (lset-difference equal?
                                             languages
                                             first-languages)))
      `(,@first-languages ,@other-languages)))

  (define locale-steps
    (list
     (installer-step
      (id 'language)
      (compute
       (lambda _
         (run-language-page
          (sort-languages
           (delete-duplicates (map locale-language supported-locales)))
          (lambda (language)
            (let ((english (language-code->language-name iso639-languages
                                                         language)))
              (setenv "LANGUAGE" language)
              (let ((native (gettext english "iso_639-3")))
                (unsetenv "LANGUAGE")
                native)))))))
     (installer-step
      (id 'territory)
      (compute
       (lambda (result _)
         (let ((locales (filter-locales supported-locales result)))
           ;; Stop the process if the language returned by the previous step
           ;; is matching one and only one supported locale.
           (break-on-locale-found locales)

           ;; Otherwise, ask the user to select a territory among those
           ;; supported by the previously selected language.
           (run-territory-page
            (delete-duplicates (map locale-territory locales))
            (lambda (territory)
              (if territory
                  (let ((english (territory-code->territory-name
                                  iso3166-territories territory)))
                    (gettext english "iso_3166-1"))
                  (G_ "No location"))))))))
     (installer-step
      (id 'codeset)
      (compute
       (lambda (result _)
         (let ((locales (filter-locales supported-locales result)))
           ;; Same as above but we now have a language and a territory to
           ;; narrow down the search of a locale.
           (break-on-locale-found locales)

           ;; Otherwise, choose a codeset.
           (let ((codesets (delete-duplicates (map locale-codeset locales))))
             (if (member "UTF-8" codesets)
                 "UTF-8"                          ;don't even ask
                 (run-codeset-page codesets)))))))
     (installer-step
      (id 'modifier)
      (compute
       (lambda (result _)
         (let ((locales (filter-locales supported-locales result)))
           ;; Same thing with a language, a territory and a codeset this time.
           (break-on-locale-found locales)

           ;; Otherwise, ask for a modifier.
           (run-modifier-page
            (delete-duplicates (map locale-modifier locales))
            (lambda (modifier)
              (or modifier (G_ "No modifier"))))))))))

  ;; If run-installer-steps returns locally, it means that the user had to go
  ;; through all steps (language, territory, codeset and modifier) to select a
  ;; locale. In that case, like if we exited by breaking to the installer
  ;; step, turn the result into a glibc locale string and return it.
  (result->locale-string
   supported-locales
   (run-installer-steps #:steps locale-steps)))
hub.com/jonathanstowe/META6") (commit (string-append "v" version)))) (file-name (git-file-name name version)) (sha256 (base32 "1xnlaamfbdlfb2zidim3bbc4mawsrg6qxhxi6gbld46z1cyry1cw")))) (build-system rakudo-build-system) (propagated-inputs (list perl6-json-class)) (native-inputs (list perl6-json-fast)) (home-page "https://github.com/jonathanstowe/META6") (synopsis "Do things with Perl 6 [META files]") (description "This provides a representation of the Perl 6 META files specification - the META file data can be read, created, parsed and written in a manner that is conformant with the specification. Where they are known about it also makes allowance for customary usage in existing software (such as installers and so forth.) The intent of this is allow the generation and testing of META files for module authors, so it can provide meta-information whether the attributes are mandatory as per the spec and where known the places that customary attributes are used.") (license license:artistic2.0))) (define-public perl6-mime-base64 (package (name "perl6-mime-base64") (version "1.2.1") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/perl6/Perl6-MIME-Base64") (commit (string-append "v" version)))) (file-name (git-file-name name version)) (sha256 (base32 "0l67m8mvz3gxml425sd1ggfnhzh4lf754k7w8fngfr453s6lsza1")))) (build-system rakudo-build-system) (arguments '(#:with-zef? #f)) (home-page "https://github.com/perl6/Perl6-MIME-Base64") (synopsis "Encoding and decoding Base64 ASCII strings") (description "This Perl 6 module implements encoding and decoding to and from base64.") (license license:artistic2.0))) (define-public perl6-oo-monitors (package (name "perl6-oo-monitors") (version "1.1") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/jnthn/oo-monitors") ;; The commit where 1.1 was "tagged" (commit "494db3a3852854f30a80c9bd1489a7d5e429e7c5"))) (file-name (git-file-name name version)) (sha256 (base32 "1sbw2x54wwjjanghjnc7ipmplaw1srvbrphsdv4ym6cipnbmbj9x")))) (build-system rakudo-build-system) (arguments '(#:with-zef? #f)) (home-page "https://github.com/jnthn/oo-monitors") (synopsis "Monitors with condition variables for Perl 6") (description "A monitor provides per-instance mutual exclusion for objects. This means that for a given object instance, only one thread can ever be inside its methods at a time. This is achieved by a lock being associated with each object. The lock is acquired automatically at the entry to each method in the monitor. Condition variables are also supported.") (license license:artistic2.0))) (define-public perl6-svg ;; Latest commit, basically unchanged since August 2015 (let ((commit "07190c0602aa276e5319f06aa0012452dbff3582") (revision "1")) (package (name "perl6-svg") (version (git-version "0.0.0" revision commit)) (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/moritz/svg") (commit commit))) (file-name (git-file-name name version)) (sha256 (base32 "0mkjdhg7ajksdn61n8fqhyzfd7ly9myazsvpsm02a5c2q73hdygg")))) (build-system rakudo-build-system) (propagated-inputs (list perl6-xml-writer)) (home-page "https://github.com/moritz/svg") (synopsis "Perl 6 module to generate SVG") (description "This is a Perl 6 module that makes it easy to write @dfn{Scalable Vector Graphic files} (SVG). Right now it is a shallow wrapper around @code{XML::Writer}, adding only the xmlns attributes that identifies an XML file as SVG.") (license license:artistic2.0)))) (define-public perl6-svg-plot ;; Latest commit (let ((commit "062570a78fd38c3c6baba29dfe2fbb8ca014f4de") (revision "1")) (package (name "perl6-svg-plot") (version (git-version "0.0.0" revision commit)) (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/moritz/svg-plot") (commit commit))) (file-name (git-file-name name version)) (sha256 (base32 "095ga5hbg92jnmczxvhk1hjz14yr334zyf8cph4w5w5frcza44my")))) (build-system rakudo-build-system) (propagated-inputs (list perl6-svg)) (home-page "https://github.com/moritz/svg-plot") (synopsis "Perl 6 charting and plotting library that produces SVG output") (description "@code{SVG::Plot} is a simple 2D chart plotter for Perl 6. It currently supports bars, stacked bars, lines and points (both equally spaced with optional labels, or xy plots).") (license license:artistic2.0)))) (define-public perl6-tap-harness (package (name "perl6-tap-harness") (version "0.0.7") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/perl6/tap-harness6") (commit (string-append "v" version)))) (file-name (git-file-name name version)) (sha256 (base32 "1lig8i0my3fgqvlay9532xslbf3iis2d7wz89gniwvwqffi2kh6r")))) (build-system rakudo-build-system) (arguments '(#:with-zef? #f #:with-prove6? #f #:phases (modify-phases %standard-phases (replace 'check (lambda _ (invoke "perl6" "-Ilib" "bin/prove6" "-l" "t")))))) (home-page "https://github.com/perl6/tap-harness6/") (synopsis "TAP harness for perl6") (description "This module provides the @command{prove6} command which runs a TAP based test suite and prints a report. The @command{prove6} command is a minimal wrapper around an instance of this module.") (license license:artistic2.0))) (define-public perl6-terminal-ansicolor (package (name "perl6-terminal-ansicolor") (version "0.5") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/tadzik/Terminal-ANSIColor") ;; The commit where 0.5 was "tagged" (commit "edded4a7116ce11cbc9fb5a83669c7ba119d0212"))) (file-name (git-file-name name version)) (sha256 (base32 "1apm999azkyg5s35gid12wq019aqnvzrkz7qjmipd74mdxgr00x7")))) (build-system rakudo-build-system) (arguments '(#:with-zef? #f)) (home-page "https://github.com/tadzik/Terminal-ANSIColor") (synopsis "Colorize terminal output") (description "This is a @code{Terminal::ANSIColor} module for Perl 6.") (license license:expat))) (define-public perl6-test-meta (package (name "perl6-test-meta") (version "0.0.14") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/jonathanstowe/Test-META") (commit (string-append "v" version)))) (file-name (git-file-name name version)) (sha256 (base32 "1mzrglb7lbiy5h9dlc7dyhvv9gppxmdmpmrv6nzbd695jzr38bri")))) (build-system rakudo-build-system) (propagated-inputs (list perl6-meta6 perl6-uri)) (home-page "https://github.com/jonathanstowe/Test-META") (synopsis "Test a distributions META file") (description "This provides a simple mechanism for module authors to have some confidence that they have a working distribution META description file.") (license license:artistic2.0))) (define-public perl6-test-mock (package (name "perl6-test-mock") (version "1.5") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/jnthn/test-mock") ;; The commit where 1.5 was "tagged" (commit "6eddb42f73f40b9ac29c14badb41ce4a04d876f2"))) (file-name (git-file-name name version)) (sha256 (base32 "07yr3qimc8fl29p23562ayj2j9h53madcnf9sgqvgf2kcprh0zd2")))) (build-system rakudo-build-system) (propagated-inputs (list perl6-oo-monitors)) (home-page "https://github.com/jnthn/test-mock") (synopsis "Module for simply generating and checking mock objects") (description "@code{Test::Mock} is a module that works alongside the standard Test module to help you write tests when you want to verify what methods are called on an object, while still having calls to undefined methods die. You get started just as normal with the test file, but also add a use statement for @code{Test::Mock}.") (license license:artistic2.0))) (define-public perl6-uri (package (name "perl6-uri") (version "0.1.5") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/perl6-community-modules/uri") (commit version))) (file-name (git-file-name name version)) (sha256 (base32 "0h318g75jqn2ckw051g35iqyfxz1mps0jyg5z6pd857y3kacbkpl")))) (build-system rakudo-build-system) (arguments '(#:with-zef? #f)) (home-page "https://github.com/perl6-community-modules/uri") (synopsis "URI implementation using Perl 6") (description "A URI implementation using Perl 6 grammars to implement RFC 3986 BNF. Currently only implements parsing. Includes @code{URI::Escape} to (un?)escape characters that aren't otherwise allowed in a URI with % and a hex character numbering.") (license license:artistic2.0))) (define-public perl6-xml-writer ;; Last commit was May 2017 (let ((commit "4d30a9d8e06033ca97387971b653817becd5a759") (revision "1")) (package (name "perl6-xml-writer") (version (git-version "0.0.0" revision commit)) (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/masak/xml-writer") (commit commit))) (file-name (git-file-name name version)) (sha256 (base32 "1kwrf7akp70kyzw1b90khp71a6hpilihwndy2jsjpffcd4hd4m4z")))) (build-system rakudo-build-system) (arguments '(#:with-zef? #f)) (home-page "https://github.com/masak/xml-writer") (synopsis "Perl 6 module to generate XML") (description "@code{XML::Writer} is a module for creating XML in Perl 6.") (license license:artistic2.0)))) (define-public perl6-zef (package (name "perl6-zef") (version "0.6.7") (source (origin (method git-fetch) (uri (git-reference (url "https://github.com/ugexe/zef") (commit (string-append "v" version)))) (file-name (git-file-name name version)) (sha256 (base32 "07n7g1xw2c4g860rs890gx85vyhdq0ysgwbrnzw6q905jph2bkv7")))) (build-system rakudo-build-system) (arguments '(#:with-zef? #f #:phases (modify-phases %standard-phases (replace 'check (lambda _ (setenv "HOME" "/tmp") (invoke "perl6" "-I." "bin/zef" "--debug" "--tap-harness" "test" ".")))))) (home-page "https://github.com/ugexe/zef") (synopsis "Perl6 Module Management") (description "Zef is a Perl 6 package (module) manager. It can be used to download and install Perl 6 modules in your home directory or as a system-wide module.") (license license:artistic2.0)))