From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58683) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1es5aB-0001c4-56 for guix-patches@gnu.org; Sat, 03 Mar 2018 06:44:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1es5a6-00051D-7N for guix-patches@gnu.org; Sat, 03 Mar 2018 06:44:07 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:33979) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1es5a6-000515-2e for guix-patches@gnu.org; Sat, 03 Mar 2018 06:44:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1es5a5-0007ob-RE for guix-patches@gnu.org; Sat, 03 Mar 2018 06:44:01 -0500 Subject: [bug#30657] [PATCH] services: messaging: Prosody config supports file-like objects. Resent-Message-ID: References: <87o9k6csz9.fsf@gnu.org> <20180303013308.12929-1-clement@lassieur.org> From: =?UTF-8?Q?Cl=C3=A9ment?= Lassieur In-reply-to: <20180303013308.12929-1-clement@lassieur.org> Date: Sat, 03 Mar 2018 12:43:28 +0100 Message-ID: <871sh1mljz.fsf@lassieur.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 30657@debbugs.gnu.org With a better use of 'format'... Clément Lassieur writes: > (define (serialize-field field-name val) > - (format #t "~a = ~a;\n" (uglify-field-name field-name) val)) > + #~(string-append > + #$(format #f "~a = " (uglify-field-name field-name)) #$val ";\n")) #~(format #f "~a = ~a;\n" #$(uglify-field-name field-name) #$val)) > (define (serialize-field-list field-name val) > (serialize-field field-name > - (with-output-to-string > - (lambda () > - (format #t "{\n") > - (for-each (lambda (x) > - (format #t "~a;\n" x)) > - val) > - (format #t "}"))))) > + #~(string-append > + "{\n" > + #$@(map (lambda (x) > + #~(string-append #$x ";\n")) > + val) > + "}"))) (ice-9 format) can do miracles ;-) (serialize-field field-name #~(format #f "{\n~@{~a;\n~}}" #$@val))) > (define (enclose-quotes s) > - (format #f "\"~a\"" s)) > + #~(string-append "\"" #$s "\"")) #~(format #f "\"~a\"" #$s)) > @@ -273,9 +285,10 @@ can create such a file with: > (maybe-string 'disabled) > "Password for encrypted private keys.")) > (define (serialize-ssl-configuration field-name val) > - (format #t "ssl = {\n") > - (serialize-configuration val ssl-configuration-fields) > - (format #t "};\n")) > + #~(string-append > + "ssl = {\n" > + #$(serialize-configuration val ssl-configuration-fields) > + "};\n")) #~(format #f "ssl = {\n~a};\n" #$(serialize-configuration val ssl-configuration-fields))) > (define-configuration opaque-prosody-configuration > (prosody > @@ -646,13 +666,10 @@ See also @url{https://prosody.im/doc/modules/mod_muc}." > (default-certs-dir "/etc/prosody/certs") > (data-path (prosody-configuration-data-path config)) > (pidfile-dir (dirname (prosody-configuration-pidfile config))) > - (config-str > - (if (opaque-prosody-configuration? config) > - (opaque-prosody-configuration-prosody.cfg.lua config) > - (with-output-to-string > - (lambda () > - (serialize-prosody-configuration config))))) > - (config-file (plain-file "prosody.cfg.lua" config-str))) > + (config-str (if (opaque-prosody-configuration? config) > + (opaque-prosody-configuration-prosody.cfg.lua config) > + (serialize-prosody-configuration config))) > + (config-file (mixed-text-file "prosody.cfg.lua" config-str))) > #~(begin > (use-modules (guix build utils)) > (define %user (getpw "prosody")) (with-imported-modules '((ice-9 format)) #~(begin (use-modules (ice-9 format)) #$(serialize-prosody-configuration config)))))