diff options
author | Richard Darst <rkd@zgib.net> | 2009-11-25 08:57:04 (GMT) |
---|---|---|
committer | Richard Darst <rkd@zgib.net> | 2009-11-25 08:57:04 (GMT) |
commit | 72cdcb42ebbb910b38758f4656cf1aceb6bca9d5 (patch) | |
tree | 2e39c390ba14b2ddb251960daa08bbeb04595ce8 | |
parent | f96de7415379b6c3431c3e67b507ed803719dbf2 (diff) |
Add %(channel) replacement to filenamesupstream
- Allows configuration of saving on a per-network basis.
darcs-hash:20091125085704-82ea9-6068d1ae3eb521f19447c6e07f8dd46390ad6868.gz
-rw-r--r-- | doc/Manual.txt | 8 | ||||
-rw-r--r-- | meeting.py | 9 | ||||
-rw-r--r-- | plugin.py | 6 | ||||
-rw-r--r-- | tests/run_test.py | 22 |
4 files changed, 37 insertions, 8 deletions
diff --git a/doc/Manual.txt b/doc/Manual.txt index 3b3665a..1dc2ea4 100644 --- a/doc/Manual.txt +++ b/doc/Manual.txt @@ -452,11 +452,11 @@ These variables are set either in ``meetingLocalConfig.py`` (in the ``logFileDir`` and ``logUrlPrefix``. Variables available for replacement using ``%(name)s`` include: - ``channel``, ``meetingname``. Double percent signs (e.g.: ``%%Y`` - are time formats, from ``time.strftime``. + ``channel``, ``network``, ``meetingname``. Double percent signs + (e.g.: ``%%Y`` are time formats, from ``time.strftime``. - This filename does *not* include extensions. Those are found from - the writers, via the variable ``writer_map``. + You should *not* include filename extensions here. Those are + found from the writers, via the variable ``writer_map``. Putting these all together, a set of variables could be: 1) ``logFileDir = /srv/www/meetings/`` @@ -148,11 +148,13 @@ class Config(object): else: pattern = self.filenamePattern channel = self.M.channel.strip('# ').lower().replace('/', '') + network = self.M.network.strip(' ').lower().replace('/', '') if self.M._meetingname: meetingname = self.M._meetingname.replace('/', '') else: meetingname = channel - path = pattern%locals() + path = pattern%{'channel':channel, 'network':network, + 'meetingname':meetingname} path = time.strftime(path, self.M.starttime) # If we want the URL name, append URL prefix and return if url: @@ -428,7 +430,7 @@ class Meeting(MeetingCommands, object): filename=None, writeRawLog=False, setTopic=None, sendReply=None, getRegistryValue=None, safeMode=False, channelNicks=None, - extraConfig={}): + extraConfig={}, network='nonetwork'): self.config = Config(self, writeRawLog=writeRawLog, safeMode=safeMode, extraConfig=extraConfig) if getRegistryValue is not None: @@ -439,6 +441,7 @@ class Meeting(MeetingCommands, object): self._setTopic = setTopic self.owner = owner self.channel = channel + self.network = network self.currenttopic = "" if oldtopic: self.oldtopic = self.config.dec(oldtopic) @@ -540,6 +543,8 @@ class Meeting(MeetingCommands, object): self.minutes.append(m) def replacements(self): repl = { } + repl['channel'] = self.channel + repl['network'] = self.network repl['MeetBotInfoURL'] = self.config.MeetBotInfoURL repl['timeZone'] = self.config.timeZone repl['starttime'] = repl['endtime'] = "None" @@ -74,6 +74,7 @@ class MeetBot(callbacks.Plugin): nick = msg.nick channel = msg.args[0] payload = msg.args[1] + network = irc.msg.tags['receivedOn'] # The following is for debugging. It's excellent to get an # interactive interperter inside of the live bot. use @@ -85,7 +86,7 @@ class MeetBot(callbacks.Plugin): # Get our Meeting object, if one exists. Have to keep track # of different servers/channels. # (channel, network) tuple is our lookup key. - Mkey = (channel,irc.msg.tags['receivedOn']) + Mkey = (channel,network) M = meeting_cache.get(Mkey, None) # Start meeting if we are requested @@ -106,10 +107,11 @@ class MeetBot(callbacks.Plugin): setTopic = _setTopic, sendReply = _sendReply, getRegistryValue = self.registryValue, safeMode=True, channelNicks=_channelNicks, + network=network, ) meeting_cache[Mkey] = M recent_meetings.append( - (channel, irc.msg.tags['receivedOn'], time.ctime())) + (channel, network, time.ctime())) if len(recent_meetings) > 10: del recent_meetings[0] # If there is no meeting going on, then we quit diff --git a/tests/run_test.py b/tests/run_test.py index 78663d1..07aecdf 100644 --- a/tests/run_test.py +++ b/tests/run_test.py @@ -223,6 +223,28 @@ class MeetBotTest(unittest.TestCase): self.assert_('<link rel="stylesheet" ' not in results['.log.html']) self.assert_('<style type="text/css" ' not in results['.log.html']) + def test_filenamevars(self): + def getM(fnamepattern): + M = meeting.Meeting(channel='somechannel', + network='somenetwork', + owner='nobody', + extraConfig={'filenamePattern':fnamepattern}) + M.addline('nobody', '#startmeeting') + return M + # Test the %(channel)s and %(network)s commands in supybot. + M = getM('%(channel)s-%(network)s') + assert M.config.filename().endswith('somechannel-somenetwork'), \ + "Filename not as expected: "+M.config.filename() + # Test dates in filenames + M = getM('%(channel)s-%%F') + import time + assert M.config.filename().endswith(time.strftime('somechannel-%F')),\ + "Filename not as expected: "+M.config.filename() + # Test #meetingname in filenames + M = getM('%(channel)s-%(meetingname)s') + M.addline('nobody', '#meetingname blah1234') + assert M.config.filename().endswith('somechannel-blah1234'),\ + "Filename not as expected: "+M.config.filename() if __name__ == '__main__': |