Skip to content
This repository was archived by the owner on Aug 4, 2020. It is now read-only.

Commit 7e2d804

Browse files
committed
Search multiple paths for config
print url without punctuation
1 parent 082d216 commit 7e2d804

File tree

1 file changed

+47
-17
lines changed

1 file changed

+47
-17
lines changed

slander.py

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
This is the configuration file used for the CiviCRM project:
1313
jobs:
1414
svn:
15-
changeset_url_format:
16-
https://fisheye2.atlassian.com/changelog/CiviCRM?cs=%s
1715
root: http://svn.civicrm.org/civicrm
1816
args: --username SVN_USER --password SVN_PASSS
17+
changeset_url_format:
18+
https://fisheye2.atlassian.com/changelog/CiviCRM?cs=%s
1919
jira:
2020
base_url:
2121
http://issues.civicrm.org/jira
@@ -57,8 +57,9 @@
5757
import feedparser
5858
from HTMLParser import HTMLParser
5959

60-
6160
test = False
61+
maxlen = 200
62+
config = None
6263

6364
class RelayToIRC(irc.IRCClient):
6465
"""
@@ -76,6 +77,9 @@ def connectionMade(self):
7677
self.nickname = self.config["irc"]["nick"]
7778
self.realname = self.config["irc"]["realname"]
7879
self.channel = self.config["irc"]["channel"]
80+
global maxlen
81+
if "maxlen" in self.config["irc"]:
82+
maxlen = self.config["irc"]["maxlen"]
7983
if "sourceURL" in self.config:
8084
self.sourceURL = self.config["sourceURL"]
8185

@@ -95,8 +99,13 @@ def privmsg(self, user, channel, message):
9599
if re.search(r'\bhelp\b', message):
96100
self.say(channel, "If I only had a brain: %s -- Commands: help jobs kill last" % (self.sourceURL, ))
97101
elif re.search(r'\bjobs\b', message):
98-
jobs_desc = [("%s: %s" % (type(j), j.config)) for j in self.jobs]
99-
self.say(channel, "Running jobs %s" % (", ".join(jobs_desc), ))
102+
jobs_desc = ", ".join(
103+
[("%s: %s" % (j.config['class'], j.config))
104+
for j in self.jobs]
105+
)
106+
jobs_desc = re.sub(r'p(ass)?w(ord)?[ :=]*[^ ]+', r'p***word', jobs_desc)
107+
108+
self.say(channel, "Running jobs [%s]" % (jobs_desc, ))
100109
#elif re.search(r'\bkill\b', message):
101110
# self.say(self.channel, "Squeal! Killed by %s" % (user, ))
102111
# self.factory.stopTrying()
@@ -168,7 +177,7 @@ def check(self):
168177
latest = self.revision()
169178
if self.previous_revision and latest != self.previous_revision:
170179
for rev in range(self.previous_revision + 1, latest + 1):
171-
yield "r%s by %s: %s [%s]" % self.revision_info(rev)
180+
yield "r%s by %s: %s -- %s" % self.revision_info(rev)
172181
self.previous_revision = latest
173182
except Exception, e:
174183
print "ERROR: %s" % e
@@ -216,7 +225,7 @@ def parse(self, entry):
216225
summary = truncate(strip(entry.summary))
217226
url = "%s/browse/%s" % (self.base_url, issue)
218227

219-
return "%s: %s %s [%s]" % (entry.author_detail.name, issue, summary, url)
228+
return "%s: %s %s -- %s" % (entry.author_detail.name, issue, summary, url)
220229

221230
class MinglePoller(FeedPoller):
222231
"""
@@ -294,21 +303,42 @@ def create_jobs(d):
294303
Read job definitions from a config source, create an instance of the job using its configuration, and store the config for reference.
295304
"""
296305
jobs = []
297-
for type, options in d.items():
298-
classname = type.capitalize() + "Poller"
306+
for type_name, options in d.items():
307+
classname = type_name.capitalize() + "Poller"
299308
klass = globals()[classname]
300309
job = klass(**options)
301310
job.config = options
311+
job.config['class'] = type_name
302312
jobs.append(job)
303313
return jobs
304314

315+
def load_config(path):
316+
dotfile = os.path.expanduser(path)
317+
if os.path.exists(dotfile):
318+
print "Reading config from %s" % (dotfile, )
319+
return yaml.load(file(dotfile))
320+
321+
def parse_args(args):
322+
if len(args) == 2:
323+
search_paths = [
324+
args[1],
325+
"~/.slander-" + args[1],
326+
"/etc/slander-" + args[1],
327+
]
328+
else:
329+
search_paths = [
330+
"~/.slander",
331+
"/etc/slander",
332+
]
333+
for path in search_paths:
334+
config = load_config(path)
335+
if config:
336+
break
337+
338+
if not config:
339+
sys.exit(args[0] + ": No config!")
340+
341+
return config
305342

306343
if __name__ == "__main__":
307-
if len(sys.argv) == 2:
308-
dotfile = sys.argv[1]
309-
else:
310-
dotfile = os.path.expanduser("~/.slander")
311-
print "Reading config from %s" % (dotfile, )
312-
config = yaml.load(file(dotfile))
313-
maxlen = config["irc"]["maxlen"]
314-
RelayToIRC.run(config)
344+
RelayToIRC.run(parse_args(sys.argv))

0 commit comments

Comments
 (0)