Skip to content

Commit

Permalink
Fix the build
Browse files Browse the repository at this point in the history
  • Loading branch information
embolalia committed Feb 14, 2015
1 parent 79d76ed commit 1afb421
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion checkstyle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ignore='--ignore=E501,E128,E127'
# These are rules that are relatively new or have had their definitions tweaked
# recently, so we'll forgive them until versions of PEP8 in various developers'
#distros are updated
ignore=$ignore',E265,E713,E111,E113'
ignore=$ignore',E265,E713,E111,E113,E402,E731'
# For now, go through all the checking stages and only die at the end
exit_code=0

Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pygeoip
praw
feedparser
pyenchant
pep8==1.4.6
File renamed without changes.
75 changes: 75 additions & 0 deletions willie/config/validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# coding=utf8
from __future__ import unicode_literals

if sys.version_info.major >= 3:
unicode = str
basestring = str


class StrictConfigSection(object):
# TODO make take a parser
def __init__(self, section):
self._section = section


def _bool(value):
if value.lower() in ['1', 'yes', 'true', 'on']:
return True
elif value.lower() in ['0', 'no', 'false', 'off']:
return False
else:
raise ValueError('Value must be a bool-like string.')


class ConfigProperty(object):
def __init__(self, name, example=None, default_to_example=False,
cls=unicode):
self.name = name
self.example = example
self._do_default = defaults
if cls is bool:
cls = _bool
elif cls is list:
cls = _list
self._cls = cls
self._have_parsed = False
self._deserialized = None

def __get__(self, obj, objtype=None):
if not self._have_parsed:
value = getattr(obj._section, self.name)
self._deserialized = self.deserialize(value)
self._have_parsed = True
return self._deserialized

def __set__(self, obj, value):
serial = self.serialize(serial)
self._deserialized = value
self._have_parsed = True
setattr(obj._section, self.name, serial)

def deserialize(self, value):
"""Return the value as the appropriate type."""
return self._cls(value)

def serialize(self, value):
"""Return the value as a string to be put in the config file"""
return unicode(value)
#TODO validate doable config values?


class CoreConfig(StrictConfigSection):
# name, example, default, cls
_strict = True
nick = ConfigProperty('nick', Identifier('Willie'), True, Identifier)
"""The nickname for the bot"""
user = ConfigProperty('user', 'willie', True)
"""The "user" for your bot (the part that comes before the @ in the hostname)"""
name = ConfigProperty('name', 'Willie - http://willie.dftba.net',
True)
"""The "real name" of you bot for WHOIS responses"""
host = ConfigProperty('host', 'irc.dftba.net', True)
"""The host to connect to"""
port = ConfigProperty('port', 6667, True, int)
"""The port to connect to"""
use_ssl = ConfigProperty('use_ssl', False, True, bool)

0 comments on commit 1afb421

Please sign in to comment.