supporting configurable color for specified nicks and regex nicks

Bug #1069589 reported by Roy Tam
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
irclog2html
Triaged
Wishlist
Unassigned

Bug Description

For now, I can edit irclog2html.py for custom color for specified nicks, but I don't want to modify python script at all.
And I don't have an good idea on implementing custom color for regex nicks (for the commit bots that will enter the channel with different number suffix)

Tags: color
Revision history for this message
Marius Gedminas (mgedmin) wrote :

Sounds like a good idea. Care to provide a patch? ;)

Changed in irclog2html:
status: New → Triaged
importance: Undecided → Wishlist
Revision history for this message
Roy Tam (roytam) wrote :

> Sounds like a good idea. Care to provide a patch? ;)
for first one, I have some idea:
- adding an option for loading colors for nicks in file containing "nick\t#rrggbb" lines, and load like this:
d = {}
with open(default_colors) as f:
    for line in f:
       (key, val) = line.split('\t')
       d[key] = val

...
nick_colour = NickColourizer(default_colours=d)

I can provide a patch against 2.9.2 if I make it done. (I have a ColorChooser local patch (for 2.9.2 also) lying in my harddisk)

Revision history for this message
Marius Gedminas (mgedmin) wrote :

I'm not fond of the idea of using tab characters as separators. How about 'nick = #rrggbb'?

Revision history for this message
Roy Tam (roytam) wrote :

> How about 'nick = #rrggbb'?
Sure. Since '=' is not valid in nick, we can do so.
(key, val) = line.split(' = ')

For second one, I thought about the flow:
- in NickColourizer.__getitem__, check if nick is in nick_colour dict, if not then check regex nick dict first
- if one of regex nick dict is matched, add it to nick_colour and return
- else run the normal procedure

but how can I combine 2 types into 1 file and 1 option?
simple split seems not play well with optional field, writing more code is needed. (I'm not Python expert ;) )

Revision history for this message
Marius Gedminas (mgedmin) wrote :

How about a traditional INI-style config file with sections?

    # comments are nice to have too

    [color:nick]
    joe = #rrggbb
    barney = #rrggbb

    [color:regex]
    somebot\d* = #rrggbb

I'm now regretting not using an INI style for the logs2html config file, but maybe it's not too late to reconsider. Then I could have a single config file describing everything.

Revision history for this message
Roy Tam (roytam) wrote :

> How about a traditional INI-style config file with sections?
it will be nice, but we can't use ConfigParser as it is too strict that it will complain about leading spaces (irssi logs having status prefix in the name (' mynick' is normal, '+mynick' for voiced, '@mynick' of op)

Revision history for this message
Roy Tam (roytam) wrote :

so rolling out non-standard class for such case is needed:
(Modified from http://webcache.googleusercontent.com/search?q=cache:wkTGGVUY2XsJ:www.dev.idv.tw/mediawiki/index.php/%E7%94%A8%E4%BE%86%E8%99%95%E7%90%86INI%E6%AA%94%E6%A1%88%E7%9A%84Python%E7%AF%84%E4%BE%8B+&cd=50&ct=clnk )

mynick.ini sample:
[nicks:normal]
 joe=#4433ff
+may=#ff88cc
@tom=#ccff22

[nicks:re]
^ cone-\d+=#ccccbb
^ lCIA-\d+=#bbccbb

Test:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from IniFile import *
>>> ini=IniFile('mynick.ini')
>>> ini['nicks:normal'].items()
[('@tom', '#ccff22'), (' joe', '#4433ff'), ('_values_', ['tger', 'br45t5']), ('+may', '#ff88cc')]
>>> ini['nicks:re'].items()
[('^ cone-\\d+', '#ccccbb'), ('^ lCIA-\\d+', '#bbccbb')]
>>>

IniFile.py:
#!/usr/bin/env python
import re
import string

class IniFile:
 _section = re.compile(r'^\[(.*)\]\s*')
 _option = re.compile(r'^(.+)\s*=\s*(.*)$')

 def __init__(self, fn):
  self.filename = fn
  self._data = {}

  # Parse the .ini file
  f = file(fn)
  sect = ""
  for line in f:
    line = string.rstrip(line)
    if line == "" or line[0] == ';' or line[0] == '#':
     continue
    matchObj = self._section.match(line)
    if matchObj != None:
     sect = matchObj.group(1)
     if not self._data.has_key(sect):
      self._data[sect] = {}
    elif sect:
     matchObj = self._option.match(line)
     if matchObj != None:
      opt, val = matchObj.group(1, 2)
      self._data[sect][opt] = val
     else:
      if not '_values_' in self._data[sect]:
       self._data[sect]['_values_'] = []
      self._data[sect]['_values_'].append(line)
  f.close()
  del f

 def items(self):
  return self._data.items()
 def __getitem__(self,x):
  return self._data[x]
 def values(self):
  return self._data.values()
 def __len__( self ):
  return len(self._data)
 def __repr__(self):
  return 'self._data'
 def __str__(self):
  return 'self._data'
 def keys(self):
  return self._data.keys()
 def has_key(self,x):
  return self._data.has_key(x)

Revision history for this message
Marius Gedminas (mgedmin) wrote :

Copying and pasting random code from the web with no licensing information is not going to be helpful, sorry.

Do you have an example of an irssi log file with nicks that contain spaces? I could use a test case.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.