~nmu-sscheel/gtg/rework-task-editor

« back to all changes in this revision

Viewing changes to gtg_new_task

  • Committer: Bertrand Rousseau
  • Date: 2012-05-09 22:33:25 UTC
  • mfrom: (1178 trunk)
  • mto: This revision was merged to the branch mainline in revision 1179.
  • Revision ID: bertrand.rousseau@gmail.com-20120509223325-a53d8nwo0x9g93bc
Merge nimit branch and trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
# -*- coding:utf-8 -*-
3
 
 
4
3
# -----------------------------------------------------------------------------
5
4
# Getting Things Gnome! - A personal organizer for the GNOME desktop
6
 
# Copyright (c) 2008,2009 Lionel Dricot & Bertrand Rousseau
 
5
# Copyright (c) 2008-2012 Lionel Dricot & Bertrand Rousseau
7
6
#
8
7
# This program is free software: you can redistribute it and/or modify it under
9
8
# the terms of the GNU General Public License as published by the Free Software
19
18
# this program.  If not, see <http://www.gnu.org/licenses/>.
20
19
# -----------------------------------------------------------------------------
21
20
 
22
 
"""
23
 
This script creates a new task and launches the editor to display it. GTG should be running
24
 
"""
 
21
""" This script creates a new task and launches the editor to display it. """
25
22
 
 
23
import cgi
 
24
import dbus
26
25
import re
27
26
import sys
28
 
import dbus
29
 
import cgi
30
 
import getopt
 
27
 
 
28
from optparse import OptionParser
 
29
 
31
30
from GTG import _
32
31
 
33
 
def get_task(title, body) :
34
 
    #We will connect on the session bus
 
32
 
 
33
def new_task(title, body):
 
34
    """ Open a new task in GTG with given title and body """
35
35
    bus = dbus.SessionBus()
36
 
    liste = bus.list_names()
37
 
    busname = "org.gnome.GTG"
38
 
    remote_object = bus.get_object(busname,"/org/gnome/GTG")
39
 
    timi = dbus.Interface(remote_object,dbus_interface="org.gnome.GTG")
40
 
    #Calling the method
41
 
    timi.OpenNewTask(title, body)
42
 
 
43
 
def usage():
44
 
    print _("Usage: %s [-i | --interactive] [-h | --help]") % sys.argv[0]
45
 
        
46
 
if __name__ == '__main__':
47
 
    interactive = False
48
 
    #Command line options handling
49
 
    try:
50
 
        opts, args = getopt.getopt(sys.argv[1:], "hi", ["help", "interactive"])
51
 
    except getopt.GetoptError, err:
52
 
        # print help information and exit:
53
 
        print str(err) # will print something like "option -a not recognized"
54
 
        usage()
55
 
        sys.exit(2)
56
 
    for o, a in opts:
57
 
        if o in ("-i", "--interactive"):
58
 
            interactive = True
59
 
        elif o in ("-h", "--help"):
60
 
            usage()
61
 
            sys.exit()
62
 
        else:
63
 
            assert False, "unhandled option"
 
36
    proxy = bus.get_object("org.gnome.GTG", "/org/gnome/GTG")
 
37
    gtg = dbus.Interface(proxy, "org.gnome.GTG")
 
38
    gtg.OpenNewTask(title, body)
 
39
 
 
40
 
 
41
def main():
 
42
    """ Parse arguments and create a new task """
 
43
    parser = OptionParser()
 
44
    parser.add_option('-i', '--interactive', action='store_true',
 
45
      dest='interactive', help=_("Use input as the text of a new task"),
 
46
      default=False)
 
47
    (options, args) = parser.parse_args()
64
48
 
65
49
    title = " ".join(args)
66
 
    if interactive:
67
 
        optlist, args = getopt.getopt(args, 'i::')
 
50
    if options.interactive:
68
51
        body = sys.stdin.read()
69
52
        subject_regex = re.compile("^Subject: (.*)$", re.M | re.I)
70
53
        if subject_regex.search(body):
72
55
            title = title + ": " + subject
73
56
    else:
74
57
        body = ""
75
 
    get_task(title, cgi.escape(body))
76
 
 
77
 
 
 
58
    new_task(title, cgi.escape(body))
 
59
 
 
60
if __name__ == "__main__":
 
61
    main()