diff options
author | kongr45gpen <electrovesta@gmail.com> | 2016-01-21 17:15:39 +0200 |
---|---|---|
committer | kongr45gpen <electrovesta@gmail.com> | 2016-01-21 17:15:39 +0200 |
commit | 042bf88ca06f04d78bd6c7506b349934df291d31 (patch) | |
tree | 261656a2dc2e4f0821077e7e0264fb2856b90cbf | |
parent | f352d99c68ecea70b5599b50c3626636d22b845a (diff) | |
download | supybot_github-042bf88ca06f04d78bd6c7506b349934df291d31.tar.gz supybot_github-042bf88ca06f04d78bd6c7506b349934df291d31.tar.bz2 supybot_github-042bf88ca06f04d78bd6c7506b349934df291d31.zip |
Allow configuring the type of brackets to use
-rw-r--r-- | config.py | 3 | ||||
-rw-r--r-- | local/handler/GithubHandler.py | 3 | ||||
-rw-r--r-- | local/theme/CompactTheme.py | 4 | ||||
-rw-r--r-- | local/theme/DefaultTheme.py | 43 | ||||
-rw-r--r-- | local/theme/Theme.py | 6 | ||||
-rw-r--r-- | local/utility.py | 9 |
6 files changed, 44 insertions, 24 deletions
@@ -60,4 +60,7 @@ conf.registerGlobalValue(Github, 'port', conf.registerGlobalValue(Github, 'theme', registry.String('default', """The name of the theme that will be used to style messages""")) +conf.registerGlobalValue(Github, 'brackets', + registry.String('( )', """The brackets to use to enclose URLs (space-separated)""")) + # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/local/handler/GithubHandler.py b/local/handler/GithubHandler.py index d0835dc..b739769 100644 --- a/local/handler/GithubHandler.py +++ b/local/handler/GithubHandler.py @@ -68,6 +68,7 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): and configValue('passcode').strip().lower() != 'false' \ and configValue('passcode').strip().lower() != 'null' \ and configValue('passcode').strip().lower() != 'no' + brackets = parseBrackets(configValue('brackets')) resetConfigOverrides() @@ -109,7 +110,7 @@ class GithubHandler(BaseHTTPServer.BaseHTTPRequestHandler): log.error("The '%s' theme was not found" % themeName) klass = themes.DefaultTheme.DefaultTheme - theme = klass() + theme = klass(brackets) # # Handle different event types diff --git a/local/theme/CompactTheme.py b/local/theme/CompactTheme.py index 590b543..a4dbed7 100644 --- a/local/theme/CompactTheme.py +++ b/local/theme/CompactTheme.py @@ -4,11 +4,11 @@ from ..utility import * class CompactTheme(DefaultTheme): def commit(self, branch, repo, author, message, id, url): - self.msgs.append("%s @ %s: %s %s: %s (%s)" % ( + self.msgs.append("%s @ %s: %s %s: %s %s" % ( ircutils.bold(ircutils.mircColor(branch, "blue")), ircutils.bold(repo), ircutils.mircColor(author, "green"), ircutils.mircColor(id[0:6], "dark grey"), maxLen(message.splitlines()[0], 300), - url + self.enclose(url) )) diff --git a/local/theme/DefaultTheme.py b/local/theme/DefaultTheme.py index 48badb8..7bd8bfc 100644 --- a/local/theme/DefaultTheme.py +++ b/local/theme/DefaultTheme.py @@ -4,23 +4,23 @@ from ..utility import * class DefaultTheme(Theme): def push(self, branch, repo, actor, count, url): - self.msgs.append( "%s @ %s: %s pushed %s %s (%s)%s" % ( + self.msgs.append( "%s @ %s: %s pushed %s %s %s%s" % ( ircutils.bold(ircutils.mircColor(branch, "blue")), ircutils.bold(repo), ircutils.mircColor(actor, "green"), ircutils.bold(str(count)), plural(count, "commit", "commits"), - url, + self.enclose(url), ':' if count else '' )) def commit(self, branch, repo, author, message, id, url): - self.msgs.append("%s @ %s: %s * %s (%s)" % ( + self.msgs.append("%s @ %s: %s * %s %s" % ( ircutils.bold(ircutils.mircColor(branch, "blue")), ircutils.bold(repo), ircutils.mircColor(author, "green"), ircutils.bold(id[0:6]), - url + self.enclose(url) )) commitlines = message.splitlines() @@ -45,7 +45,7 @@ class DefaultTheme(Theme): ircutils.bold(ircutils.mircColor(base, "blue")), distinctMessage, ircutils.bold(ircutils.mircColor(to, "blue")), - ' (%s)' % url if url else '' + ' %s' % self.enclose(url) if url else '' )) def branch(self, repo, actor, action, count, to, url, base = None): @@ -55,7 +55,7 @@ class DefaultTheme(Theme): colorAction(action), ircutils.bold(ircutils.mircColor(to, "blue")), ' from %s' % ircutils.bold(ircutils.mircColor(base, "blue")) if base else '', - ' (%s)' % url if url else '', + ' %s' % self.enclose(url) if url else '', ':' if count else '' )) @@ -74,7 +74,7 @@ class DefaultTheme(Theme): colorAction(action), commitInfo, ircutils.bold(ircutils.mircColor(to, "blue")), - ' (%s)' % url if url else '' + ' %s' % self.enclose(url) if url else '' )) def issue(self, repo, actor, action, issueNo, issueTitle, creator, milestone, url, assignee = None, comment = None, labelName = None, labelColor = None): @@ -91,7 +91,7 @@ class DefaultTheme(Theme): elif action == 'labeled' or action == 'unlabeled': extra = " as %s" % ircutils.mircColor(labelName, hexToMirc(labelColor)) - self.msgs.append( "%s: %s %s issue #%s \"%s\"%s%s%s %s%s)%s" % ( + self.msgs.append( "%s: %s %s issue #%s \"%s\"%s%s %s %s" % ( ircutils.bold(repo), formattedActor, colorAction(action), @@ -99,19 +99,20 @@ class DefaultTheme(Theme): ircutils.bold(issueTitle), " by %s" % ircutils.mircColor(creator,"green") if creator != actor else '', extra, - " (%s" % ircutils.mircColor(milestone, "brown") if milestone else '', - '- ' if milestone else '(', - url, + self.enclose("%s%s" % ( + ircutils.mircColor(milestone, "brown") + '- ' if milestone else '', + url + )), ": %s" % maxLen(comment, 70) if comment else '' )) def wikiPush(self, repo, actor, count, url): - self.msgs.append( "%s: %s modified %s wiki %s (%s):" % ( + self.msgs.append( "%s: %s modified %s wiki %s %s:" % ( ircutils.bold(repo), ircutils.mircColor(actor, "green"), ircutils.bold(str(count)), plural(count, "page", "pages"), - url + self.enclose(url) )) def wikiPages(self, repo, actor, pages, url): @@ -119,12 +120,12 @@ class DefaultTheme(Theme): for page in pages: if configValue("hidePush") and urlShown is False: - pageurl = "(%s)" % (url,) + pageurl = self.enclose(url) urlShown = True elif configValue("hidePush"): pageurl = "" else: - pageurl = "(%s)" % (page['url'],) + pageurl = self.enclose(page['url']) self.msgs.append( "%s: %s %s %s * %s %s" % ( ircutils.bold(repo), @@ -136,20 +137,22 @@ class DefaultTheme(Theme): )) def travis(self, branch, repo, status, commitId, commitMessage, commitAuthor, buildUrl): - self.msgs.append( "%s @ %s: Build status: %s * %s by %s (%s - %s)" % ( + self.msgs.append( "%s @ %s: Build status: %s * %s by %s %s" % ( ircutils.bold(ircutils.mircColor(branch, "blue")), ircutils.bold(repo), colorAction(status.lower()), ircutils.bold(commitId[0:6]), ircutils.mircColor(commitAuthor, "green"), - ircutils.mircColor(maxLen(commitMessage, 50), "dark gray"), - buildUrl + self.enclose("%s - %s" % ( + ircutils.mircColor(maxLen(commitMessage, 50), "dark gray"), + buildUrl + )) )) def status(self, repo, status, description, url): - self.msgs.append( "%s: %s - %s (%s)" % ( + self.msgs.append( "%s: %s - %s %s" % ( ircutils.bold(repo), colorAction(status), description, - url + self.enclose(url) )) diff --git a/local/theme/Theme.py b/local/theme/Theme.py index a1c565d..8aa32fb 100644 --- a/local/theme/Theme.py +++ b/local/theme/Theme.py @@ -1,6 +1,10 @@ class Theme(object): - def __init__(self): + def __init__(self, brackets = "()"): self.msgs = [] + self.brackets = brackets def finalize(self): pass + + def enclose(self, text): + return "%s%s%s" % (self.brackets[0], text, self.brackets[1]) diff --git a/local/utility.py b/local/utility.py index 3487b06..aa96835 100644 --- a/local/utility.py +++ b/local/utility.py @@ -41,6 +41,15 @@ def plural(number, s, p): return p return s +def parseBrackets(bracketConfig): + if " " in bracketConfig: + return tuple(bracketConfig.split(' ', 1)) + else: + # Cut the config in the middle + mid = len(bracketConfig)/2 + return (bracketConfig[:mid], bracketConfig[mid:]) + + def maxLen(msg, maxn=400, splitLines=True): """Cut down a string if its longer than `maxn` chars""" |