Authors sorted in _show_authors() + show all authors with --all
authorDmitriy Morozov <morozov@cs.duke.edu>
Tue, 15 Jul 2008 08:49:46 -0400
changeset 13 53b93fa00f44
parent 12 71fba4d319b2
child 14 53e32c952ebd
Authors sorted in _show_authors() + show all authors with --all
alexandria.py
--- a/alexandria.py	Mon Jul 14 13:09:22 2008 -0400
+++ b/alexandria.py	Tue Jul 15 08:49:46 2008 -0400
@@ -134,7 +134,7 @@
             an.author = a
             session.flush()
 
-    _show_authors()
+    _show_authors(options)
 
 def labels(args, options):
     """rename and/or list labels"""
@@ -212,18 +212,22 @@
             else:
                 a.papers.append(p)
 
-def _show_authors():
+def _show_authors(options):
     print "Authors:"
-    for a in Author.query.all():
-        if len(a.nicknames) > 0:
+    authors = Author.query.all()
+    _sort_authors(authors, lambda x: x.name)
+    for a in authors:
+        if (len(a.papers) > 0 and options.all) or len(a.nicknames) > 0:
             print '  %s (%d):' % (a.name, len(a.papers)),
-            for an in a.nicknames[:-1]:
-                print an.name + ',',
-            #print '%s: %s' % (a.nicknames[-1], a.name)
-            print a.nicknames[-1]
+            if len(a.nicknames) > 0:
+                for an in a.nicknames[:-1]:
+                    print an.name + ',',
+                #print '%s: %s' % (a.nicknames[-1], a.name)
+                print a.nicknames[-1],
+            print
 
-def _sort_authors(authors):
-    authors.sort(lambda x,y: cmp(x.split()[-1], y.split()[-1]))
+def _sort_authors(authors, name = lambda x: x):
+    authors.sort(lambda x,y: cmp(name(x).split()[-1], name(y).split()[-1]))
 
 def _show_paper(paper):
     print _colorize_string('title', paper.title)
@@ -283,6 +287,7 @@
     parser.add_option('-t', '--title',      dest='title')
     parser.add_option('-l', '--label',      action='append', dest='labels', help='"label" to add a label or "-label" to remove a label')
     parser.add_option('-D', '--database',   dest='database', help='directory with the database')
+    parser.add_option(      '--all',        action='store_true', dest='all', help='show all')
     parser.add_option('-h', '--help',       action='store_true', dest='show_help', help='show help message')
     (options, args) = parser.parse_args()