Re: PRELIMINARY: [PATCH] guix package: Add '--list-generations'.

2013-09-18 Thread Nikita Karetnikov
 I’ve just found a bug.  On my machine, ‘guix package -p test -l 2d’
 and ‘guix package -p test -l’ should return the same set of
 generations, but the fourth generation is shown twice in the former
 case.

Generations 4 and 5 have the same creation date for some reason:

scheme@(guix ui) dates-generations
$4 = ((1379357250 . 1) (1379364436 . 2) (1379364463 . 3) (1379364530 . 4) 
(1379364530 . 5) (1379419461 . 6))

Since this line

(map (cut assoc-ref dates-generations )

returns the first entry with the given key, the fourth generation is
printed twice.

I’ll try to replace the alist with something else.


pgploKIAGj9qP.pgp
Description: PGP signature


Re: PRELIMINARY: [PATCH] guix package: Add '--list-generations'.

2013-09-18 Thread Ludovic Courtès
Nikita Karetnikov nik...@karetnikov.org skribis:

 Not sure what you mean by “two record sets”.

 “You can have two record sets: one for generations, one for
 packages.” [1]

Ah so I was referring to recutils record sets (I thought you were
talking about SRFI-9 records or something.)  So what’s the question?
:-)

 Why do you suggest to put ‘string-duration’ into (guix ui)?

 Because it’s a user-interface function.

 Done.  However, I think it would be better to write more generic
 procedures if we want to place them in separate modules, so they can be
 reused.  (I can replace the current version with a more generic one if
 you want.)

Well, ‘string-duration’ is just as generic as ‘string-number’.

However I agree ‘string-generation’ could remain internal to
(guix scripts package).  No big deal though.

 I’m attaching the patch.  Please don’t push it yet.  I’ve just found a
 bug.  On my machine, ‘guix package -p test -l 2d’ and ‘guix package -p
 test -l’ should return the same set of generations, but the fourth
 generation is shown twice in the former case.

OK.

 Other issues:

 1. ‘false-if-exception’ in ‘generation-ctime’.

 2. A race condition (marked with XXX).

 3. ‘guix package -l -p test’ returns ‘guix package: error: test:
extraneous argument’.  (However, the same happens with ‘-I’.)

 4. There must be a better way to write the test in
‘tests/guix-package.sh’.

[...]

 --- a/doc/guix.texi
 +++ b/doc/guix.texi
 @@ -606,6 +606,42 @@ library are installed in the profile, then 
 @code{--search-paths} will
  suggest setting these variables to @code{@var{profile}/include} and
  @code{@var{profile}/lib}, respectively.
  
 +@item --list-generations[=@var{regexp}]
 +@itemx -l [@var{regexp}]

s/regexp/pattern/

 +Return a list of generations along with their creation dates.
 +
 +For each installed package, print the following items, separated by
 +tabs: the name of a package, its version string, the part of the package
 +that is installed (@pxref{Packages with Multiple Outputs}), and the
 +location of this package in the store.
 +
 +When @var{regexp} is used, the command returns only matching
 +generations.  Valid patterns include:
 +
 +@itemize
 +@item @emph{Integers and comma-separated integers}.  Both patterns will 
 simply
 +return the corresponding generations.  For instance,
 +@code{--list-generations=1} will return the first one.

I’d use @table rather than @itemize.

Wording: a pattern doesn’t “return” anything, so perhaps:

  These patterns denote generation numbers.

 +If you pass @code{--list-generations=1,8,2}, the command will return
 +three generations in the specified order.  Neither spaces nor trailing
 +commas are allowed.

s/If you pass/Passing/
s/will return/specifies/

 @@ -441,6 +502,9 @@ Install, remove, or upgrade PACKAGES in a single 
 transaction.\n))
--roll-backroll back to the previous generation))
(display (_ 
--search-paths display needed environment variable definitions))
 +  (display (_ 
 +  -l  --list-generations[=REGEXP]
 + list generations matching REGEXP))

Should be “-l, --list-generations”, with a comma.
s/REGEXP/PATTERN/

 --- a/tests/guix-package.sh
 +++ b/tests/guix-package.sh
 @@ -81,6 +81,10 @@ then
  name: hello
  test `guix package -s n0t4r341p4ck4g3` = 
  
 +# List generations.
 +test `guix package -p $profile -l | cut -f1 | grep guile | head -n1` 
 \
 +=   guile-bootstrap

That’s OK.  You could also grep the string “generation 1” (assuming
we’re running in the C locale, dunno if it’s the case.)

 +(test-equal infinite end range

s/infinite/indefinite/

Looks like this is ready to get in!

Ludo’.



Re: PRELIMINARY: [PATCH] guix package: Add '--list-generations'.

2013-09-18 Thread Ludovic Courtès
Nikita Karetnikov nik...@karetnikov.org skribis:

 3. ‘guix package -l -p test’ returns ‘guix package: error: test:
extraneous argument’.  (However, the same happens with ‘-I’.)

That’s because -p is interpreted as the optional argument to -l, and so
‘test’ is considered an extra argument.

Ludo’.



PRELIMINARY: [PATCH] guix package: Add '--list-generations'.

2013-09-17 Thread Nikita Karetnikov
 I think it’s reasonable to have a first milestone without recutils
 output.

OK.

 Not sure what you mean by “two record sets”.

“You can have two record sets: one for generations, one for
packages.” [1]

 I see two use cases: one where you just want human-friendly output, for
 when one is glancing at the available generations, and one that is more
 amenable to Unix pipelines for post-processing.  Recutils output is for
 the latter case.

Right.

 I still think that someone may benefit from the recutils format.  So
 let’s allow the ‘recutils’ argument that would list all generations in
 that format [1] and use the following format [2] for everything else:

   generation 1 Dec 16 2013
 guile2.0.7 out,debuggnu/packages/guile.scm
 hello2.8   out  gnu/packages/base.scm

   generation 2 May 7 2013
 guile2.0.9 out  gnu/packages/guile.scm

 Is it OK?

 Yes.

 Should it point to the store instead of (gnu packages …)?

 Yes, I think so.

Done.

 Why do you suggest to put ‘string-duration’ into (guix ui)?

 Because it’s a user-interface function.

Done.  However, I think it would be better to write more generic
procedures if we want to place them in separate modules, so they can be
reused.  (I can replace the current version with a more generic one if
you want.)

 I installed Nix 1.5.3. and ran the command:

 error: setting synchronous mode: unable to open database file

 Problem with permissions on the SQLite database, I guess.

I “fixed” it by deleting the store and reinstalling Guix.

I’m attaching the patch.  Please don’t push it yet.  I’ve just found a
bug.  On my machine, ‘guix package -p test -l 2d’ and ‘guix package -p
test -l’ should return the same set of generations, but the fourth
generation is shown twice in the former case.

Other issues:

1. ‘false-if-exception’ in ‘generation-ctime’.

2. A race condition (marked with XXX).

3. ‘guix package -l -p test’ returns ‘guix package: error: test:
   extraneous argument’.  (However, the same happens with ‘-I’.)

4. There must be a better way to write the test in
   ‘tests/guix-package.sh’.

[1] https://lists.gnu.org/archive/html/guix-devel/2013-08/msg00173.html

From 27e73d3d86ca7abfbc470f3561c059d730314821 Mon Sep 17 00:00:00 2001
From: Nikita Karetnikov nik...@karetnikov.org
Date: Tue, 17 Sep 2013 23:56:10 +
Subject: [PATCH] guix package: Add '--list-generations'.

* guix/scripts/package.scm: Import (srfi srfi-19).
  (generation-ctime, matching-generations): New functions.
  (show-help): Add '--list-generations'.
  (%options): Likewise.
  (guix-package)[process-query]: Add support for '--list-generations'.
* guix/ui.scm: Import (srfi srfi-19) and (ice-9 regex).
  (string-generations, string-duration): New functions.
* tests/guix-package.sh: Test '--list-generations'.
* tests/ui.scm: Import (srfi srfi-19).
  Test 'string-generations' and 'string-duration'.
* doc/guix.texi (Invoking guix-package): Document '--list-generations'.
---
 doc/guix.texi|   36 +
 guix/scripts/package.scm |  100 ++
 guix/ui.scm  |   68 +++
 tests/guix-package.sh|4 ++
 tests/ui.scm |   85 +++
 5 files changed, 293 insertions(+)

diff --git a/doc/guix.texi b/doc/guix.texi
index 5d1b780..ebf80b4 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -606,6 +606,42 @@ library are installed in the profile, then @code{--search-paths} will
 suggest setting these variables to @code{@var{profile}/include} and
 @code{@var{profile}/lib}, respectively.
 
+@item --list-generations[=@var{regexp}]
+@itemx -l [@var{regexp}]
+Return a list of generations along with their creation dates.
+
+For each installed package, print the following items, separated by
+tabs: the name of a package, its version string, the part of the package
+that is installed (@pxref{Packages with Multiple Outputs}), and the
+location of this package in the store.
+
+When @var{regexp} is used, the command returns only matching
+generations.  Valid patterns include:
+
+@itemize
+@item @emph{Integers and comma-separated integers}.  Both patterns will simply
+return the corresponding generations.  For instance,
+@code{--list-generations=1} will return the first one.
+
+If you pass @code{--list-generations=1,8,2}, the command will return
+three generations in the specified order.  Neither spaces nor trailing
+commas are allowed.
+
+@item @emph{Ranges}.  @code{--list-generations=2..9} will print the
+specified generations and everything in between.  Note that the
+start of a range must be lesser than its end.
+
+It is also possible to omit the endpoint.  For example,
+@code{--list-generations=2..}, will output all generations starting from
+the second one.
+
+@item @emph{Durations}.  You can also get the last @emph{N}@tie{}days, weeks,
+or months by passing an integer along with the first letter of the
+duration, e.g.,