guix-commits
[Top][All Lists]
Advanced

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

04/20: squash! "--db-path" -> "--database".


From: guix-commits
Subject: 04/20: squash! "--db-path" -> "--database".
Date: Sun, 4 Jun 2023 17:34:40 -0400 (EDT)

civodul pushed a commit to branch wip-guix-index
in repository guix.

commit ee0eed7d5db38bd49ec05aa1292b9716a2e30a0c
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sun Apr 2 22:31:18 2023 +0200

    squash! "--db-path" -> "--database".
---
 guix/scripts/index.scm | 94 ++++++++++++++++++++++++--------------------------
 tests/guix-index.sh    | 10 +++---
 2 files changed, 51 insertions(+), 53 deletions(-)

diff --git a/guix/scripts/index.scm b/guix/scripts/index.scm
index adf0f31269..731fd418ef 100644
--- a/guix/scripts/index.scm
+++ b/guix/scripts/index.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2022, 2023 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2023 Antoine R. Dumont <antoine.romain.dumont@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -18,16 +19,16 @@
 
 (define-module (guix scripts index)
   #:use-module ((guix i18n) #:select (G_))
-  #:use-module ((guix ui) #:select (show-version-and-exit
-                                    show-bug-report-information
-                                    with-error-handling
-                                    string->number*))
+  #:use-module ((guix ui)
+                #:select (show-version-and-exit
+                          show-bug-report-information
+                          with-error-handling
+                          string->number*
+                          leave))
   #:use-module (guix scripts)
   #:use-module (sqlite3)
   #:use-module (ice-9 match)
   #:use-module (ice-9 format)
-  #:use-module (ice-9 getopt-long)
-  #:use-module (guix describe)
   #:use-module (guix store)
   #:use-module (guix monads)
   #:autoload   (guix combinators) (fold2)
@@ -40,11 +41,11 @@
                                           call-with-progress-reporter))
   #:use-module (guix sets)
   #:use-module ((guix utils) #:select (cache-directory))
-  #:autoload   (guix build utils) (find-files)
+  #:autoload   (guix build utils) (find-files mkdir-p)
   #:autoload   (gnu packages) (fold-packages)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-9)
-  #:use-module (srfi srfi-37)  ;; option
+  #:use-module (srfi srfi-37) ;; option
   #:use-module (srfi srfi-71)
   #:export     (guix-index))
 
@@ -297,9 +298,9 @@ VALUES (:name, :basename, :directory);"
                 (list (manifest-entry-output entry))
                 (list (manifest-entry-item entry)))) ;FIXME: outputs?
 
-(define (index-packages-from-manifests-with-db db-pathname)
-  "Index packages entries into DB-PATHNAME from the system manifests."
-  (call-with-database db-pathname
+(define (index-packages-from-manifests-with-db file)
+  "Index packages entries into FILE from the system manifests."
+  (call-with-database file
     (lambda (db)
       (let ((entries (profiles->manifest-entries (all-profiles))))
         (insert-packages-with-progress db entries insert-manifest-entry)))))
@@ -338,14 +339,13 @@ ON f.basename = :file
                '() lookup-stmt))
 
 
-
 ;;;
-;;; CLI
+;;; Entry point.
 ;;;
 
-(define (index-packages-from-store-with-db db-pathname)
-  "Index local store packages using db at location DB-PATHNAME."
-  (call-with-database db-pathname
+(define (index-packages-from-store-with-db file)
+  "Index local store packages using db at location FILE."
+  (call-with-database file
     (lambda (db)
       (with-store store
         (parameterize ((%graft? #f))
@@ -361,17 +361,16 @@ ON f.basename = :file
             (insert-packages-with-progress
              db packages insert-package-from-store)))))))
 
-(define (matching-packages-with-db db-pathname file)
-  "Compute list of packages referencing FILE using db at DB-PATHNAME."
-  (call-with-database db-pathname
+(define (matching-packages-with-db db-file file)
+  "Compute list of packages referencing FILE using the database at DB-FILE."
+  (call-with-database db-file
     (lambda (db) (matching-packages db file))))
 
-(define (read-version-from-db db-pathname)
-  (call-with-database db-pathname
-    (lambda (db) (read-version db))))
+(define (read-version-from-db file)
+  (call-with-database file read-version))
 
-(define (migrate-schema-to-version db-pathname)
-  (call-with-database db-pathname
+(define (migrate-schema-to-version file)
+  (call-with-database file
     (lambda (db)
       (catch #t
         (lambda ()
@@ -410,7 +409,8 @@ ON f.basename = :file
                         file)))
             matches))
 
-(define default-db-path
+(define user-database-file
+  ;; Default user database file name.
   (string-append (cache-directory #:ensure? #f)
                  "/index/db.sqlite"))
 
@@ -428,7 +428,7 @@ the build farm node.
 
 With 'search FILE', search for packages installing FILE.\n
 Note: Internal cache is located at ~/.cache/guix/index/db.sqlite by default.
-See --db-path for customization.\n"))
+See --database for customization.\n"))
   (newline)
   (display (G_ "The valid values for OPTIONS are:"))
   (newline)
@@ -437,7 +437,7 @@ See --db-path for customization.\n"))
   (display (G_ "
   -V, --version       Display version information and exit"))
   (display (G_ "
-  --db-path=DIR       Change default location of the cache db"))
+  --database=DIR       Change default location of the cache db"))
   (newline)
   (display (G_ "
   --method=METH       Change default indexation method. By default it uses the
@@ -462,23 +462,23 @@ See --db-path for customization.\n"))
            (lambda (opt name arg result)
              (catch 'sqlite-error
                (lambda ()
-                 (let ((db-path (assoc-ref result 'db-path)))
+                 (let ((database (assoc-ref result 'database)))
                    (simple-format
                     #t
                     "Extension local cache database:\n- path: ~a\n- version: 
~a\n\n"
-                    db-path (read-version-from-db db-path))))
+                    database (read-version-from-db database))))
                (lambda (key . arg) 'no-db-yet-so-nothing-to-display))
              (show-version-and-exit "guix index")))
    ;; index data out of the method (store or package)
-   (option '(#\d "db-path") #f #t
+   (option '(#\d "database") #f #t
            (lambda (opt name arg result)
              (when debug
-               (format #t "%options: --db-path: opt ~a\n" opt)
-               (format #t "%options: --db-path: name ~a\n" name)
-               (format #t "%options: --db-path: arg ~a\n" arg)
-               (format #t "%options: --db-path: result ~a\n" result))
-             (alist-cons 'db-path arg
-                         (alist-delete 'db-path result))))
+               (format #t "%options: --database: opt ~a\n" opt)
+               (format #t "%options: --database: name ~a\n" name)
+               (format #t "%options: --database: arg ~a\n" arg)
+               (format #t "%options: --database: result ~a\n" result))
+             (alist-cons 'database arg
+                         (alist-delete 'database result))))
 
    ;; index data out of the method (store or package)
    (option '(#\m "method") #f #t
@@ -497,7 +497,7 @@ See --db-path for customization.\n"))
  (fast) or store (slow)~%")))))))
 
 (define %default-options
-  `((db-path . ,default-db-path)
+  `((database . ,user-database-file)
     (with-method . "manifests")))
 
 (define-command (guix-index . args)
@@ -563,33 +563,31 @@ See --db-path for customization.\n"))
                                             parse-sub-command))
            (args        (option-arguments opts))
            (action      (assoc-ref args 'action))
-           (db-path     (assoc-ref args 'db-path))
+           (database    (assoc-ref args 'database))
            (with-method (assoc-ref args 'with-method)))
       (when debug
         (format #t "main: opts: ~a\n" opts)
         (format #t "main: args: ~a\n" args)
         (format #t "main: action: ~a\n" action)
-        (format #t "main: db-path: ~a\n" db-path)
+        (format #t "main: database: ~a\n" database)
         (format #t "main: with-method: ~a\n" with-method))
 
       (match action
         ('search
-         (unless (file-exists? db-path)
+         (unless (file-exists? database)
            (format (current-error-port)
                    (G_ "guix index: The local cache db does not exist yet.
 You need to index packages first.\nTry 'guix index --help' for more 
information.~%"))
            (exit 1))
          (let* ((file (assoc-ref args 'argument))
-                (matches (matching-packages-with-db db-path file)))
+                (matches (matching-packages-with-db database file)))
            (print-matching-results matches)
            (exit (pair? matches))))
         ('index
-         (let ((db-dirpath (dirname db-path)))
-           (unless (file-exists? db-dirpath)
-             (mkdir db-dirpath)))
+         (mkdir-p (dirname database))
          ;; Migrate/initialize db to schema at version application-version
-         (migrate-schema-to-version db-path)
+         (migrate-schema-to-version database)
          ;; Finally index packages
          (if (string= with-method "manifests")
-             (index-packages-from-manifests-with-db db-path)
-             (index-packages-from-store-with-db db-path)))))))
+             (index-packages-from-manifests-with-db database)
+             (index-packages-from-store-with-db database)))))))
diff --git a/tests/guix-index.sh b/tests/guix-index.sh
index 8e77e53371..104cc11647 100755
--- a/tests/guix-index.sh
+++ b/tests/guix-index.sh
@@ -37,19 +37,19 @@ guix index --version
 # Preparing db locations for both indexation methods.
 mkdir -p "$(dirname "$tmpdb_manifests")" "$(dirname "$tmpdb_store")"
 
-cmd_manifests="guix index --db-path=$tmpdb_manifests --method=manifests"
-cmd_store="guix index --db-path=$tmpdb_store --method=store"
+cmd_manifests="guix index --database=$tmpdb_manifests --method=manifests"
+cmd_store="guix index --database=$tmpdb_store --method=store"
 
 # Lookup without any db should fail.
-! guix index --db-path="$tmpdb_manifests" search guile
-! guix index --db-path="$tmpdb_store" search guile
+! guix index --database="$tmpdb_manifests" search guile
+! guix index --database="$tmpdb_store" search guile
 
 # Initializing db with bare store should work.
 $cmd_manifests
 
 # Lookup without anything in db should yield no results because the indexer
 # didn't stumble upon any profile.
-test -z "$(guix index --db-path="$tmpdb_manifests" search guile)"
+test -z "$(guix index --database="$tmpdb_manifests" search guile)"
 
 # Install a package.
 guix package --bootstrap --install guile-bootstrap \



reply via email to

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