artemis.py
changeset 7 74cbd53bf7d8
parent 6 11cab5930258
child 8 b1f268a9e4ed
equal deleted inserted replaced
6:11cab5930258 7:74cbd53bf7d8
     2 
     2 
     3 """A very simple and lightweight issue tracker for Mercurial."""
     3 """A very simple and lightweight issue tracker for Mercurial."""
     4 
     4 
     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, ConfigParser
     8 
     8 
     9 
     9 
    10 state = {'new': 'new', 'fixed': 'fixed'}
    10 state = {'new': 'new', 'fixed': 'fixed'}
    11 state['default'] = state['new']
    11 state['default'] = state['new']
    12 issues_dir = ".issues"
    12 issues_dir = ".issues"
    13 filter_filename = ".filters"
    13 filter_prefix = ".filter"
    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 ilist(ui, repo, **opts):
    17 def ilist(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 = opts['all']
    21 	show_all = opts['all']
    22 	properties = _get_properties(opts['property'])
    22 	properties = []
    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
    28 	issues_path = os.path.join(repo.root, issues_dir)
    28 	issues_path = os.path.join(repo.root, issues_dir)
    29 	if not os.path.exists(issues_path): return
    29 	if not os.path.exists(issues_path): return
    30 
    30 
    31 	issues = glob.glob(os.path.join(issues_path, '*'))
    31 	issues = glob.glob(os.path.join(issues_path, '*'))
       
    32 	
       
    33 	# Process filter
       
    34 	if opts['filter']:
       
    35 		filters = glob.glob(os.path.join(issues_path, filter_prefix + '*'))
       
    36 		config = ConfigParser.SafeConfigParser()
       
    37 		config.read(filters)
       
    38 		if not config.has_section(opts['filter']): 
       
    39 			ui.warning('No filter %s defined\n', opts['filter'])
       
    40 		else:
       
    41 			properties += config.items(opts['filter'])
       
    42 	
       
    43 	_get_properties(opts['property'])
    32 	
    44 	
    33 	for issue in issues:
    45 	for issue in issues:
    34 		mbox = mailbox.mbox(issue)
    46 		mbox = mailbox.mbox(issue)
    35 		property_match = True
    47 		property_match = True
    36 		for property,value in properties: 
    48 		for property,value in properties: 
   236 				 [('a', 'all', False, 
   248 				 [('a', 'all', False, 
   237 				   'list all issues (by default only those with state new)'),
   249 				   'list all issues (by default only those with state new)'),
   238 				  ('p', 'property', [], 
   250 				  ('p', 'property', [], 
   239 				   'list issues with specific field values (e.g., -p state=fixed)'),
   251 				   'list issues with specific field values (e.g., -p state=fixed)'),
   240 				  ('d', 'date', '', 'restrict to issues matching the date (e.g., -d ">12/28/2007)"'),
   252 				  ('d', 'date', '', 'restrict to issues matching the date (e.g., -d ">12/28/2007)"'),
   241 				  ('f', 'filter', '', 'restrict to pre-defined filter (in %s/%s)' % (issues_dir, filter_filename))], 
   253 				  ('f', 'filter', '', 'restrict to pre-defined filter (in %s/%s*)' % (issues_dir, filter_prefix))], 
   242 				 _('hg ilist [OPTIONS]')),
   254 				 _('hg ilist [OPTIONS]')),
   243 	'iadd':   	(iadd,  
   255 	'iadd':   	(iadd,  
   244 				 [], 
   256 				 [], 
   245 				 _('hg iadd [ID] [COMMENT]')),
   257 				 _('hg iadd [ID] [COMMENT]')),
   246 	'ishow':  	(ishow, 
   258 	'ishow':  	(ishow,