Label renaming + listing by patterns on labels and authors
authorDmitriy Morozov <morozov@cs.duke.edu>
Wed, 21 May 2008 10:45:31 -0400
changeset 5 35552b6cdc51
parent 4 2a543aeac83d
child 6 3f2c0ca0812a
Label renaming + listing by patterns on labels and authors
alexandria.py
--- a/alexandria.py	Wed May 21 08:44:59 2008 -0400
+++ b/alexandria.py	Wed May 21 10:45:31 2008 -0400
@@ -87,16 +87,17 @@
         labels = label_with_commas.split(',')
         for label in labels:
             label = unicode(label.strip())
-            papers = papers.filter(Paper.tags.any(Tag.name.startswith(label)))
+            label = label.replace('*', '%')             # allow for glob style-pattern
+            papers = papers.filter(Paper.tags.any(Tag.name.like(label)))
 
     for author_with_commas in (options.authors or []):
         authors = author_with_commas.split(',')
         for author in authors:
             author = unicode(author.strip())
             an = AuthorNickname.get_by(name = author)
-            if an: a = an.author
-            else:  a = Author.get_by_or_init(name = author)
-            papers = papers.filter(Paper.authors.any(name = unicode(a))) 
+            if an: a = an.author.name
+            else:  a = author.replace('*', '%')
+            papers = papers.filter(Paper.authors.any(Author.name.like(a)))
 
     print
     for p in papers.all():
@@ -120,6 +121,12 @@
             print a.nicknames[-1]
 
 def labels(args, options):
+    if len(args) >= 2:
+        t = Tag.get_by(name = unicode(args[0]))
+        if t:
+            t.name = unicode(args[1])
+    session.flush()
+
     print "Labels:"
     for t in Tag.query.order_by(asc(Tag.name)).all():
         if len(t.papers) == 0:                  # clean the database
@@ -180,7 +187,7 @@
             (update,    'update paper by hash'),
             (view,      'view paper by hash'),
             (remove,    'remove paper by hash'),
-            (labels,    'list labels')
+            (labels,    'rename and/or list labels')
            ]