12 from email.mime.base import MIMEBase |
12 from email.mime.base import MIMEBase |
13 from email.mime.image import MIMEImage |
13 from email.mime.image import MIMEImage |
14 from email.mime.multipart import MIMEMultipart |
14 from email.mime.multipart import MIMEMultipart |
15 from email.mime.text import MIMEText |
15 from email.mime.text import MIMEText |
16 |
16 |
|
17 from termcolor import colored |
|
18 |
17 |
19 |
18 state = {'new': 'new', 'fixed': ['fixed', 'resolved']} |
20 state = {'new': 'new', 'fixed': ['fixed', 'resolved']} |
19 state['default'] = state['new'] |
21 state['default'] = state['new'] |
20 default_issues_dir = ".issues" |
22 default_issues_dir = ".issues" |
21 filter_prefix = ".filter" |
23 filter_prefix = ".filter" |
34 match_date, date_match = True, util.matchdate(opts['date']) |
36 match_date, date_match = True, util.matchdate(opts['date']) |
35 order = 'new' |
37 order = 'new' |
36 if opts['order']: |
38 if opts['order']: |
37 order = opts['order'] |
39 order = opts['order'] |
38 |
40 |
|
41 # Colors |
|
42 colors = _read_colors(ui) |
39 |
43 |
40 # Find issues |
44 # Find issues |
41 issues_dir = ui.config('artemis', 'issues', default = default_issues_dir) |
45 issues_dir = ui.config('artemis', 'issues', default = default_issues_dir) |
42 issues_path = os.path.join(repo.root, issues_dir) |
46 issues_path = os.path.join(repo.root, issues_dir) |
43 if not os.path.exists(issues_path): return |
47 if not os.path.exists(issues_path): return |
59 cmd_properties = _get_properties(opts['property']) |
63 cmd_properties = _get_properties(opts['property']) |
60 list_properties = [p[0] for p in cmd_properties if len(p) == 1] |
64 list_properties = [p[0] for p in cmd_properties if len(p) == 1] |
61 list_properties_dict = {} |
65 list_properties_dict = {} |
62 properties += filter(lambda p: len(p) > 1, cmd_properties) |
66 properties += filter(lambda p: len(p) > 1, cmd_properties) |
63 |
67 |
64 subjects = [] |
68 summaries = [] |
65 for issue in issues: |
69 for issue in issues: |
66 mbox = mailbox.Maildir(issue, factory=mailbox.MaildirMessage) |
70 mbox = mailbox.Maildir(issue, factory=mailbox.MaildirMessage) |
67 root = _find_root_key(mbox) |
71 root = _find_root_key(mbox) |
68 if not root: continue |
72 if not root: continue |
69 property_match = True |
73 property_match = True |
75 |
79 |
76 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 |
80 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 |
77 if match_date and not date_match(util.parsedate(mbox[root]['date'])[0]): continue |
81 if match_date and not date_match(util.parsedate(mbox[root]['date'])[0]): continue |
78 |
82 |
79 if not list_properties: |
83 if not list_properties: |
80 subjects.append(("%s (%3d) [%s]: %s\n" % (issue[len(issues_path)+1:], # +1 for trailing / |
84 summaries.append((_summary_line(mbox, root, issue[len(issues_path)+1:], colors), # +1 for trailing / |
81 len(mbox)-1, # number of replies (-1 for self) |
85 _find_mbox_date(mbox, root, order))) |
82 _status_msg(mbox[root]), |
|
83 mbox[root]['Subject']), |
|
84 _find_mbox_date(mbox, root, order))) |
|
85 else: |
86 else: |
86 for lp in list_properties: |
87 for lp in list_properties: |
87 if lp in mbox[root]: list_properties_dict.setdefault(lp, set()).add(mbox[root][lp]) |
88 if lp in mbox[root]: list_properties_dict.setdefault(lp, set()).add(mbox[root][lp]) |
88 |
89 |
89 if not list_properties: |
90 if not list_properties: |
90 subjects.sort(lambda (s1,d1),(s2,d2): cmp(d2,d1)) |
91 summaries.sort(lambda (s1,d1),(s2,d2): cmp(d2,d1)) |
91 for s,d in subjects: |
92 for s,d in summaries: |
92 ui.write(s) |
93 ui.write(s) |
93 else: |
94 else: |
94 for lp in list_properties_dict.keys(): |
95 for lp in list_properties_dict.keys(): |
95 ui.write("%s:\n" % lp) |
96 ui.write("%s:\n" % lp) |
96 for value in sorted(list_properties_dict[lp]): |
97 for value in sorted(list_properties_dict[lp]): |
419 if msg['State'] == 'resolved': |
420 if msg['State'] == 'resolved': |
420 return 'resolved=' + msg['resolution'] |
421 return 'resolved=' + msg['resolution'] |
421 else: |
422 else: |
422 return msg['State'] |
423 return msg['State'] |
423 |
424 |
|
425 def _read_colors(ui): |
|
426 colors = {} |
|
427 # defaults |
|
428 colors['new.color'] = 'red' |
|
429 colors['new.on_color'] = 'on_grey' |
|
430 colors['new.attrs'] = 'bold' |
|
431 colors['resolved.color'] = 'white' |
|
432 colors['resolved.on_color'] = '' |
|
433 colors['resolved.attrs'] = '' |
|
434 for v in colors: |
|
435 colors[v] = ui.config('artemis', v, colors[v]) |
|
436 if v.endswith('attrs'): colors[v] = colors[v].split() |
|
437 return colors |
|
438 |
|
439 def _color_summary(line, msg, colors): |
|
440 if msg['State'] == 'new': |
|
441 return colored(line, colors['new.color'], attrs = colors['new.attrs']) |
|
442 elif msg['State'] in state['fixed']: |
|
443 return colored(line, colors['resolved.color'], attrs = colors['resolved.attrs']) |
|
444 else: |
|
445 return line |
|
446 |
|
447 def _summary_line(mbox, root, issue, colors): |
|
448 line = "%s (%3d) [%s]: %s\n" % (issue, |
|
449 len(mbox)-1, # number of replies (-1 for self) |
|
450 _status_msg(mbox[root]), |
|
451 mbox[root]['Subject']) |
|
452 return _color_summary(line, mbox[root], colors) |
|
453 |
424 cmdtable = { |
454 cmdtable = { |
425 'ilist': (ilist, |
455 'ilist': (ilist, |
426 [('a', 'all', False, |
456 [('a', 'all', False, |
427 'list all issues (by default only those with state new)'), |
457 'list all issues (by default only those with state new)'), |
428 ('p', 'property', [], |
458 ('p', 'property', [], |