Package conary :: Module changelog
[hide private]
[frames] | no frames]

Source Code for Module conary.changelog

  1  # 
  2  # Copyright (c) 2004-2008 rPath, Inc. 
  3  # 
  4  # This program is distributed under the terms of the Common Public License, 
  5  # version 1.0. A copy of this license should have been distributed with this 
  6  # source file in a file called LICENSE. If it is not present, the license 
  7  # is always available at http://www.rpath.com/permanent/licenses/CPL-1.0. 
  8  # 
  9  # This program is distributed in the hope that it will be useful, but 
 10  # without any warranty; without even the implied warranty of merchantability 
 11  # or fitness for a particular purpose. See the Common Public License for 
 12  # full details. 
 13  # 
 14  """ 
 15  Implements changelog entries for repository commits. 
 16  """ 
 17   
 18  import os 
 19  import sys 
 20  import string 
 21  import subprocess 
 22  import tempfile 
 23   
 24  from conary import streams 
 25   
 26  _CHANGELOG_NAME    = 1 
 27  _CHANGELOG_CONTACT = 2 
 28  _CHANGELOG_MESSAGE = 3 
 29   
 30  SMALL = streams.SMALL 
 31  LARGE = streams.LARGE 
 32   
33 -class ChangeLog(streams.StreamSet):
34 35 streamDict = { 36 _CHANGELOG_NAME : (SMALL, streams.StringStream, "name" ), 37 _CHANGELOG_CONTACT : (SMALL, streams.StringStream, "contact" ), 38 _CHANGELOG_MESSAGE : (SMALL, streams.StringStream, "message" ) 39 } 40 41 __slots__ = [ 'name', 'contact', 'message' ] 42
43 - def getName(self):
44 return self.name()
45
46 - def setName(self, value):
47 self.name.set(value)
48
49 - def getContact(self):
50 return self.contact()
51
52 - def setContact(self, value):
53 self.contact.set(value)
54
55 - def getMessage(self):
56 return self.message()
57
58 - def setMessage(self, value):
59 assert(not value or value[-1] == '\n') 60 self.message.set(value)
61
62 - def getMessageFromUser(self, prompt=''):
63 editor = os.environ.get("EDITOR", "/bin/vi") 64 (fd, name) = tempfile.mkstemp() 65 if not prompt: 66 prompt = 'Enter your change log message.' 67 msg = "\n-----\n%s\n" % prompt 68 os.write(fd, msg) 69 os.close(fd) 70 71 def _getMessageNoEditor(): 72 sys.stderr.write("Error executing %s. Please set the EDITOR\n" 73 "environment variable to a valid editor, or enter log message,\n" 74 "terminated with single '.' (or CTRL+D to cancel)\n" % editor) 75 rows = [] 76 while 1: 77 try: 78 row = raw_input('>> ') 79 except EOFError: 80 return None 81 if row == '.': 82 # We need a trailing newline 83 rows.append('') 84 break 85 rows.append(row) 86 return '\n'.join(rows)
87 88 class EditorError(Exception): 89 pass
90 91 cmdargs = [editor, name] 92 try: 93 try: 94 # Capture stderr and discard it 95 retcode = subprocess.call(" ".join(cmdargs), shell=True, 96 stderr=subprocess.PIPE) 97 except OSError, e: 98 raise EditorError 99 if retcode != 0: 100 raise EditorError 101 except EditorError: 102 # Error running the editor 103 msg = _getMessageNoEditor() 104 if msg is None: 105 return False 106 self.message.set(msg) 107 return True 108 109 newMsg = open(name).read() 110 os.unlink(name) 111 112 if newMsg == msg: 113 return False 114 115 if newMsg[-len(msg):]: 116 newMsg = newMsg[:-len(msg)] 117 118 newMsg = string.strip(newMsg) 119 newMsg += '\n' 120 self.setMessage(newMsg) 121 return True 122
123 - def __init__(self, name = None, contact = None, message = None):
124 if contact is None: 125 streams.StreamSet.