diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-08-27 19:57:34 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-08-27 20:01:19 +0300 |
commit | a5bde557e0f8848983c7b5151615571483f76cec (patch) | |
tree | 3e5b8d3ead41c78462901af1c945234e8ca0118a | |
parent | 2e6def2e969656e496a82c6d041a7b52d7f52086 (diff) | |
download | releaselogparser-a5bde557e0f8848983c7b5151615571483f76cec.tar.gz releaselogparser-a5bde557e0f8848983c7b5151615571483f76cec.tar.bz2 |
Housekeeping changes.
* .gitignore: New file.
* releaselog.py: Rename to bin/releaselog.
* releaselog/__init__.py (filename): New ReleaseLog class method.
* releaselog/format/__init__.py: Update.
* releaselog/format/cpan.py: Define the filename attribute.
* releaselog/format/gnu.py: Likewise.
* releaselog/format/python.py: Likewise.
* setup.py: New file.
-rw-r--r-- | .gitignore | 7 | ||||
-rwxr-xr-x[-rw-r--r--] | bin/releaselog (renamed from releaselog.py) | 0 | ||||
-rw-r--r-- | releaselog/__init__.py | 26 | ||||
-rw-r--r-- | releaselog/format/__init__.py | 8 | ||||
-rw-r--r-- | releaselog/format/cpan.py | 1 | ||||
-rw-r--r-- | releaselog/format/gnu.py | 1 | ||||
-rw-r--r-- | releaselog/format/python.py | 1 | ||||
-rw-r--r-- | setup.py | 48 |
8 files changed, 83 insertions, 9 deletions
@@ -1,4 +1,7 @@ *~ -.emacs* *.pyc -/tmp +.emacs.desktop +build/ +dist/ +tmp/ +*.egg-info/ diff --git a/releaselog.py b/bin/releaselog index c535a08..c535a08 100644..100755 --- a/releaselog.py +++ b/bin/releaselog diff --git a/releaselog/__init__.py b/releaselog/__init__.py index e4a04c5..015f796 100644 --- a/releaselog/__init__.py +++ b/releaselog/__init__.py @@ -36,19 +36,26 @@ class Release(object): return "Version %s, released at %s" % (self.version, self.date) class ReleaseHistory(object): """ReleaseHistory - base class for ReleaseLog implementations - Attributes: + Class Attributes: + + format - array of names for this format + filename - name of the file normally used to keep the log file - history - a list of Release objects header - a compiled regular expression that returns a match for history entry heading lines end_of_entry_rx - a compiled regular expression returning a match for end of entry. Can be None + + Instance Attributes: + + history - a list of Release objects. Normally not needed, since + it is accessed by indexing the object. """ history = [] end_of_entry_rx = re.compile('^(\f|^\s*=+\s*$)') @@ -60,16 +67,16 @@ class ReleaseHistory(object): def append(self, arg): """Appends new release to the end of release history list""" if isinstance(arg, Release): self.history.append(arg) else: - raise TypeError() + raise TypeError('argument to append must be a Release') def parse_header(self, line): - """Matche input line against the history header regexp. On match, + """Match input line against the history header regexp. On match, return a tuple (date, version, startdescr), where date is the release date (datetime), version is the release version number, and startdescr is the first line of the description or None. On failure, return (None, None, None). """ date = None @@ -118,12 +125,14 @@ class ReleaseHistory(object): is computed as [start, min(start+count, stop)] Entries are numbered from 0. """ + self.history = [] + date = None version = None descr = [] start = None stop = None @@ -133,13 +142,13 @@ class ReleaseHistory(object): start = val elif kw == 'stop': stop = val elif kw == 'count': count = val else: - raise TypeError() # FIXME + raise KeyError ('keyword %s is not known' % kw) if count: if start: if not (stop and stop < start + count): stop = start + count elif stop: @@ -244,13 +253,18 @@ class ReleaseLog(object): rev = {} for fmt in cls.formatdb: if cls.formatdb[fmt] not in rev: rev[cls.formatdb[fmt]] = [] rev[cls.formatdb[fmt]].append(fmt) return rev.values() - + + @classmethod + def filename(cls, name): + """Returns the accepted log file name for the given format.""" + return cls.formatdb[name].filename + # Initialize the ReleaseLog implementations import pkgutil import importlib for (loader, name, ispkg) in pkgutil.iter_modules([dir for dir in diff --git a/releaselog/format/__init__.py b/releaselog/format/__init__.py index 67d9bac..a5e8ea0 100644 --- a/releaselog/format/__init__.py +++ b/releaselog/format/__init__.py @@ -2,14 +2,20 @@ Release History Format implementations To implement a new format, drop into this directory a python source defining a subclass of ReleaseHistory with the new implementation. The name for the new format must be defined in the 'format' subclass attribute. This attribute can be either a string or a list of strings. Use the latter form to define -aliases. For example +aliases. + +The name of the file normally used to keep release history in this format +must be stored in the 'filename' attribute. + +For example class NewHistoryFormat(ReleaseHistory): format = 'newformat' + filename = 'HISTORY.txt' ... See the ReleaseHistory documentation for details. """ diff --git a/releaselog/format/cpan.py b/releaselog/format/cpan.py index deec1f7..d6ffb78 100644 --- a/releaselog/format/cpan.py +++ b/releaselog/format/cpan.py @@ -13,8 +13,9 @@ the releaselog module. import re from releaselog import ReleaseHistory class ReleaseLogFormat(ReleaseHistory): format = ['CPAN', 'Changes'] + filename = 'Changes' header = re.compile('^(?P<version>\d[\d.]*)\s+(?P<date>.+?)\s*$') diff --git a/releaselog/format/gnu.py b/releaselog/format/gnu.py index 1b5894b..503a7de 100644 --- a/releaselog/format/gnu.py +++ b/releaselog/format/gnu.py @@ -13,11 +13,12 @@ the releaselog module. import re from releaselog import ReleaseHistory class ReleaseLogFormat(ReleaseHistory): format = ['GNU', 'NEWS'] + filename = 'NEWS' header = re.compile(r"""^(?:\*\s+)? # optional initial section (?:(?i)version)\s+ (?P<version>\d(?:[.,]\d+){1,2} # At least MAJOR.MINOR (?:[\d._-])*) # Optional patchlevel (?:.*[-,:]\s+(?P<date>.+))""", re.X) diff --git a/releaselog/format/python.py b/releaselog/format/python.py index bdcdea6..cd742cc 100644 --- a/releaselog/format/python.py +++ b/releaselog/format/python.py @@ -25,12 +25,13 @@ input line that matches any of the above patterns. import re from releaselog import ReleaseHistory class PythonLogFormat(ReleaseHistory): format = ['Python', 'python'] + filename = 'CHANGES.txt' header = None header_rx = [ re.compile("""^[vV](?P<version>\d[\d.]*)\s* ,\s* (?P<date>.*?) \s+-+\s* diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..9844af3 --- /dev/null +++ b/setup.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2008-2018 Sergey Poznyakoff +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +from setuptools import setup, find_packages +from codecs import open + +#with open("README.rst", "r") as fh: +# long_description = fh.read() + +setup(name='releaselog', + version='0.2', + author='Sergey Poznyakoff', + author_email='gray@gnu.org', + url='http://git.gnu.org.ua/cgit/gsc/releaselog.git/', + packages = find_packages(exclude=['contrib', 'docs', + 'tests', 'testdata']), + scripts=['bin/releaselog'], + license='GPL License', + description='Release log parser.', +# long_description=long_description, +# long_description_content_type="text/x-rst", + platforms=['any'], + # test_suite='tests', + classifiers=[ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: GNU General Public License (GPL)', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Topic :: Software Development :: Libraries :: Python Modules', + 'Topic :: Text Processing :: General' + ], + keywords = 'release log history changes news', +) |