Skip to content

Commit

Permalink
Display warning for missing regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Mar 17, 2016
1 parent 3553d54 commit 48908b1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion data/templates/fry/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ aliases:
- futurama-fry
- not-sure-if
regexes:
- (not sure if .+)/?(or .+)
- (not sure .+)/?(or .+)
- (.+ if .+)/?(or .+)
1 change: 1 addition & 0 deletions data/templates/sb/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ default:
link: http://knowyourmeme.com/memes/scumbag-brain
aliases:
- scumbag-brain
regexes: []
5 changes: 5 additions & 0 deletions memegen/domain/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,18 @@ def validate_size(self):
return True

def validate_regexes(self):
if not self.regexes:
self._warn("no regexes")
for regex in self.regexes:
pattern = regex.pattern
if ")/?(" not in pattern:
self._error("regex missing separator: %r", pattern)
return False
return True

def _warn(self, fmt, *objects):
log.warning("Template '%s' " + fmt, self, *objects)

def _error(self, fmt, *objects):
log.error("Template '%s' " + fmt, self, *objects)

Expand Down

0 comments on commit 48908b1

Please sign in to comment.