You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.6 KiB

;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2015 David Thompson <>
;;; Copyright © 2018 Oleg Pykhalov <>
;;; This file is part of GNU Guix.
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; GNU General Public License for more details.
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix. If not, see <>.
(define-module (guix scripts import gem)
#:use-module (guix ui)
#:use-module (guix utils)
#:use-module (guix scripts)
#:use-module (guix import gem)
#:use-module (guix scripts import)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-11)
#:use-module (srfi srfi-37)
#:use-module (srfi srfi-41)
#:use-module (ice-9 match)
#:use-module (ice-9 format)
#:export (guix-import-gem))
;;; Command-line options.
(define %default-options
(define (show-help)
(display (G_ "Usage: guix import gem PACKAGE-NAME
Import and convert the RubyGems package for PACKAGE-NAME.\n"))
(display (G_ "
-h, --help display this help and exit"))
(display (G_ "
-V, --version display version information and exit"))
(display (G_ "
-r, --recursive generate package expressions for all Gem packages\
that are not yet in Guix"))
(define %options
;; Specification of the command-line options.
(cons* (option '(#\h "help") #f #f
(lambda args
(exit 0)))
(option '(#\V "version") #f #f
(lambda args
(show-version-and-exit "guix import pypi")))
(option '(#\r "recursive") #f #f
(lambda (opt name arg result)
(alist-cons 'recursive #t result)))
;;; Entry point.
(define (guix-import-gem . args)
(define (parse-options)
;; Return the alist of option values.
(args-fold* args %options
(lambda (opt name arg result)
(leave (G_ "~A: unrecognized option~%") name))
(lambda (arg result)
(alist-cons 'argument arg result))
(let* ((opts (parse-options))
(args (filter-map (match-lambda
(('argument . value)
(_ #f))
(reverse opts))))
(match args
(if (assoc-ref opts 'recursive)
(map (match-lambda
((and ('package ('name name) . rest) pkg)
`(define-public ,(string->symbol name)
(_ #f))
(gem-recursive-import package-name 'rubygems))))
(let ((sexp (gem->guix-package package-name)))
(unless sexp
(leave (G_ "failed to download meta-data for package '~a'~%")
(leave (G_ "too few arguments~%")))
((many ...)
(leave (G_ "too many arguments~%"))))))