From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: [PATCH] guix package: Add '--switch-generation' option. Date: Tue, 07 Oct 2014 18:00:07 +0200 Message-ID: <87h9zfc1ko.fsf@gnu.org> References: <87k3719v7p.fsf@gmail.com> <87fvho9fqm.fsf@gmail.com> <87a97taixl.fsf@gmail.com> <87sil2rbly.fsf@gnu.org> <87tx5idn7f.fsf_-_@gmail.com> <87egwlkcy1.fsf@gnu.org> <87ppg5el2i.fsf@gmail.com> <87d2c5h4if.fsf@gnu.org> <87lhqsev1d.fsf@gmail.com> <877g2c74xh.fsf@gnu.org> <87ha1gds3w.fsf@gmail.com> <8761hsmxkl.fsf@gnu.org> <87zjf4d1mh.fsf@gmail.com> <87mwb0b3fq.fsf@gnu.org> <87ha17ctyv.fsf_-_@gmail.com> <87ppfs6gxk.fsf@gnu.org> <87wq8fk979.fsf_-_@gmail.com> <87eguninyx.fsf@gnu.org> <8738b1jndu.fsf_-_@gmail.com> <87ppe5vw1b.fsf@gnu.org> <87y4ssi4ak.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34081) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbXBM-0005UK-SD for guix-devel@gnu.org; Tue, 07 Oct 2014 12:00:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XbXBD-0005Lo-Jo for guix-devel@gnu.org; Tue, 07 Oct 2014 12:00:12 -0400 Received: from hera.aquilenet.fr ([2a01:474::1]:50155) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XbXBD-0005J1-35 for guix-devel@gnu.org; Tue, 07 Oct 2014 12:00:03 -0400 In-Reply-To: <87y4ssi4ak.fsf@gmail.com> (Alex Kost's message of "Tue, 07 Oct 2014 14:04:51 +0400") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: Alex Kost Cc: guix-devel@gnu.org Alex Kost skribis: > Thanks, I've added a couple of tests. The new patches are attached. Thanks for the quick reply. > Further improvements (documentation may be unsatisfactory)? > From 9493421a4e094be6686ff6f28749946d491f81cd Mon Sep 17 00:00:00 2001 > From: Alex Kost > Date: Tue, 7 Oct 2014 11:50:44 +0400 > Subject: [PATCH 1/2] profiles: Add procedures for switching generations. > > * guix/scripts/package.scm (switch-to-previous-generation): Move to... > * guix/profiles.scm: ... here. Use 'switch-to-generation'. > (relative-generation): New procedure. > (previous-generation-number): Use it. > (switch-to-generation): New procedure. [...] > +(define* (relative-generation profile shift #:optional > + (current (generation-number profile))) > + "Return PROFILE's generation shifted from the CURRENT generation by SH= IFT. > +SHIFT is a positive or negative number. > +Return #f if there is no such generation." [...] > +(define (switch-to-generation profile number) > + "Atomically switch PROFILE to the generation NUMBER." > + (let ((current (generation-number profile)) > + (file (generation-file-name profile number))) > + (cond ((not (file-exists? profile)) > + (format (current-error-port) > + (_ "profile '~a' does not exist~%") > + profile)) > + ((not (file-exists? file)) > + (format (current-error-port) > + (_ "generation ~a does not exist~%") > + number)) > + (else > + (format #t (_ "switching from generation ~a to ~a~%") > + current number) > + (switch-symlinks profile file))))) Could this procedure raise an exception instead of writing messages? The reason is that I=E2=80=99d like UI code to remain in (guix scripts pack= age), in the Emacs code, and in guix-web, with (guix profiles) remaining generic. It=E2=80=99d be enough for me to just call =E2=80=98switch-symlinks=E2=80= =99 and let it throw =E2=80=98system-error=E2=80=99 if something=E2=80=99s wrong. The exception= will be caught, the user will see a =E2=80=9CNo such file=E2=80=9D error, and =E2=80=98guix pac= kage=E2=80=99 with exit with non-zero (this is done by =E2=80=98call-with-error-handling=E2=80=99.) It=E2=80=99s less informative than what you did, though. The other option = would be to define specific error condition types and throw them from here. WDYT? My apologies for being sloppy and not catching it earlier! > From 0d89e5466741d8f80a1ac27502cb6cd600afb796 Mon Sep 17 00:00:00 2001 > From: Alex Kost > Date: Tue, 7 Oct 2014 12:05:06 +0400 > Subject: [PATCH 2/2] guix package: Add '--switch-generation' option. > > * guix/scripts/package.scm: Add '--switch-generation' option. > (guix-package): Adjust accordingly. > * tests/guix-package.sh: Test it. > * doc/guix.texi (Invoking guix package): Document it. [...] > + (('switch-generation . pattern) > + (let* ((number (string->number pattern)) > + (number (and number > + (case (string-ref pattern 0) > + ((#\+ #\-) > + (relative-generation profile numbe= r)) > + (else number))))) > + (if number > + (switch-to-generation profile number) > + (format (current-error-port) > + "Cannot switch to generation '~a'~%" patter= n))) Use =E2=80=98leave=E2=80=99 instead of =E2=80=98format=E2=80=99 here, with = lower-case =E2=80=9Ccannot=E2=80=9D. The rest is perfect. Thanks for your patience, Ludo=E2=80=99.