Created authors command
authorDmitriy Morozov <morozov@cs.duke.edu>
Sat, 12 Jul 2008 12:00:53 -0400
changeset 10 002b2375f2c1
parent 9 f7462be0b274
child 11 ebb3a597f1d5
Created authors command
.issues/8b7421be0f725ccb/new/1214837703.M728267P2422Q1.metatron
.issues/8b7421be0f725ccb/new/1215878440.M724972P14225Q2.metatron
alexandria.py
--- a/.issues/8b7421be0f725ccb/new/1214837703.M728267P2422Q1.metatron	Mon Jun 30 10:55:27 2008 -0400
+++ b/.issues/8b7421be0f725ccb/new/1214837703.M728267P2422Q1.metatron	Sat Jul 12 12:00:53 2008 -0400
@@ -1,6 +1,6 @@
 From: Dmitriy Morozov <morozov@cs.duke.edu>
 Date: Mon, 30 Jun 2008 10:53:51
-State: new
+State: fixed
 Subject: Merge alias and ralias into authors command
 Message-Id: <8b7421be0f725ccb-0-artemis@metatron>
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.issues/8b7421be0f725ccb/new/1215878440.M724972P14225Q2.metatron	Sat Jul 12 12:00:53 2008 -0400
@@ -0,0 +1,8 @@
+From: Dmitriy Morozov <morozov@cs.duke.edu>
+Date: Sat, 12 Jul 2008 12:00:40
+Subject: properties changes (state)
+Message-Id: <8b7421be0f725ccb-cf96a48d2aa866db-artemis@metatron>
+References: <8b7421be0f725ccb-0-artemis@metatron>
+In-Reply-To: <8b7421be0f725ccb-0-artemis@metatron>
+
+state=fixed
--- a/alexandria.py	Mon Jun 30 10:55:27 2008 -0400
+++ b/alexandria.py	Sat Jul 12 12:00:53 2008 -0400
@@ -113,15 +113,25 @@
         _show_paper(p)
         print
 
-def alias(args, options):
-    """add or list author nicknames"""
-    if len(args) > 1:
-        a =  Author.get_by_or_init(name = unicode(args[1]))
-        an = AuthorNickname.get_by_or_init(name = unicode(args[0]))
-        an.author = a
-        session.flush()
+def authors(args, options):
+    """List authors, add, and remove aliases
+  ax authors                 - list authors
+  ax authors NAME ALIAS      - add ALIAS to AUTHOR's aliases
+  ax authors ~ALIAS          - remove ALIAS"""
+    
+    if len(args) > 0:
+        if args[0][0] == '~':
+            an = AuthorNickname.get_by(name = unicode(args[0][1:]))
+            if an:
+                an.delete()
+                session.flush()
+        else:
+            a =  Author.get_by_or_init(name = unicode(args[0]))
+            an = AuthorNickname.get_by_or_init(name = unicode(args[1]))
+            an.author = a
+            session.flush()
 
-    _show_nicknames()
+    _show_authors()
 
 def labels(args, options):
     """rename and/or list labels"""
@@ -145,18 +155,6 @@
         print '  (%d) %s' % (len(t.papers), t.name)
     session.flush()
 
-def ralias(args, options):
-    """remove alias"""
-    if len(args) == 0:
-        print _colorize_string('error', 'Need alias to remove as an argument.')
-
-    an = AuthorNickname.get_by(name = unicode(args[0]))
-    if an:
-        an.delete()
-        session.flush()
-
-    _show_nicknames()
-
 def info(args, options):
     """Show information about a path"""
 
@@ -207,11 +205,11 @@
             else:
                 a.papers.append(p)
 
-def _show_nicknames():
-    print "Nicknames:"
+def _show_authors():
+    print "Authors:"
     for a in Author.query.all():
         if len(a.nicknames) > 0:
-            print '  ' + a.name + ':',
+            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)
@@ -256,7 +254,7 @@
         return None
 
 
-commands = [add, list, alias, update, view, remove, labels, ralias, info]
+commands = [add, list, authors, update, view, remove, labels, info]
 
 
 if __name__ == "__main__":