From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nikita Karetnikov Subject: [PATCH] Add 'guix hash'. Date: Mon, 01 Apr 2013 09:06:05 +0400 Message-ID: <87li92alhe.fsf@karetnikov.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:60762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMWuE-0002UA-LM for bug-guix@gnu.org; Mon, 01 Apr 2013 01:03:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMWu8-0007J6-Cp for bug-guix@gnu.org; Mon, 01 Apr 2013 01:03:42 -0400 Received: from [2a01:7e00::f03c:91ff:fedf:181] (port=36372 helo=cooksoni.karetnikov.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMWu8-0007Iy-2V for bug-guix@gnu.org; Mon, 01 Apr 2013 01:03:36 -0400 List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org To: bug-guix@gnu.org --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= This patch adds a 'guix hash' command. I'd like it to output non-Base32 too, but I haven't found a way to convert the output of 'sha256', which is a bytevector, to a string. What options would you like to see implemented? Should we capitalize error messages? The current one was copied from 'guix import'. Is it OK to output a backtrace when the specified file doesn't exist? For example: # ./pre-inst-env guix hash foobar Should we only print the error message? --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename=0001-Add-guix-hash.patch Content-Transfer-Encoding: quoted-printable From=208de1cfe973c1c0897a959250dad95048f12833b7 Mon Sep 17 00:00:00 2001 From: Nikita Karetnikov Date: Mon, 1 Apr 2013 04:48:02 +0000 Subject: [PATCH] Add 'guix hash'. * guix/scripts/hash.scm: New file. * Makefile.am (MODULES): Add it. =2D-- Makefile.am | 1 + guix/scripts/hash.scm | 90 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 91 insertions(+), 0 deletions(-) create mode 100644 guix/scripts/hash.scm diff --git a/Makefile.am b/Makefile.am index 41ef503..f2dffd8 100644 =2D-- a/Makefile.am +++ b/Makefile.am @@ -30,6 +30,7 @@ MODULES =3D \ guix/scripts/import.scm \ guix/scripts/package.scm \ guix/scripts/gc.scm \ + guix/scripts/hash.scm \ guix/scripts/pull.scm \ guix/base32.scm \ guix/utils.scm \ diff --git a/guix/scripts/hash.scm b/guix/scripts/hash.scm new file mode 100644 index 0000000..4ed04f2 =2D-- /dev/null +++ b/guix/scripts/hash.scm @@ -0,0 +1,90 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2013 Nikita Karetnikov +;;; +;;; 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 +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; 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 hash) + #:use-module (guix base32) + #:use-module (guix ui) + #:use-module (guix utils) + #:use-module (rnrs io ports) + #:use-module (ice-9 match) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-37) + #:export (guix-hash)) + +(define (file->hash file) + "Return the cryptographic hash of FILE in Base32." + (call-with-input-file file + (compose bytevector->nix-base32-string + sha256 + get-bytevector-all))) + + +;;; +;;; Command-line options. +;;; + +(define %default-options + '()) + +(define (show-help) + (display (_ "Usage: guix hash FILE +Return the cryptographic hash of FILE in Base32.\n")) + (display (_ " + -h, --help display this help and exit")) + (display (_ " + -V, --version display version information and exit")) + (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 hash"))))) + + +;;; +;;; Entry point. +;;; + +(define (guix-hash . 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 + ((file) + (format #t "~a~%" (file->hash file))) + + (_ + (leave (_ "wrong number of arguments~%")))))) =2D-=20 1.7.5.4 --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQIcBAEBAgAGBQJRWRXAAAoJEM+IQzI9IQ38JJkP/jImfrEbvmDG1+ueHVwttZhl aqB8taC+5NkaQVu0lN4y0OdMZoCDjUS/DSNBOgbRy8Zgk0dGgIAuSyx2090++LKX i3dmCUmVNVCto51d+7F43nMg+Q5lx2ngm8bEq5uj5podTK35Vssg4A+Y3G0Zwv4q T1X/BI6larCBaadfd8B/H8ZmiZ+BVHb+rrrq7St2w/H2byyMgVxH4pe9ZbiiuYPt CtGjMCFSSjeEEwzTiqvhABAXGKZvrpNebkIoeYCAX/QQNYdo8spGxIXxqqe9Mfyz gCs63sw5uGFxQlVQq+QoVzzIA1gfbXyRprT5SQqCDEtAX5WZgUHU+0Z/DzbfQyTn Vh5tJystaFW7RtJpjagyoFcPrr3xJ5VmiXv8T5r4dDhES6s+o5CRXjuwOhS0QqTq vyHeI580X5yqZEJKrik4MxeVNr1ao2HH4/azqyan6cFBBZhXbN9XcU4c3hIn11fg Fs2Q7WLpxnnMAnRaEQ5Z4qEipir4i2F4h/KjwjgjvC5UTcJ4h/Eq6kdfnjBR5IoR s4HFG9YAoCQRMmo8tlK3vXFbatMfB3FVhPeip26V2KkP67o567FSNAdgifT4Lcwz 3sUytPq+lVNv5ahOCDokkZxCvQKS9unpGbSr5TSvDJ/2BvYRfLkQxXIMYdcaJcg2 6j9MjXp/H358mMWUZB1Q =QpLj -----END PGP SIGNATURE----- --==-=-=--