Пример #1
0
def read_configs():
    global ConfigRead

    try:
        dbg('trying to load CONFIG')
        dbg('current working directory: %s' % os.getcwd())
        f = unicode(open('CONFIG', 'r').read(), 'utf-8')

        for line in f.split(u'\n'):
            if line.startswith(u'#'):
                continue

            if u'=' in line:
                l = [s.strip() for s in line.split(u'=')]
                if l[0] in configs:
                    dbg('config %s found, value=%s' % (l[0], eval(l[1])))
                    configs[l[0]] = eval(l[1])
                else:
                    err('unrecognized config parameter %s' % l[0])

    except IOError as e:
        if e.errno == 2:
            dbg('CONFIG not found, using default config')
            return
        else:
            err('error while loading CONFIG')
            return
    def __init__(self, calendar_timezone, calendar_location):
        gmail_account = get_account_info(configs[CONFIG_KEY_GMAIL_ACCOUNT],
                                         GMAIL_PROMPT)
        gmail_pwd = get_account_info(configs[CONFIG_KEY_GMAIL_PWD],
                                     PASSWORD_PROMPT,
                                     True)

        self.client = gdata.calendar.client.CalendarClient(
            source=GoogleCalendarProxy.app_source
        )

        try:
            info('logging in as %s' % gmail_account)
            self.client.ClientLogin(gmail_account, gmail_pwd,
                                    self.client.source)

            for calendar in self.client.GetOwnCalendarsFeed().entry:
                if calendar.summary and\
                   calendar.summary.text == configs[CONFIG_KEY_THIS_CALENDAR_SUMMARY]:
                    if configs[CONFIG_KEY_IF_THIS_CALENDAR_FOUND_THEN_PERFORM_DELETE]:
                        info('previously created calendar %s found,'
                             'deleting' % calendar.title.text)
                        self.client.Delete(calendar.GetEditLink().href)
                        self.current_calendar = self.client.InsertCalendar(
                            new_calendar=self.gen_calender(
                                configs[CONFIG_KEY_THIS_CALENDAR_TITLE],
                                configs[CONFIG_KEY_THIS_CALENDAR_SUMMARY],
                                configs[CONFIG_KEY_THIS_CALENDAR_COLOR],
                                calendar_timezone,
                                calendar_location
                            )
                        )
                    else:
                        self.current_calendar = calendar
                    break
            else:
                self.current_calendar = self.client.InsertCalendar(
                    new_calendar=self.gen_calender(
                        configs[CONFIG_KEY_THIS_CALENDAR_TITLE],
                        configs[CONFIG_KEY_THIS_CALENDAR_SUMMARY],
                        configs[CONFIG_KEY_THIS_CALENDAR_COLOR],
                        calendar_timezone,
                        calendar_location
                    )
                )
            dbg('calendar id = %s' % self.current_calendar.content.src)

        except gdata.client.RequestError as e:
            err(e)
            return