Make dependency on python-dateutil optionnal.

This commit is contained in:
Valentin Lorentz 2013-11-24 14:47:26 +00:00
parent a0c5e06445
commit b8abbd1e36

View File

@ -31,8 +31,6 @@ import time
TIME = time # For later use.
from datetime import datetime
from dateutil import parser
import supybot.conf as conf
import supybot.utils as utils
from supybot.commands import *
@ -40,7 +38,10 @@ import supybot.callbacks as callbacks
from supybot.i18n import PluginInternationalization, internationalizeDocstring
_ = PluginInternationalization('Time')
def parse(s):
try:
from dateutil import parser
def parse(s):
todo = []
s = s.replace('noon', '12:00')
s = s.replace('midnight', '00:00')
@ -54,6 +55,8 @@ def parse(s):
for f in todo:
i = f(i)
return i
except ImportError:
parse = None
class Time(callbacks.Plugin):
@internationalizeDocstring
@ -99,6 +102,9 @@ class Time(callbacks.Plugin):
<time string> can be any number of natural formats; just try something
and see if it will work.
"""
if not parse:
irc.error(_('This command is not available on this bot, ask the '
'owner to install the python-dateutil library.'), Raise=True)
now = int(time.time())
new = parse(s)
if new != now:
@ -113,6 +119,9 @@ class Time(callbacks.Plugin):
Returns the number of seconds until <time string>.
"""
if not parse:
irc.error(_('This command is not available on this bot, ask the '
'owner to install the python-dateutil library.'), Raise=True)
now = int(time.time())
new = parse(s)
if new != now: