Files
ubuntu-bots/Webcal/rruler.py
Terence Simpson ad7a493262 Update copyright/license/author/contributors information
Make sure all files have encoding set to utf-8 unless they already have an encoding
Added COPYING with contense of GPL-2
Added plugin name prefix to all log output. This should take the form of self.log.severity("Plugin: message"),
when not logging from plugin.py use: "Plugin/file_without_dot_py: message"
Bantracker: Made the confgure() function do something, it also creates an initial database if it doesn't exist
Encyclopedia: Made the configure() function do something, it also creates an initial database if it doesn't exist
PackageInfo: Improve the configure() function, it also now creates some initial .list files and prompts to run update_apt and update_apt_file
This goes some way to getting an "ubottu" package together, all we need to do is patch supybot-wizard to download the plugins
from bzr and put them somewhere supybot will see them, then the wizard will do all the initial setup
2010-05-24 14:38:06 +01:00

77 lines
2.6 KiB
Python

#!/usr/bin/env python
# -*- Encoding: utf-8 -*-
###
# Copyright (c) 2008-2010 Terence Simpson
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
###
from dateutil import rrule
import re, datetime
#wk_days = ('MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU')
wk_days = re.compile("([0-9]?)([M|T|W|F|S][O|U|E|H|R|A])")
rrule_map = {
'SECONDLY': rrule.SECONDLY,
'MINUTELY': rrule.MINUTELY,
'HOURLY': rrule.HOURLY,
'DAILY': rrule.DAILY,
'WEEKLY': rrule.WEEKLY,
'MONTHLY': rrule.MONTHLY,
'YEARLY': rrule.YEARLY,
'MO': rrule.MO,
'TU': rrule.TU,
'WE': rrule.WE,
'TH': rrule.TH,
'FR': rrule.FR,
'SA': rrule.SA,
'SU': rrule.SU }
def rrule_wrapper(*args, **kwargs):
for k, v in kwargs.iteritems():
if k == 'byday' or k == 'BYDAY':
del kwargs[k]
groups = wk_days.match(v[0]).groups()
if groups[0]:
kwargs['byweekday'] = rrule_map[groups[1]](int(groups[0]))
else:
kwargs['byweekday'] = rrule_map[groups[1]]
else:
del kwargs[k]
k = k.lower()
if isinstance(v, list):
if len(v) > 1:
res = []
for x in v:
if isinstance(x, basestring) and wk_days.match(x):
res.append(rrule_map[wk_days.match(x).group(1)])
elif v in rrule_map:
res.append(rrule_map[x])
elif isinstance(x, datetime.datetime):
res.append(datetime.datetime.fromordinal(x.toordinal()))
else:
res.append(v)
kwargs[k] = tuple(res)
else:
if isinstance(v[0], basestring) and wk_days.match(v[0]):
kwargs[k] = rrule_map[wk_days.match(v[0]).group(0)]
elif v[0] in rrule_map:
kwargs[k] = rrule_map[v[0]]
elif isinstance(v[0], datetime.datetime):
kwargs[k] = datetime.datetime.fromordinal(v[0].toordinal())
else:
kwargs[k] = v[0]
else:
kwargs[k] = v
return rrule.rrule(*args, **kwargs)