SF.net SVN: gar:[23465] csw/mgar/gar/v2/bin/cswch
guengel at users.sourceforge.net
guengel at users.sourceforge.net
Tue Apr 22 12:19:49 CEST 2014
Revision: 23465
http://sourceforge.net/p/gar/code/23465
Author: guengel
Date: 2014-04-22 10:19:47 +0000 (Tue, 22 Apr 2014)
Log Message:
-----------
bin/cswch: added 'version' command, which extracts the latest version from changelog.CSW. Started working on ChangeLogEntry class.
Modified Paths:
--------------
csw/mgar/gar/v2/bin/cswch
Modified: csw/mgar/gar/v2/bin/cswch
===================================================================
--- csw/mgar/gar/v2/bin/cswch 2014-04-22 09:39:49 UTC (rev 23464)
+++ csw/mgar/gar/v2/bin/cswch 2014-04-22 10:19:47 UTC (rev 23465)
@@ -1,8 +1,21 @@
#!/usr/bin/env python
-"""
-Maintain OpenCSW changelog
+"""Maintain OpenCSW changelog.
+The changelog files generated are modeled after the Debian changelog
+
+ http://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog
+
+except that the header line for each entry is somewhat
+simplyfied. Instead of using
+
+ package (version) distribution(s); urgency=urgency
+
+it uses
+
+ package (version,REV=revision)
+
$Id$
+
"""
import argparse
import datetime
@@ -290,7 +303,7 @@
:param dt: datetime object or none, in which case the current time
will be taken.
-
+
"""
if date_obj is None:
timezone = dateutil.tz.tzlocal()
@@ -381,6 +394,67 @@
whitespace_re = r'\s{2,}|\n+'
whitespace_re_c = re.compile(whitespace_re)
+
+class ChangeLogEntry(object):
+ """A ChangeLogEntry
+
+ A ChangeLogEntry is comprised of a ChangeLogHeader,
+ ChangeLogFooter, and one or more ChangeLogParagraph's.
+
+ """
+
+ def __init__(self):
+ self.paragaphs = list()
+
+ def add_header(self, cl_header):
+ """Add a ChangeLog Entry header.
+
+ Add or replace the ChangeLog Entry header.
+
+ """
+ assert cl_header is not None
+ self.header = cl_header
+
+ def add_footer(self, cl_footer):
+ """Add a ChangeLog Entry footer.
+
+ Add or replace the ChangeLog Entry footer.
+
+ """
+ assert cl_footer is not None
+ self.footer = cl_footer
+
+ def add_paragraph(self, cl_paragraph, infront=True):
+ """Add a ChangeLog Entry paragraph.
+
+ Add another ChangeLog Entry paragraph.
+
+ If :param infront: is True, the paragraph will be prepended to
+ the paragraph list. Else it will be appended.
+
+ """
+ assert cl_paragraph is not None
+
+ if infront:
+ self.paragraphs.insert(0, cl_pargraph)
+ else:
+ self.paragraphs.append(cl_paragraph)
+
+ def remove_paragraph(self, index):
+ """Remove a ChangeLog paragraph
+
+ Remove a ChangeLog paragraph from the list of paragraphs. The
+ removed paragraph will be returned to the caller.
+
+ """
+ chlogp = self.paragraphs[index]
+ del self.paragraphs[index]
+ return chlogp
+
+ def __str__(self):
+ pass
+
+
def slurpin_changelog(filename):
"""Load existing changelog"""
@@ -401,7 +475,7 @@
if entry_start_re.match(line):
entry_dict = {'header': ChangeLogHeader(line=line)}
continue
-
+
# is it the footer, and thus marks the end of a entry?
if line.startswith(' -- '):
# is there a paragraph pending?
@@ -418,7 +492,7 @@
# append to the list
changelog_entries.append(entry_dict)
continue
-
+
# is it the start of an entry paragraph?
if line.startswith(' * '):
# is the first item of the paragraph list a paragraph
@@ -492,6 +566,17 @@
fobj.write(str(chlg_footer))
fobj.write('\n\n')
+
+def get_version(logfile, allversions):
+ chlg_entries = slurpin_changelog(logfile)
+
+ if allversions:
+ for entry in chlg_entries:
+ print entry['header'].version
+ else:
+ print chlg_entries[0]['header'].version
+
+
def cmdline_parse():
"""Parse the command line
@@ -526,6 +611,13 @@
help="the log entry",
nargs='+')
+ parser_version = subparser.add_parser('version',
+ help="retrieve version from changelog.CSW")
+ parser_version.add_argument('--all-versions',
+ help="retrieve all versions",
+ default=False, action='store_const',
+ const=True)
+
parser_test = subparser.add_parser('test', help="test cswch")
return parser.parse_args()
@@ -551,3 +643,6 @@
new_changelog_entry(cmdline.logfile,
cmdline.version,
cmdline.log)
+
+ if cmdline.command == "version":
+ get_version(cmdline.logfile, cmdline.all_versions)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the devel
mailing list