3
# Author: Rodney Dawes <rodney.dawes@canonical.com>
5
# Copyright 2009 Canonical Ltd.
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranties of
13
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14
# PURPOSE. See the GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License along
17
# with this program. If not, see <http://www.gnu.org/licenses/>.
19
from __future__ import with_statement
24
from xdg.BaseDirectory import xdg_cache_home
26
from threading import Thread
28
from launchpadlib.launchpad import Launchpad, EDGE_SERVICE_ROOT
29
from launchpadlib.credentials import Credentials
33
def __init__(self, project):
34
self.project = project
36
self.cachedir = os.path.join(xdg_cache_home, "lptools")
37
if not os.path.isdir(self.cachedir):
38
os.makedirs(self.cachedir)
44
def __start_calendar(self):
45
self.buffer.append("BEGIN:VCALENDAR")
46
self.buffer.append("VERSION:2.0")
47
self.buffer.append("PRODID:-//Canonical/lptools/NONSGML v1.0//EN")
49
def __end_calendar(self):
50
self.buffer.append("END:VCALENDAR")
52
def __convert_to_ical(self, item):
53
for milestone in item.all_milestones:
54
if not milestone.date_targeted:
56
self.buffer.append("BEGIN:VEVENT")
57
date = milestone.date_targeted.strftime("%Y%m%dT%H%M%SZ")
58
self.buffer.append("DTSTART:%s" % date)
59
self.buffer.append("SUMMARY:%s" % milestone.name)
60
self.buffer.append("END:VEVENT")
62
def __login_and_go(self):
63
credsfile = os.path.join(self.cachedir, "credentials")
65
if os.path.exists(credsfile):
68
with file(credsfile) as f:
70
self.launchpad = Launchpad(creds, EDGE_SERVICE_ROOT)
72
self.launchpad = Launchpad.get_token_and_login(
76
with file(credsfile, "w") as f:
77
self.launchpad.credentials.save(f)
79
self.__start_calendar()
81
lp_project = self.launchpad.project_groups[self.project]
83
lp_project = self.launchpad.projects[self.project]
85
self.__convert_to_ical(lp_project)
90
self.thread = Thread(target=self.__login_and_go).start()
96
return "\n".join(self.buffer)
98
if __name__ == "__main__":
100
project = sys.argv[1]
102
print "Usage: %s <project>" % sys.argv[0]
106
mt = MSMain(project=sys.argv[1])
108
except KeyboardInterrupt: