From a5bde557e0f8848983c7b5151615571483f76cec Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Mon, 27 Aug 2018 19:57:34 +0300 Subject: 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. --- .gitignore | 7 +++-- bin/releaselog | 66 +++++++++++++++++++++++++++++++++++++++++++ releaselog.py | 66 ------------------------------------------- releaselog/__init__.py | 26 +++++++++++++---- releaselog/format/__init__.py | 8 +++++- releaselog/format/cpan.py | 1 + releaselog/format/gnu.py | 1 + releaselog/format/python.py | 1 + setup.py | 48 +++++++++++++++++++++++++++++++ 9 files changed, 149 insertions(+), 75 deletions(-) create mode 100755 bin/releaselog delete mode 100644 releaselog.py create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index ed0a9ff..5f2763b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ *~ -.emacs* *.pyc -/tmp +.emacs.desktop +build/ +dist/ +tmp/ +*.egg-info/ diff --git a/bin/releaselog b/bin/releaselog new file mode 100755 index 0000000..c535a08 --- /dev/null +++ b/bin/releaselog @@ -0,0 +1,66 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +from __future__ import print_function +from __future__ import unicode_literals + +import sys +from optparse import OptionParser +from releaselog.input import ReleaseLogFile, ReleaseLogURL + +# Set utf-8 as the default encoding for Python 2.7. +try: + reload(sys) + sys.setdefaultencoding('utf-8') +except: + pass + +def main(): + usage = '%prog [OPTIONS] ARG' + version = '%prog 1.0' + description = """Read release logs in various formats""" + parser = OptionParser(usage=usage, + version=version, + description=description) + parser.add_option('-T', '--type', + action='store', type='string', dest='logtype', + default='GNU', + help='set log type') + parser.add_option('-f', '--from', '--start', + action='store', type='int', dest='start', + help='start from this entry') + parser.add_option('-t', '--to', '--stop', + action='store', type='int', dest='stop', + help='end on this entry') + parser.add_option('-n', '--count', + action='store', type='int', dest='count', + help='read at most that much entries') + parser.add_option('-u', '--url', + action="store_true", dest='url', + help='treat ARG as URL') + parser.add_option('-l', '--list', + action="store_true", dest='list', + help="list supported formats") + (options, args) = parser.parse_args() + + if options.list: + for f in ReleaseLogFile.formats(): + if len(f) > 1: + print("%s; %s" % (f[0], ', '.join(f[1:]))) + else: + print("%s" % f[0]) + sys.exit(0) + + if len(args) != 1: + parser.error("bad number of arguments") + + release_log = ReleaseLogURL if options.url else ReleaseLogFile + cl = release_log(options.logtype, args[0], + start=options.start, + stop=options.stop, + count=options.count) + for r in cl: + print(r) + print('\n'.join(r.descr)) + +if __name__ == '__main__': + main() diff --git a/releaselog.py b/releaselog.py deleted file mode 100644 index c535a08..0000000 --- a/releaselog.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -from __future__ import print_function -from __future__ import unicode_literals - -import sys -from optparse import OptionParser -from releaselog.input import ReleaseLogFile, ReleaseLogURL - -# Set utf-8 as the default encoding for Python 2.7. -try: - reload(sys) - sys.setdefaultencoding('utf-8') -except: - pass - -def main(): - usage = '%prog [OPTIONS] ARG' - version = '%prog 1.0' - description = """Read release logs in various formats""" - parser = OptionParser(usage=usage, - version=version, - description=description) - parser.add_option('-T', '--type', - action='store', type='string', dest='logtype', - default='GNU', - help='set log type') - parser.add_option('-f', '--from', '--start', - action='store', type='int', dest='start', - help='start from this entry') - parser.add_option('-t', '--to', '--stop', - action='store', type='int', dest='stop', - help='end on this entry') - parser.add_option('-n', '--count', - action='store', type='int', dest='count', - help='read at most that much entries') - parser.add_option('-u', '--url', - action="store_true", dest='url', - help='treat ARG as URL') - parser.add_option('-l', '--list', - action="store_true", dest='list', - help="list supported formats") - (options, args) = parser.parse_args() - - if options.list: - for f in ReleaseLogFile.formats(): - if len(f) > 1: - print("%s; %s" % (f[0], ', '.join(f[1:]))) - else: - print("%s" % f[0]) - sys.exit(0) - - if len(args) != 1: - parser.error("bad number of arguments") - - release_log = ReleaseLogURL if options.url else ReleaseLogFile - cl = release_log(options.logtype, args[0], - start=options.start, - stop=options.stop, - count=options.count) - for r in cl: - print(r) - print('\n'.join(r.descr)) - -if __name__ == '__main__': - main() diff --git a/releaselog/__init__.py b/releaselog/__init__.py index e4a04c5..015f796 100644 --- a/releaselog/__init__.py +++ b/releaselog/__init__.py @@ -39,13 +39,20 @@ class Release(object): 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 = [] @@ -63,10 +70,10 @@ class ReleaseHistory(object): 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. @@ -121,6 +128,8 @@ class ReleaseHistory(object): Entries are numbered from 0. """ + self.history = [] + date = None version = None descr = [] @@ -136,7 +145,7 @@ class ReleaseHistory(object): elif kw == 'count': count = val else: - raise TypeError() # FIXME + raise KeyError ('keyword %s is not known' % kw) if count: if start: @@ -247,7 +256,12 @@ class ReleaseLog(object): 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 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 @@ -5,10 +5,16 @@ 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 @@ -16,5 +16,6 @@ from releaselog import ReleaseHistory class ReleaseLogFormat(ReleaseHistory): format = ['CPAN', 'Changes'] + filename = 'Changes' header = re.compile('^(?P\d[\d.]*)\s+(?P.+?)\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 @@ -16,6 +16,7 @@ from releaselog import ReleaseHistory class ReleaseLogFormat(ReleaseHistory): format = ['GNU', 'NEWS'] + filename = 'NEWS' header = re.compile(r"""^(?:\*\s+)? # optional initial section (?:(?i)version)\s+ (?P\d(?:[.,]\d+){1,2} # At least MAJOR.MINOR 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 @@ -28,6 +28,7 @@ from releaselog import ReleaseHistory class PythonLogFormat(ReleaseHistory): format = ['Python', 'python'] + filename = 'CHANGES.txt' header = None header_rx = [ re.compile("""^[vV](?P\d[\d.]*)\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 . + +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', +) -- cgit v1.2.1