artemis.py
changeset 5 cef66aa31468
parent 4 bf71e2069dbd
child 6 11cab5930258
equal deleted inserted replaced
4:bf71e2069dbd 5:cef66aa31468
     5 from mercurial import hg, util
     5 from mercurial import hg, util
     6 from mercurial.i18n import _
     6 from mercurial.i18n import _
     7 import os, time, random, mailbox, glob, socket
     7 import os, time, random, mailbox, glob, socket
     8 
     8 
     9 
     9 
    10 new_state = "new"
    10 state = {'new': 'new', 'fixed': 'fixed'}
    11 default_state = new_state
    11 state['default'] = state['new']
    12 issues_dir = ".issues"
    12 issues_dir = ".issues"
    13 filter_filename = ".filters"
    13 filter_filename = ".filters"
    14 date_format = '%a, %d %b %Y %H:%M:%S %Z'
    14 date_format = '%a, %d %b %Y %H:%M:%S %Z'
    15 
    15 
    16 
    16 
    17 def list(ui, repo, **opts):
    17 def list(ui, repo, **opts):
    18 	"""List issues associated with the project"""
    18 	"""List issues associated with the project"""
    19 
    19 
    20 	# Process options
    20 	# Process options
    21 	show_all = False or opts['all']
    21 	show_all = opts['all']
    22 	properties = _get_properties(opts['property']) or [['state', new_state]]
    22 	properties = _get_properties(opts['property'])
    23 	date_match = lambda x: True
    23 	date_match = lambda x: True
    24 	if opts['date']: 
    24 	if opts['date']: 
    25 		date_match = util.matchdate(opts['date'])
    25 		date_match = util.matchdate(opts['date'])
    26 
    26 
    27 	# Find issues
    27 	# Find issues
    33 	for issue in issues:
    33 	for issue in issues:
    34 		mbox = mailbox.mbox(issue)
    34 		mbox = mailbox.mbox(issue)
    35 		property_match = True
    35 		property_match = True
    36 		for property,value in properties: 
    36 		for property,value in properties: 
    37 			property_match = property_match and (mbox[0][property] == value)
    37 			property_match = property_match and (mbox[0][property] == value)
    38 		if not show_all and not property_match: continue
    38 		if not show_all and (not properties or not property_match) and (properties or mbox[0]['State'].upper() == state['fixed'].upper()): continue 
       
    39 
       
    40 
    39 		if not date_match(util.parsedate(mbox[0]['date'], [date_format])[0]): continue
    41 		if not date_match(util.parsedate(mbox[0]['date'], [date_format])[0]): continue
    40 		print "%s (%d) [%s]: %s" % (issue[len(issues_path)+1:], # +1 for trailing /
    42 		ui.write("%s (%d) [%s]: %s\n" % (issue[len(issues_path)+1:], # +1 for trailing /
    41 									len(mbox)-1,				# number of replies (-1 for self)
    43 										 len(mbox)-1,				 # number of replies (-1 for self)
    42 									mbox[0]['State'],
    44 										 mbox[0]['State'],
    43 									mbox[0]['Subject'])
    45 										 mbox[0]['Subject']))
    44 	
    46 	
    45 
    47 
    46 def add(ui, repo, id = None, comment = 0):
    48 def add(ui, repo, id = None, comment = 0):
    47 	"""Adds a new issue, or comment to an existing issue ID or its comment COMMENT"""
    49 	"""Adds a new issue, or comment to an existing issue ID or its comment COMMENT"""
    48 	
    50 	
    60 	
    62 	
    61 	user = ui.username()
    63 	user = ui.username()
    62 
    64 
    63 	default_issue_text  = 		"From: %s\nDate: %s\n" % (user, time.strftime(date_format))
    65 	default_issue_text  = 		"From: %s\nDate: %s\n" % (user, time.strftime(date_format))
    64 	if not id: 
    66 	if not id: 
    65 		default_issue_text += 	"State: %s\n" % default_state
    67 		default_issue_text += 	"State: %s\n" % state['default']
    66 	default_issue_text +=		"Subject: brief description\n\n"
    68 	default_issue_text +=		"Subject: brief description\n\n"
    67 	default_issue_text += 		"Detailed description."
    69 	default_issue_text += 		"Detailed description."
    68 
    70 
    69 	issue = ui.edit(default_issue_text, user)
    71 	issue = ui.edit(default_issue_text, user)
    70 	if issue.strip() == '':
    72 	if issue.strip() == '':
   222 	ui.write('-'*70 + '\n')
   224 	ui.write('-'*70 + '\n')
   223 
   225 
   224 
   226 
   225 cmdtable = {
   227 cmdtable = {
   226 	'ilist':	(list, 
   228 	'ilist':	(list, 
   227 				 [('a', 'all', None, 
   229 				 [('a', 'all', False, 
   228 				   'list all issues (by default only those with state new)'),
   230 				   'list all issues (by default only those with state new)'),
   229 				  ('p', 'property', [], 
   231 				  ('p', 'property', [], 
   230 				   'list issues with specific field values (e.g., -p state=fixed)'),
   232 				   'list issues with specific field values (e.g., -p state=fixed)'),
   231 				  ('d', 'date', '', 'restrict to issues matching the date (e.g., -d ">12/28/2007)"'),
   233 				  ('d', 'date', '', 'restrict to issues matching the date (e.g., -d ">12/28/2007)"'),
   232 				  ('f', 'filter', '', 'restrict to pre-defined filter (in %s/%s)' % (issues_dir, filter_filename))], 
   234 				  ('f', 'filter', '', 'restrict to pre-defined filter (in %s/%s)' % (issues_dir, filter_filename))],