~parthpanchl/gtg/fix-calendar1

1240.2.67 by huxuan
Convert all python2 declaration to python3 in header
1
#!/usr/bin/env python3
415.3.2 by Lionel Dricot
new command : gtg_new_task
2
# -*- coding:utf-8 -*-
3
# -----------------------------------------------------------------------------
1248.1.1 by Izidor Matušov
Updated every license in the head of files
4
# Getting Things GNOME! - A personal organizer for the GNOME desktop
1328 by Parin Porecha
Changed all instances of 2008-2012 to 2008-2013 and updated version to 0.3.1
5
# Copyright (c) 2008-2013 Lionel Dricot & Bertrand Rousseau
415.3.2 by Lionel Dricot
new command : gtg_new_task
6
#
7
# This program is free software: you can redistribute it and/or modify it under
8
# the terms of the GNU General Public License as published by the Free Software
9
# Foundation, either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# This program is distributed in the hope that it will be useful, but WITHOUT
13
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15
# details.
16
#
17
# You should have received a copy of the GNU General Public License along with
18
# this program.  If not, see <http://www.gnu.org/licenses/>.
19
# -----------------------------------------------------------------------------
20
1172 by Izidor Matušov
pylint likes gtg_new_task now :-)
21
""" This script creates a new task and launches the editor to display it. """
415.3.2 by Lionel Dricot
new command : gtg_new_task
22
1172 by Izidor Matušov
pylint likes gtg_new_task now :-)
23
import cgi
24
import dbus
542.1.3 by Bryce Harrington
Escape any HTML entities in the body (like <> around email addys)
25
import re
542.1.2 by Bryce Harrington
Add functionality to take task title from cmdline and body from stdin.
26
import sys
1172 by Izidor Matušov
pylint likes gtg_new_task now :-)
27
28
from optparse import OptionParser
29
1173 by Izidor Matušov
Pylint loves GTCli now :-)
30
from GTG import _
31
1172 by Izidor Matušov
pylint likes gtg_new_task now :-)
32
33
def new_task(title, body):
34
    """ Open a new task in GTG with given title and body """
415.3.2 by Lionel Dricot
new command : gtg_new_task
35
    bus = dbus.SessionBus()
1172 by Izidor Matušov
pylint likes gtg_new_task now :-)
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',
1289 by Izidor Matušov
PEP8ification by Nimit
45
                      dest='interactive',
46
                      help=_("Use input as the text of a new task"),
47
                      default=False)
1172 by Izidor Matušov
pylint likes gtg_new_task now :-)
48
    (options, args) = parser.parse_args()
573.1.1 by Luca Invernizzi
switch proposal
49
573.1.2 by Luca Invernizzi
Added options --help and --interactive to gtg_new_task
50
    title = " ".join(args)
1172 by Izidor Matušov
pylint likes gtg_new_task now :-)
51
    if options.interactive:
573.1.1 by Luca Invernizzi
switch proposal
52
        body = sys.stdin.read()
53
        subject_regex = re.compile("^Subject: (.*)$", re.M | re.I)
54
        if subject_regex.search(body):
55
            subject = subject_regex.findall(body)[0]
56
            title = title + ": " + subject
57
    else:
58
        body = ""
1172 by Izidor Matušov
pylint likes gtg_new_task now :-)
59
    new_task(title, cgi.escape(body))
60
61
if __name__ == "__main__":
62
    main()