summaryrefslogtreecommitdiff
path: root/guix/scripts/import.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-09-27 10:16:23 -0400
committerDavid Thompson <dthompson2@worcester.edu>2014-09-29 19:30:28 -0400
commit1b3e968512ebbccf02d00c52f7e089156946f445 (patch)
treec45d203439ab9a74d01f2c76850cafb847a755e2 /guix/scripts/import.scm
parent2efb3ddaa434b86a841dffbba89e21d2d9208526 (diff)
downloadgnu-guix-1b3e968512ebbccf02d00c52f7e089156946f445.tar
gnu-guix-1b3e968512ebbccf02d00c52f7e089156946f445.tar.gz
import: Add PyPI importer.
* guix/snix.scm: Delete. * guix/import/snix.scm: New file. * guix/import/pypi.scm: New file. * guix/import/utils.scm: New file. * guix/scripts/import/nix.scm: New file. * guix/scripts/import/pypi.scm: New file. * tests/pypi.scm: New file. * tests/snix.scm: Import (guix import snix) module. * guix/scripts/import.scm (%default-options, %options): Delete. (%standard-import-options, importers): New variables. (show-help): List importers. (guix-import): Factor out Nix-specific logic. Delegate to correct importer based upon first argument. * configure.ac (HAVE_GUILE_JSON): New conditional. * Makefile.am (MODULES): Add new files and remove 'guix/snix.scm'. (SCM_TESTS): Add 'tests/pypi.scm' if guile-json is installed.
Diffstat (limited to 'guix/scripts/import.scm')
-rw-r--r--guix/scripts/import.scm85
1 files changed, 39 insertions, 46 deletions
diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm
index 6f75017d6e..e9576bad8c 100644
--- a/guix/scripts/import.scm
+++ b/guix/scripts/import.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2014 David Thompson <davet@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -18,15 +19,16 @@
(define-module (guix scripts import)
#:use-module (guix ui)
- #:use-module (guix snix)
#:use-module (guix utils)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-11)
#:use-module (srfi srfi-26)
#:use-module (srfi srfi-37)
+ #:use-module (ice-9 format)
#:use-module (ice-9 match)
#:use-module (ice-9 pretty-print)
- #:export (guix-import))
+ #:export (%standard-import-options
+ guix-import))
;;;
@@ -61,15 +63,30 @@ rather than \\n."
;;;
-;;; Command-line options.
+;;; Command line options.
;;;
-(define %default-options
- '())
+(define %standard-import-options '())
+
+
+;;;
+;;; Entry point.
+;;;
+
+(define importers '("nix" "pypi"))
+
+(define (resolve-importer name)
+ (let ((module (resolve-interface
+ `(guix scripts import ,(string->symbol name))))
+ (proc (string->symbol (string-append "guix-import-" name))))
+ (module-ref module proc)))
(define (show-help)
- (display (_ "Usage: guix import NIXPKGS ATTRIBUTE
-Import and convert the Nix expression ATTRIBUTE of NIXPKGS.\n"))
+ (display (_ "Usage: guix import IMPORTER ARGS ...
+Run IMPORTER with ARGS.\n"))
+ (newline)
+ (display (_ "IMPORTER must be one of the importers listed below:\n"))
+ (format #t "~{ ~a~%~}" importers)
(display (_ "
-h, --help display this help and exit"))
(display (_ "
@@ -77,43 +94,19 @@ Import and convert the Nix expression ATTRIBUTE of NIXPKGS.\n"))
(newline)
(show-bug-report-information))
-(define %options
- ;; Specification of the command-line options.
- (list (option '(#\h "help") #f #f
- (lambda args
- (show-help)
- (exit 0)))
- (option '(#\V "version") #f #f
- (lambda args
- (show-version-and-exit "guix import")))))
-
-
-;;;
-;;; Entry point.
-;;;
-
(define (guix-import . args)
- (define (parse-options)
- ;; Return the alist of option values.
- (args-fold* args %options
- (lambda (opt name arg result)
- (leave (_ "~A: unrecognized option~%") name))
- (lambda (arg result)
- (alist-cons 'argument arg result))
- %default-options))
-
- (let* ((opts (parse-options))
- (args (filter-map (match-lambda
- (('argument . value)
- value)
- (_ #f))
- (reverse opts))))
- (match args
- ((nixpkgs attribute)
- (let-values (((expr loc)
- (nixpkgs->guix-package nixpkgs attribute)))
- (format #t ";; converted from ~a:~a~%~%"
- (location-file loc) (location-line loc))
- (pretty-print expr (newline-rewriting-port (current-output-port)))))
- (_
- (leave (_ "wrong number of arguments~%"))))))
+ (match args
+ (()
+ (format (current-error-port)
+ (_ "guix import: missing importer name~%")))
+ ((or ("-h") ("--help"))
+ (show-help)
+ (exit 0))
+ (("--version")
+ (show-version-and-exit "guix import"))
+ ((importer args ...)
+ (if (member importer importers)
+ (let ((expr (apply (resolve-importer importer) args)))
+ (pretty-print expr (newline-rewriting-port (current-output-port))))
+ (format (current-error-port)
+ (_ "guix import: invalid importer~%"))))))