artemis.py
changeset 1 0bbf290d6f07
parent 0 c1b34481e50a
child 2 9e804a85c82c
equal deleted inserted replaced
0:c1b34481e50a 1:0bbf290d6f07
     1 #!/usr/bin/env python
     1 #!/usr/bin/env python
     2 
     2 
     3 from mercurial import hg
     3 from mercurial import hg
     4 from mercurial.i18n import _
     4 from mercurial.i18n import _
       
     5 import os, time, random
     5 
     6 
     6 def issues(ui, repo, **opts):
     7 def list(ui, repo, **opts):
     7 	"""Keep track of issues associated with the project"""
     8 	"""List issues associated with the project"""
     8 	if opts['list']:
     9 
     9 		print "listing issues"
    10 def add(ui, repo):
    10 	elif opts['add']:
    11 	"""Adds a new issue"""
    11 		print "adding issue"
    12 	
    12 	elif opts['show']:
    13 	# First, make sure issues have a directory
    13 		print "showing issue"
    14 	issues_path = os.path.join(repo.root, '.issues')
    14 	elif opts['reply']:
    15 	if not os.path.exists(issues_path): os.mkdir(issues_path)
    15 		print "replying to issue"
    16 	
       
    17 	user = ui.username()
       
    18 
       
    19 	default_issue_text = 	"From: %s\nDate: %s\n" % (user,
       
    20 													  time.strftime('%a, %d %b %Y %H:%M:%S %Z'))
       
    21 	default_issue_text += 	"Status: new\nSubject: brief description\n\n"
       
    22 	default_issue_text += 	"Detailed description."
       
    23 
       
    24 	issue = ui.edit(default_issue_text, user)
       
    25 	if issue.strip() == '':
       
    26 		ui.warn('Empty issue, ignoring\n')
       
    27 		return
       
    28 	if issue.strip() == default_issue_text:
       
    29 		ui.warn('Unchanged issue text, ignoring\n')
       
    30 		return
       
    31 
       
    32 	# Pick random filename
       
    33 	issue_fn = issues_path
       
    34 	while os.path.exists(issue_fn):
       
    35 		issue_fn = os.path.join(issues_path, "%x" % random.randint(2**32, 2**64-1))
       
    36 
       
    37 	# FIXME: replace with creating a mailbox
       
    38 	f =	file(issue_fn, "w")
       
    39 	f.write(issue)
       
    40 	f.close()
       
    41 
       
    42 	repo.add([issue_fn[(len(repo.root)+1):]])			# +1 for the trailing /
       
    43 
       
    44 def show(ui, repo, id):
       
    45 	"""Shows issue ID"""
    16 
    46 
    17 cmdtable = {
    47 cmdtable = {
    18 	'issues':	(issues,
    48 	'issues-list':	(list, 
    19 				 [('l', 'list', 	None, 	'list issues'),
    49 					 [('s', 'status', None, 'restrict status')], 
    20 				  ('a', 'add', 		None, 	'add issue'),
    50 					 _('hg issues-list')),
    21 				  ('s', 'show', 	None, 	'show issue'),
    51 	'issues-add':   (add,  
    22 				  ('r', 'reply', 	None,	'reply to issue')],
    52 					 [], 
    23 				 _('hg issues [OPTIONS]'))
    53 					 _('hg issues-add')),
       
    54 	'issues-show':  (show, 
       
    55 					 [], 
       
    56 					 _('hg issues-show ID'))
    24 }
    57 }