gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet-scheme] 284/324: config: Automatically load defaults, system and


From: gnunet
Subject: [gnunet-scheme] 284/324: config: Automatically load defaults, system and user configuration.
Date: Tue, 21 Sep 2021 13:25:24 +0200

This is an automated email from the git hooks/post-receive script.

maxime-devos pushed a commit to branch master
in repository gnunet-scheme.

commit ec2062f0da48c494a6b91cfb8bf31d4edb218ba3
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Mon Sep 13 17:22:37 2021 +0200

    config: Automatically load defaults, system and user configuration.
    
    * gnu/gnunet/config/fs.scm
      (locate-defaults,load-configuration): New procedures.
    * doc/scheme-gnunet.tm
      (Loading configuration files): Document new procedure.
    * gnu/gnunet/config/default.conf: New file.
    * Makefile.am (nobase_dist_guilesite_DATA): Add new file.
---
 Makefile.am                    |  2 +-
 doc/scheme-gnunet.tm           | 13 ++++++++++++-
 gnu/gnunet/config/default.conf | 19 +++++++++++++++++++
 gnu/gnunet/config/fs.scm       | 35 +++++++++++++++++++++++++++++++++--
 4 files changed, 65 insertions(+), 4 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 536c705..15673e2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -76,7 +76,7 @@ modules = \
   gnu/gnunet/netstruct/syntactic.scm
 
 GOBJECTS = $(modules:%.scm=%.go)
-nobase_dist_guilesite_DATA = $(modules)
+nobase_dist_guilesite_DATA = $(modules) gnu/gnunet/config/defaults.conf
 
 E = gnu/gnunet/message/enum-
 nobase_dist_guilesite_DATA += \
diff --git a/doc/scheme-gnunet.tm b/doc/scheme-gnunet.tm
index 0ddaf1b..9415e50 100644
--- a/doc/scheme-gnunet.tm
+++ b/doc/scheme-gnunet.tm
@@ -179,7 +179,18 @@
     expanded.
   </explain>
 
-  <todo|loading configuration files from the disk>
+  To automatically load the defaults, the system configuration and the user
+  configuration, use the thunk <scm|load-configuration>:
+
+  <\explain>
+    <scm|(load-configuration #:getenv=<var|getenv> #:files=<text-dots>)>
+  </explain|Load the defaults, the system configuration and the user
+  configuration and return the resulting configuration object.<space|1em>The
+  list of files to load can be overriden by setting the undocumented
+  <var|files> keyword argument.>
+
+  Applications (whether graphical or textual) are recommended to use
+  <scm|load-configuration> by default, as it largely just works.
 
   <subsection|Value types>
 
diff --git a/gnu/gnunet/config/default.conf b/gnu/gnunet/config/default.conf
new file mode 100644
index 0000000..ea019ef
--- /dev/null
+++ b/gnu/gnunet/config/default.conf
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Copyright (C) 2020, 2021 Maxime Devos
+# SPDX-License-Identifier: FSFAP
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.  This file is offered as-is,
+# without any warranty.
+#
+# For compatibility with C GNUnet, it is important that the default UNIXPATH,
+# GNUNET_RUNTIME_DIR and GNUNET_USER_RUNTIME_DIR is the same.
+
+[nse]
+UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-nse.sock
+
+[PATHS]
+# Directory for UNIX domain sockets of system-wide services.
+GNUNET_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/gnunet-system-runtime/
+# Likewise, for per-user services
+GNUNET_USER_RUNTIME_DIR = 
${TMPDIR:-${TMP:-/tmp}}/gnunet-${USERHOME:-${USER:-user}}-runtime/
diff --git a/gnu/gnunet/config/fs.scm b/gnu/gnunet/config/fs.scm
index dfd10a5..1a073ab 100644
--- a/gnu/gnunet/config/fs.scm
+++ b/gnu/gnunet/config/fs.scm
@@ -34,12 +34,15 @@
 (define-library (gnu gnunet config fs)
   (export locate-system-configuration
          locate-user-configuration
+         load-configuration
          load-configuration/port!
          make-expanded-configuration)
   (import (only (rnrs base)
                begin define and not or cond define-syntax identifier-syntax
                if ... eq? values + lambda quote vector car cdr cons string?
                string-length vector? vector-ref string=? list)
+         (only (rnrs control)
+               when)
          (prefix (rnrs hashtables)
                  rnrs:)
          (only (ice-9 optargs)
@@ -50,13 +53,18 @@
                getenv in-vicinity string-null? define-syntax-rule eof-object?
                substring error syntax-error define-syntax-parameter
                syntax-parameterize syntax-violation identity
-               make-hash-table hash-set! hash-ref hash-for-each)
+               make-hash-table hash-set! hash-ref hash-for-each
+               call-with-input-file for-each file-exists?
+               search-path %load-path)
          (only (gnu gnunet utils hat-let)
                let^)
          (gnu gnunet config db)
          (gnu gnunet config expand)
          (gnu gnunet config parser))
   (begin
+    (define (locate-defaults)
+      (search-path %load-path "gnu/gnunet/config/default.conf"))
+
     (define (locate-system-configuration)
       "/etc/gnunet.conf")
 
@@ -212,6 +220,29 @@ are added to the configuration and every variable is 
expanded."
        hash)
       config)
 
+    ;; XXX no tests
+    (define* (load-configuration #:key (getenv getenv)
+                                (files (list (locate-defaults)
+                                             (locate-system-configuration)
+                                             (locate-user-configuration
+                                              #:getenv getenv))))
+      "Load the user configuration, system configuration and defaults.
+The configuration files to load can be overridden by setting @var{files}
+appropriately."
+      (define configurations
+       (list (locate-system-configuration)
+             (locate-user-configuration)))
+      (define (load! set-value!)
+       (define (load-file! file)
+         (when (and file (file-exists? file))
+           (call-with-input-file file
+             (lambda (p)
+               (load-configuration/port! set-value! p))
+             #:guess-encoding #t
+             #:encoding "UTF-8")))
+       (for-each load-file! configurations))
+      (define c (make-expanded-configuration load! #:getenv getenv))
+      c)
+
     ;; TODO error reporting
-    ;; TODO actually load the configuration, defaults, ...
     ))

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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