guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/03: services: dicod: Allow the configuration of "handlers".


From: Ludovic Courtès
Subject: 01/03: services: dicod: Allow the configuration of "handlers".
Date: Fri, 31 Mar 2017 18:46:22 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit 9af7ecd9591b4eff41389291bbc586dcf09e2665
Author: Huang Ying <address@hidden>
Date:   Thu Mar 30 19:13:34 2017 +0800

    services: dicod: Allow the configuration of "handlers".
    
    * gnu/services/dict.scm (<dicod-configuration>)[handlers]: New field.
    (<dicod-handler>): New record type.
    (<dicod-database>): Add fields.
    (dicod-configuration-file): Support convert handlers and enhanced databases.
    configuration to config file.
    * doc/guix.texi (Miscellaneous Services): Update accordingly.
    
    Signed-off-by: Ludovic Courtès <address@hidden>
---
 doc/guix.texi         | 52 ++++++++++++++++++++++++++++++++++++++++++++-----
 gnu/services/dict.scm | 54 ++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 92 insertions(+), 14 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 57595b9..ae5f04b 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -14370,25 +14370,49 @@ This is the list of IP addresses and ports and 
possibly socket file
 names to listen to (@pxref{Server Settings, @code{listen} directive,,
 dico, GNU Dico Manual}).
 
address@hidden @code{handlers} (default: @var{'()})
+List of @code{<dicod-handler>} objects denoting handlers (module instances).
+
 @item @code{databases} (default: @var{(list %dicod-database:gcide)})
 List of @code{<dicod-database>} objects denoting dictionaries to be served.
 @end table
 @end deftp
 
address@hidden {Data Type} dicod-database
-Data type representing a dictionary database.
address@hidden {Data Type} dicod-handler
+Data type representing a dictionary handler (module instance).
 
 @table @asis
 @item @code{name}
-Name of the database, will be used in DICT commands.
+Name of the handler (module instance).
 
address@hidden @code{module}
-Name of the dicod module used by this database
address@hidden @code{module} (default: @var{#f})
+Name of the dicod module of the handler (instance).  If it is @code{#f},
+the module has the same name as the handler.
 (@pxref{Modules,,, dico, GNU Dico Manual}).
 
 @item @code{options}
 List of strings or gexps representing the arguments for the module handler
address@hidden table
address@hidden deftp
+
address@hidden {Data Type} dicod-database
+Data type representing a dictionary database.
+
address@hidden @asis
address@hidden @code{name}
+Name of the database, will be used in DICT commands.
+
address@hidden @code{handler}
+Name of the dicod handler (module instance) used by this database
 (@pxref{Handlers,,, dico, GNU Dico Manual}).
+
address@hidden @code{complex?} (default: @var{#f})
+Whether the database configuration complex.  The complex configuration
+will need a corresponding @code{<dicod-handler>} object, otherwise not.
+
address@hidden @code{options}
+List of strings or gexps representing the arguments for the database
+(@pxref{Databases,,, dico, GNU Dico Manual}).
 @end table
 @end deftp
 
@@ -14397,6 +14421,24 @@ A @code{<dicod-database>} object serving the GNU 
Collaborative International
 Dictonary of English using the @code{gcide} package.
 @end defvr
 
+The following is an example @code{dicod-service} configuration.
+
address@hidden
+(dicod-service #:config
+  (dicod-configuration
+   (handlers (list (dicod-handler
+                    (name "wordnet")
+                    (module "dictorg")
+                    (options
+                     (list #~(string-append "dbdir=" #$wordnet))))))
+   (databases (list (dicod-database
+                     (name "wordnet")
+                     (complex? #t)
+                     (handler "wordnet")
+                     (options '("database=wn")))
+                    %dicod-database:gcide))))
address@hidden example
+
 @subsubsection Version Control
 
 The @code{(gnu services version-control)} module provides the following 
services:
diff --git a/gnu/services/dict.scm b/gnu/services/dict.scm
index 3030670..64de111 100644
--- a/gnu/services/dict.scm
+++ b/gnu/services/dict.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2016 Sou Bunnbu <address@hidden>
-;;; Copyright © 2016 Ludovic Courtès <address@hidden>
+;;; Copyright © 2016, 2017 Ludovic Courtès <address@hidden>
+;;; Copyright © 2017 Huang Ying <address@hidden>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -32,6 +33,7 @@
   #:export (dicod-service
             dicod-service-type
             dicod-configuration
+            dicod-handler
             dicod-database
             %dicod-database:gcide))
 
@@ -46,21 +48,30 @@
   (dico        dicod-configuration-dico       (default dico))
   (interfaces  dicod-configuration-interfaces     ;list of strings
                (default '("localhost")))
-  (databases   dicod-configuration-databases
-               ;; list of <dicod-database>
+  (handlers    dicod-configuration-handlers       ;list of <dicod-handler>
+               (default '()))
+  (databases   dicod-configuration-databases      ;list of <dicod-database>
                (default (list %dicod-database:gcide))))
 
+(define-record-type* <dicod-handler>
+  dicod-handler make-dicod-handler
+  dicod-handler?
+  (name        dicod-handler-name)
+  (module      dicod-handler-module          (default #f))
+  (options     dicod-handler-options         (default '())))
+
 (define-record-type* <dicod-database>
   dicod-database make-dicod-database
   dicod-database?
   (name        dicod-database-name)
-  (module      dicod-database-module)
+  (handler     dicod-database-handler)
+  (complex?    dicod-database-complex?       (default #f))
   (options     dicod-database-options        (default '())))
 
 (define %dicod-database:gcide
   (dicod-database
    (name "gcide")
-   (module "gcide")
+   (handler "gcide")
    (options (list #~(string-append "dbdir=" #$gcide "/share/gcide")
                   "idxdir=/var/run/dicod"))))
 
@@ -76,22 +87,47 @@
          (shell (file-append shadow "/sbin/nologin")))))
 
 (define (dicod-configuration-file config)
+  (define handler->text
+    (match-lambda
+      (($ <dicod-handler> name #f '())
+       `("
+load-module " ,name ";"))
+      (($ <dicod-handler> name #f options)
+       (handler->text (dicod-handler
+                       (name name)
+                       (module name)
+                       (options options))))
+      (($ <dicod-handler> name module options)
+       `("
+load-module " ,name " {
+   command \"" ,module (string-join (list ,@options) " " 'prefix) "\";
+}\n"))))
+
   (define database->text
     (match-lambda
-      (($ <dicod-database> name module options)
+      (($ <dicod-database> name handler #f options)
+       (append
+        (handler->text (dicod-handler
+                        (name handler)))
+        (database->text (dicod-database
+                         (name name)
+                         (handler handler)
+                         (complex? #t)
+                         (options options)))))
+      (($ <dicod-database> name handler complex? options)
        `("
-load-module " ,module ";
 database {
    name \"" ,name "\";
-   handler \"" ,module
+   handler \"" ,handler
    (string-join (list ,@options) " " 'prefix) "\";
 }\n"))))
 
   (define configuration->text
     (match-lambda
-      (($ <dicod-configuration> dico (interfaces ...) databases)
+      (($ <dicod-configuration> dico (interfaces ...) handlers databases)
        (append `("listen ("
                  ,(string-join interfaces ", ") ");\n")
+               (append-map handler->text handlers)
                (append-map database->text databases)))))
 
   (apply mixed-text-file "dicod.conf" (configuration->text config)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]