artemis.py
changeset 8 b1f268a9e4ed
parent 7 74cbd53bf7d8
child 11 8bf7b97035f1
equal deleted inserted replaced
7:74cbd53bf7d8 8:b1f268a9e4ed
    67 	if not os.path.exists(issues_path): os.mkdir(issues_path)
    67 	if not os.path.exists(issues_path): os.mkdir(issues_path)
    68 
    68 
    69 	if id:
    69 	if id:
    70 		issue_fn, issue_id = _find_issue(ui, repo, id)
    70 		issue_fn, issue_id = _find_issue(ui, repo, id)
    71 		if not issue_fn: 
    71 		if not issue_fn: 
    72 			ui.warn('No such issue')
    72 			ui.warn('No such issue\n')
    73 			return
    73 			return
    74 	
    74 	
    75 	user = ui.username()
    75 	user = ui.username()
    76 
    76 
    77 	default_issue_text  = 		"From: %s\nDate: %s\n" % (user, time.strftime(date_format))
    77 	default_issue_text  = 		"From: %s\nDate: %s\n" % (user, time.strftime(date_format))
    94 	
    94 	
    95 	# Pick random filename
    95 	# Pick random filename
    96 	if not id:
    96 	if not id:
    97 		issue_fn = issues_path
    97 		issue_fn = issues_path
    98 		while os.path.exists(issue_fn):
    98 		while os.path.exists(issue_fn):
    99 			issue_id = "%x" % random.randint(2**63, 2**64-1)
    99 			issue_id = _random_id() 
   100 			issue_fn = os.path.join(issues_path, issue_id)
   100 			issue_fn = os.path.join(issues_path, issue_id)
   101 	# else: issue_fn already set
   101 	# else: issue_fn already set
   102 
   102 
   103 	# Add message to the mailbox
   103 	# Add message to the mailbox
   104 	mbox = mailbox.mbox(issue_fn)
   104 	mbox = mailbox.mbox(issue_fn)
   105 	if id and comment not in mbox: 
   105 	if id and comment not in mbox: 
   106 		ui.warn('No such comment number in mailbox, commenting on the issue itself\n')
   106 		ui.warn('No such comment number in mailbox, commenting on the issue itself\n')
   107 	if not id:
   107 	if not id:
   108 		msg.add_header('Message-Id', "%s-0-artemis@%s" % (issue_id, socket.gethostname()))
   108 		msg.add_header('Message-Id', "<%s-0-artemis@%s>" % (issue_id, socket.gethostname()))
   109 	else:
   109 	else:
   110 		msg.add_header('Message-Id', "%s-%d-artemis@%s" % (issue_id, len(mbox), socket.gethostname()))
   110 		msg.add_header('Message-Id', "<%s-%s-artemis@%s>" % (issue_id, _random_id(), socket.gethostname()))
   111 		msg.add_header('References', mbox[(comment < len(mbox) and comment) or 0]['Message-Id'])
   111 		msg.add_header('References', mbox[(comment < len(mbox) and comment) or 0]['Message-Id'])
   112 	mbox.add(msg)
   112 	mbox.add(msg)
   113 	mbox.close()
   113 	mbox.close()
   114 
   114 
   115 	# If adding issue, add the new mailbox to the repository
   115 	# If adding issue, add the new mailbox to the repository
   161 		properties_text  = 	"From: %s\nDate: %s\nSubject: properties changes (%s)\n\n%s" % \
   161 		properties_text  = 	"From: %s\nDate: %s\nSubject: properties changes (%s)\n\n%s" % \
   162 							(user, time.strftime(date_format),
   162 							(user, time.strftime(date_format),
   163 							 _pretty_list(list(set([property for property, value in properties]))), 
   163 							 _pretty_list(list(set([property for property, value in properties]))), 
   164 							 properties_text)
   164 							 properties_text)
   165 		msg = mailbox.mboxMessage(properties_text)
   165 		msg = mailbox.mboxMessage(properties_text)
   166 		msg.add_header('Message-Id', "%s-%d-artemis@%s" % (id, len(mbox), socket.gethostname()))
   166 		msg.add_header('Message-Id', "<%s-%s-artemis@%s>" % (id, _random_id(), socket.gethostname()))
   167 		msg.add_header('References', mbox[0]['Message-Id'])
   167 		msg.add_header('References', mbox[0]['Message-Id'])
       
   168 		msg.set_from('artemis', True)
   168 		mbox.add(msg)
   169 		mbox.add(msg)
   169 	mbox.flush()
   170 	mbox.flush()
   170 
   171 
   171 	# Show updated message
   172 	# Show updated message
   172 	_show_mbox(ui, mbox, 0)
   173 	_show_mbox(ui, mbox, 0)
   239 def _pretty_list(lst):
   240 def _pretty_list(lst):
   240 	s = ''
   241 	s = ''
   241 	for i in lst:
   242 	for i in lst:
   242 		s += i + ', '
   243 		s += i + ', '
   243 	return s[:-2]
   244 	return s[:-2]
       
   245 
       
   246 def _random_id():
       
   247 	return "%x" % random.randint(2**63, 2**64-1)
   244 
   248 
   245 
   249 
   246 cmdtable = {
   250 cmdtable = {
   247 	'ilist':	(ilist, 
   251 	'ilist':	(ilist, 
   248 				 [('a', 'all', False, 
   252 				 [('a', 'all', False,