diff options
author | David Thompson <dthompson2@worcester.edu> | 2015-08-16 21:09:19 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2015-08-27 18:02:35 -0400 |
commit | 140b3048155d8fe4b8598786c014139ac5a91706 (patch) | |
tree | 9e07f54e4ab718976c1d65602b622accfe5e0a7f /guix/import/utils.scm | |
parent | f8da3af08655acf2bb016e3a84bcba9b16e667ff (diff) |
import: pypi: Move generally useful procedures to utils module.
* guix/import/pypi.scm (make-pypi-sexp): Factorize license to symbol
conversion code.
(string->license, snake-case, guix-hash-url): Move from here...
* guix/import/utils.scm: ... to here.
(license->symbol): New procedure.
Diffstat (limited to 'guix/import/utils.scm')
-rw-r--r-- | guix/import/utils.scm | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/guix/import/utils.scm b/guix/import/utils.scm index 969491d28d..0734fa1230 100644 --- a/guix/import/utils.scm +++ b/guix/import/utils.scm @@ -21,6 +21,8 @@ #:use-module (ice-9 regex) #:use-module (srfi srfi-1) #:use-module (guix hash) + #:use-module (guix base32) + #:use-module (guix licenses) #:use-module (guix utils) #:use-module ((guix build download) #:prefix build:) #:export (factorize-uri @@ -29,7 +31,13 @@ flatten assoc-ref* - url-fetch)) + url-fetch + guix-hash-url + + string->license + license->symbol + + snake-case)) (define (factorize-uri uri version) "Factorize URI, a package tarball URI as a string, such that any occurrences @@ -95,3 +103,36 @@ recursively apply the procedure to the sub-list." "Save the contents of URL to FILE-NAME. Return #f on failure." (parameterize ((current-output-port (current-error-port))) (build:url-fetch url file-name))) + +(define (guix-hash-url filename) + "Return the hash of FILENAME in nix-base32 format." + (bytevector->nix-base32-string (file-sha256 filename))) + +(define (string->license str) + "Convert the string STR into a license object." + (match str + ("GNU LGPL" lgpl2.0) + ("GPL" gpl3) + ((or "BSD" "BSD License") bsd-3) + ((or "MIT" "MIT license" "Expat license") expat) + ("Public domain" public-domain) + ((or "Apache License, Version 2.0" "Apache 2.0") asl2.0) + (_ #f))) + +(define (license->symbol license) + "Convert license to a symbol representing the variable the object is bound +to in the (guix licenses) module, or #f if there is no such known license." + ;; TODO: Traverse list public variables in (guix licenses) instead so we + ;; don't have to maintain a list manualy. + (assoc-ref `((,lgpl2.0 . lgpl2.0) + (,gpl3 . gpl3) + (,bsd-3 . bsd-3) + (,expat . expat) + (,public-domain . public-domain) + (,asl2.0 . asl2.0)) + license)) + +(define (snake-case str) + "Return a downcased version of the string STR where underscores are replaced +with dashes." + (string-join (string-split (string-downcase str) #\_) "-")) |