[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r9827 - trunk/gnue-common/src/setup
From: |
johannes |
Subject: |
[gnue] r9827 - trunk/gnue-common/src/setup |
Date: |
Thu, 22 Nov 2007 04:00:11 -0600 (CST) |
Author: johannes
Date: 2007-11-22 04:00:10 -0600 (Thu, 22 Nov 2007)
New Revision: 9827
Modified:
trunk/gnue-common/src/setup/ChangeLog.py
Log:
PEP8
Modified: trunk/gnue-common/src/setup/ChangeLog.py
===================================================================
--- trunk/gnue-common/src/setup/ChangeLog.py 2007-11-22 08:48:49 UTC (rev
9826)
+++ trunk/gnue-common/src/setup/ChangeLog.py 2007-11-22 10:00:10 UTC (rev
9827)
@@ -20,125 +20,194 @@
# Copyright 2001-2007 Free Software Foundation
#
# $Id$
+"""
+Build a ChangeLog file based on the log information from subversion
+"""
-SVNCMD='svn log -v --xml'
-
import xml.parsers.expat
-import tempfile, os, sys, string
+import tempfile
+import os
+import sys
-# -----------------------------------------------------------------------------
+
+__all__ = ['Parser', 'build']
+
+SVNCMD = 'svn log -v --xml'
+
+# =============================================================================
# The Parser
-# -----------------------------------------------------------------------------
+# =============================================================================
class Parser:
- def __init__ (self, input, output):
+ """
+ An EXPAT parser for the XML log information from SubVersion.
+ """
- self.out = output
- self.package = os.path.basename (os.getcwd ())
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
- p = xml.parsers.expat.ParserCreate ()
+ def __init__(self, infile, outfile):
- p.StartElementHandler = self.start_element
- p.EndElementHandler = self.end_element
- p.CharacterDataHandler = self.char_data
+ self.out = outfile
+ self.package = os.path.basename(os.getcwd())
- p.ParseFile (input)
+ parser = xml.parsers.expat.ParserCreate()
+ parser.StartElementHandler = self.start_element
+ parser.EndElementHandler = self.end_element
+ parser.CharacterDataHandler = self.char_data
+
self.paths = []
self.revision = ''
+ self.date = ''
+ self.author = ''
+ self.text = ''
- # 3 handler functions
- def start_element (self, name, attrs):
+ parser.ParseFile(infile)
+
+
+ # -------------------------------------------------------------------------
+ # Start of an XML element
+ # -------------------------------------------------------------------------
+
+ def start_element(self, name, attrs):
+ """
+ Called for the start of every element.
+
+ @param name: Name of the element started
+ @type name: string
+ @param attrs: a dictionary mapping attribute names to their values
+ @type attrs: dictionary
+ """
+
self.text = ''
+
if name == 'logentry':
- self.revision = string.ljust (attrs ['revision'], 5)
+ self.revision = attrs['revision'].ljust(5)
+
elif name == 'paths':
self.paths = []
- def end_element (self, name):
+
+ # -------------------------------------------------------------------------
+ # End of an XML element
+ # -------------------------------------------------------------------------
+
+ def end_element(self, name):
+ """
+ Called for the end of every element
+
+ @param name: name of the element ended
+ @type name: string
+ """
+
if name == 'logentry':
- self.out.write ('\n')
+ self.out.write('\n')
+
elif name == 'author':
self.author = self.text
+
elif name == 'path':
- p = string.split (self.text, '/', 3)
- if len (p) == 4:
- if p [2] == self.package:
- self.paths.append (p [3])
+ parts = self.text.split('/', 3)
+ if len(parts) == 4:
+ if parts[2] == self.package:
+ self.paths.append(parts[3])
+
elif name == 'msg':
- self.out.write ('%s Rev %s %s\n\n' % \
+ self.out.write('%s Rev %s %s\n\n' % \
(self.date, self.revision, self.author))
- text = '%s: %s' % (string.join (self.paths, ', '), self.text)
- self.out.write ('\t* %s' % linewrap (text))
+ text = '%s: %s' % (', '.join(self.paths), self.text)
+ self.out.write('\t* %s' % linewrap(text))
+
elif name == 'date':
self.date = self.text[:10] + ' ' + self.text[11:19]
+
+ # -------------------------------------------------------------------------
+ # Contents of an XML element
+ # -------------------------------------------------------------------------
+
def char_data(self, data):
+ """
+ Called for character data including normal character data, CDATA marked
+ content and ignorable whitespace.
+
+ @param data: the data being processed
+ @type data: string
+ """
self.text += data.encode('ascii','replace')
+
# -----------------------------------------------------------------------------
# Helper function to wrap long lines
# -----------------------------------------------------------------------------
-def linewrap (message, maxWidth=69, indent = '\t '):
+def linewrap(message, max_width=69, indent = '\t '):
+ """
+ Fold the given message so it fits into a ChangeLog entry
+ @param message: the message to be folded
+ @param max_width: the maximum width of a line
+ @param indent: the indentation of each line
+
+ @returns: folded message
+ """
+
text = ''
- temptext = string.strip (str (message))
- temptext = temptext.replace ('\n\n', '\r')
- temptext = temptext.replace ('\n', ' ')
+ temptext = str(message).strip()
+ temptext = temptext.replace('\n\n', '\r')
+ temptext = temptext.replace('\n', ' ')
- buff = string.split (temptext, '\r')
+ buff = temptext.split('\r')
for strings in buff:
- while len (strings) > maxWidth:
+ while len(strings) > max_width:
- index = string.rfind (strings, ' ', 0, maxWidth)
+ index = strings.rfind(' ', 0, max_width)
if index > 0:
- line = strings [:index]
+ line = strings[:index]
else:
- line = strings [:maxWidth]
- index = maxWidth - 1
+ line = strings[:max_width]
+ index = max_width - 1
if text != '':
text += indent
text += '%s\n' % line
- strings = strings [index+1:]
- strings = strings.strip ()
+ strings = strings[index+1:]
+ strings = strings.strip()
line = strings
if text != '':
text += indent
text += '%s\n' % line
- first = 0
+
return text
+
# -----------------------------------------------------------------------------
# Build the ChangeLog file
# -----------------------------------------------------------------------------
-def build ():
- filename = tempfile.mktemp ('xml')
- if os.system (SVNCMD + '> %s' % filename):
+def build():
+ """
+ Create the ChangeLog file
+ """
+ filename = tempfile.mktemp('xml')
+ if os.system(SVNCMD + '> %s' % filename):
print 'Unable to retrieve svn log'
- sys.exit (1)
+ sys.exit(1)
- inp = open (filename)
- out = open ('ChangeLog' ,'w')
+ inp = open(filename)
+ out = open('ChangeLog' ,'w')
try:
- Parser (inp, out)
- except:
- try:
- inp.close ()
- out.close ()
- os.unlink (filename)
- except:
- pass
- raise
+ Parser(inp, out)
- # Clean up input/output files
- inp.close ()
- out.close ()
- os.unlink (filename)
+ finally:
+ inp.close()
+ out.close()
+
+ os.unlink(filename)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r9827 - trunk/gnue-common/src/setup,
johannes <=