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,
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]")
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 = ""
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 = ""
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()
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()