]> khamidou — GitHub mirrors - liszt.git/commitdiff
fixed an even tastier unicode bug
authorkhamidou <khamidou@gmail.com>
Fri, 12 Feb 2010 08:47:29 +0000 (09:47 +0100)
committerkhamidou <khamidou@gmail.com>
Fri, 12 Feb 2010 08:47:29 +0000 (09:47 +0100)
liszt

diff --git a/liszt b/liszt
index a609d5e7f757f9a40ed0b38bb0d86a6460a7d6fd..ba6df3279acf217deb33880ef5fd96ebca789280 100755 (executable)
--- a/liszt
+++ b/liszt
@@ -10,7 +10,6 @@ import urllib, urllib2, cookielib
 from urllib import quote
 from urllib2 import HTTPError, URLError
 import subprocess
-from subprocess import Popen
 import fnmatch
 import tempfile
 import datetime
@@ -22,13 +21,15 @@ try:
 except ImportError:
     import simplejson as json                                                                                                                         
 
+# unicode magic.
 sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
 
 def help():
-    print "liszt c|create listname ?entryname? "
-    print "liszt r[remove|d|delete listname ?entryindex?"
-    print "liszt s listname ?entryindex?"
+    print "liszt c|create listname [optional entry text]"
+    print "liszt r[remove|delete listname [optional entry index]"
+    print "liszt s|show listname [optional entry index]"
     print "liszt chk|check listname index"
+    print "liszt a|add listname"
     print "liszt u|update listname"
     
 
@@ -63,7 +64,7 @@ class CachedList(object):
 
     def save(self):
         fd = open(os.path.expanduser('~/.liszt/cached/') + self.listname, 'w+')
-        json.dump(self.cached_list, fd, ensure_ascii=False)
+        json.dump(self.cached_list, fd, encoding="utf8")
     
     def fget(self):
         return self.cached_list
@@ -257,8 +258,10 @@ class CommandParser(object):
         fd, filename = tempfile.mkstemp()
 
         editor = os.getenv("EDITOR")
-        os.system(editor + " " + filename)
-        os.close(fd)
+        if editor == None:
+            editor = "vi"  # Not my editor of choice but it should work everywhere.
+        
+        os.system(("%s %s" % (editor, filename)))
         
         # Now, reopen the fd, as a python file handle.
         fd = open(filename)
@@ -268,7 +271,7 @@ class CommandParser(object):
             # fields = lines[i].split("\t")  FIXME: add support for different fields on a line.
             
             if line != '':
-                title = unicode(line.strip())
+                title = unicode(line.strip(), encoding="utf8")
                 dict = {"request" : "create-entry", "listname" : listname, "content" : {"title" : title}}
                 create_spool_file(dict)
                 cached_list = CachedList(listname)