]> khamidou — GitHub mirrors - liszt.git/commitdiff
porting liszt to the new daemon arch...
authorkhamidou <khamidou@gmail.com>
Tue, 9 Feb 2010 12:13:15 +0000 (13:13 +0100)
committerkhamidou <khamidou@gmail.com>
Tue, 9 Feb 2010 12:13:15 +0000 (13:13 +0100)
liszt
liszt-daemon

diff --git a/liszt b/liszt
index 4ef4891b9b66b0ff275fa49e0840efb419fc61ff..35ad795623ffe8bdde5ee8134c639a263a2d107e 100755 (executable)
--- a/liszt
+++ b/liszt
@@ -39,6 +39,13 @@ def bailout(msg):
     print msg
     sys.exit(-1)
 
+def create_spool_file(dict):
+# Create a spool file and save dict inside as a json dict.
+    fd, filename = tempfile.mkstemp(dir=os.path.expanduser('~/.liszt/delayed/'))
+    json.dump(dict, fd)
+    fd.close()
+    
+    
 class CommandParser(object):
     def __init__(self, args):
         self.dispatch = {"create" : self.parse_create,
@@ -59,6 +66,7 @@ class CommandParser(object):
     def parse_create(self, args):
         listname = ""
         entryname = ""
+        spldict = {} # The dictionnary saved in a spool file.
 
         if len(args) == 0:
             bailout("liszt create listname [optional entry name]")
@@ -76,9 +84,17 @@ class CommandParser(object):
             entryname = reduce(addstr, args[1:])
         
         if entryname == "":
-            session.create_list(listname)
+            spldict["request"] = "create-list"
+            spldict["listname"] = listname
+            
         else:
-            session.create_list_entry(listname, entryname)
+            spldict["request"] = "create-entry"
+            spldict["listname"] = listname
+            spldict["content"] = dict()
+            spldict["content"]["title"] = entryname # FIXME : specify the other options.
+
+        create_spool_file(spldict)
+            
 
     def parse_show(self, args):
         listname = ""
@@ -89,18 +105,20 @@ class CommandParser(object):
 
         if len(args) == 0:
             print "List of the created lists :"
-            for list in session.get_lists_list():
+            lists = open(os.path.expanduser('~/.liszt/cache/lists_list'))
+            for list in lists.readlines():
                 print list
 
         if len(args) == 1:
-            entries = session.get_list(args[0])
-
-            for entry in entries["contents"]:
-                print entry["title"] + "\t" + entry["date"]
-
-        elif len(args) == 2:
-            entry = session.get_entry(args[0], args[1])
-            print entry["title"] + "\t" + entry["date"]
+            listfd = open(os.path.expanduser('~/.liszt/cache/lists_list') + args[0])
+            list = json.load(listfd)
+            print list
+#             for entry in entries["contents"]:
+#                 print entry["title"] + "\t" + entry["date"]
+
+#         elif len(args) == 2:
+#             entry = session.get_entry(args[0], args[1])
+#             print entry["title"] + "\t" + entry["date"]
 
     def parse_remove(self, args):
         listname = ""
index 3d69670ddcc24b722d836fe81f0621ae5ce8448b..c500915c5535721252fbe34627e78db1251ff72c 100755 (executable)
@@ -57,6 +57,8 @@ class Daemon:
         do the UNIX double-fork magic, see Stevens' "Advanced 
         Programming in the UNIX Environment" for details (ISBN 0201563177)
         http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
+
+        Note: the process doesn't decouple himself from the parent environment.
         """
         try: 
             pid = os.fork() 
@@ -67,11 +69,6 @@ class Daemon:
             sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror))
             sys.exit(1)
             
-            # decouple from parent environment
-            os.chdir("/") 
-            os.setsid() 
-            os.umask(0) 
-            
             # do second fork
             try: 
                 pid = os.fork()