artemis/artemis.py
changeset 63 c384fa42f8a2
parent 62 c933fa2cd204
child 66 4129876c8b86
equal deleted inserted replaced
62:c933fa2cd204 63:c384fa42f8a2
    15 from email.mime.text import MIMEText
    15 from email.mime.text import MIMEText
    16 
    16 
    17 from    termcolor       import colored
    17 from    termcolor       import colored
    18 
    18 
    19 
    19 
    20 state = { 'new':   ['new'],
    20 state = { 'new':      ['new'],
    21           'fixed': ['fixed', 'resolved'] }
    21           'resolved': ['fixed', 'resolved'] }
    22 annotation = { 'resolved': 'resolution' }
    22 annotation = { 'resolved': 'resolution' }
    23 default_state = 'new'
    23 default_state = 'new'
    24 default_issues_dir = ".issues"
    24 default_issues_dir = ".issues"
    25 filter_prefix = ".filter"
    25 filter_prefix = ".filter"
    26 date_format = '%a, %d %b %Y %H:%M:%S %1%2'
    26 date_format = '%a, %d %b %Y %H:%M:%S %1%2'
    77             if value:
    77             if value:
    78                 property_match = property_match and (mbox[root][property] == value)
    78                 property_match = property_match and (mbox[root][property] == value)
    79             else:
    79             else:
    80                 property_match = property_match and (property not in mbox[root])
    80                 property_match = property_match and (property not in mbox[root])
    81 
    81 
    82         if not show_all and (not properties or not property_match) and (properties or mbox[root]['State'].upper() in [f.upper() for f in state['fixed']]): continue
    82         if not show_all and (not properties or not property_match) and (properties or mbox[root]['State'].upper() in [f.upper() for f in state['resolved']]): continue
    83         if match_date and not date_match(util.parsedate(mbox[root]['date'])[0]): continue
    83         if match_date and not date_match(util.parsedate(mbox[root]['date'])[0]): continue
    84 
    84 
    85         if not list_properties:
    85         if not list_properties:
    86             summaries.append((_summary_line(mbox, root, issue[len(issues_path)+1:], colors),     # +1 for trailing /
    86             summaries.append((_summary_line(mbox, root, issue[len(issues_path)+1:], colors),     # +1 for trailing /
    87                               _find_mbox_date(mbox, root, order)))
    87                               _find_mbox_date(mbox, root, order)))
   425     else:
   425     else:
   426         return s
   426         return s
   427 
   427 
   428 def _read_colors(ui):
   428 def _read_colors(ui):
   429     colors = {}
   429     colors = {}
   430     # defaults
   430 
   431     colors['new.color']             = 'red'
   431     for k,v in ui.configitems('artemis'):
   432     colors['new.on_color']          = 'on_grey'
   432         if k == 'issues': continue
   433     colors['new.attrs']             = 'bold'
   433         k = k.split('.')
   434     colors['resolved.color']        = 'white'
   434         s = k[0]; t = k[1]
   435     colors['resolved.on_color']     = ''
   435         if s not in colors: colors[s] = {}
   436     colors['resolved.attrs']        = ''
   436         colors[s][t] = v
   437     for v in colors:
   437 
   438         colors[v] = ui.config('artemis', v, colors[v])
       
   439         if v.endswith('attrs'): colors[v] = colors[v].split()
       
   440     return colors
   438     return colors
   441 
   439 
   442 def _color_summary(line, msg, colors):
   440 def _color_summary(line, msg, colors):
   443     if msg['State'] == 'new':
   441     s = msg['State']
   444         return colored(line, colors['new.color'],      attrs = colors['new.attrs'])
   442     for alias, l in state.items():
   445     elif msg['State'] in state['fixed']:
   443         if s in l: s = alias; break
   446         return colored(line, colors['resolved.color'], attrs = colors['resolved.attrs'])
   444     if s in colors:
       
   445         color    = colors[s]['color']         if 'color'    in colors[s] else None
       
   446         on_color = colors[s]['on_color']      if 'on_color' in colors[s] else None
       
   447         attrs    = colors[s]['attrs'].split() if 'attrs'    in colors[s] else None
       
   448         return colored(line, color, on_color, attrs)
   447     else:
   449     else:
   448         return line
   450         return line
   449 
   451 
   450 def _summary_line(mbox, root, issue, colors):
   452 def _summary_line(mbox, root, issue, colors):
   451     line = "%s (%3d) [%s]: %s\n" % (issue,
   453     line = "%s (%3d) [%s]: %s\n" % (issue,