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. TIME = time # For later use.
from datetime import datetime from datetime import datetime
from dateutil import parser
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
from supybot.commands import * from supybot.commands import *
@ -40,6 +38,9 @@ import supybot.callbacks as callbacks
from supybot.i18n import PluginInternationalization, internationalizeDocstring from supybot.i18n import PluginInternationalization, internationalizeDocstring
_ = PluginInternationalization('Time') _ = PluginInternationalization('Time')
try:
from dateutil import parser
def parse(s): def parse(s):
todo = [] todo = []
s = s.replace('noon', '12:00') s = s.replace('noon', '12:00')
@ -54,6 +55,8 @@ def parse(s):
for f in todo: for f in todo:
i = f(i) i = f(i)
return i return i
except ImportError:
parse = None
class Time(callbacks.Plugin): class Time(callbacks.Plugin):
@internationalizeDocstring @internationalizeDocstring
@ -99,6 +102,9 @@ class Time(callbacks.Plugin):
<time string> can be any number of natural formats; just try something <time string> can be any number of natural formats; just try something
and see if it will work. 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()) now = int(time.time())
new = parse(s) new = parse(s)
if new != now: if new != now:
@ -113,6 +119,9 @@ class Time(callbacks.Plugin):
Returns the number of seconds until <time string>. 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()) now = int(time.time())
new = parse(s) new = parse(s)
if new != now: if new != now: