diff --git a/CHANGELOG b/CHANGELOG index e332ef3..aae58f7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,38 +1,48 @@ Change log for paragrep --------------------------------------------------------------------------- +Version 3.1.0 (24 March, 2012) + +- Added ability to display the matching end-of-paragraph lines. Specify + the "-P" option. (Issue #1, https://github.com/bmc/paragrep/issues/1) +- "-a" and "-o" options not working correctly with multiple regexs. Problem + was a Python statement indentation issue. (Issue #2, + https://github.com/bmc/paragrep/issues/2) +- Fixed some minor issues with the "-i" (case-blind) option +- Removed some dead code. + + Version 3.0.7 (6 March, 2012) - Removed unused "-t" option from option summary in usage message. ---------------------------------------------------------------------------- Version 3.0.6 (14 March, 2011) - Removed setup.py dependency on ez_setup. - Changed to refer to 'grizzled-python', instead of 'grizzled' ---------------------------------------------------------------------------- + Version 3.0.5 (28 March, 2010) - Updated to latest version of ez_setup.py - Adjusted license to new BSD license. - Changed URL to new GitHub URL. ---------------------------------------------------------------------------- + Version 3.0.4 (16 January, 2009) - Now reads lines from the files in a more memory-efficient manner. - Fixed problem with compilation of regexps. ---------------------------------------------------------------------------- + Version 3.0.3 (9 November, 2008) - Version (--version) option is now handled by the option parser. - Removed left-over camel case variable names. - Fixed -i (case-blind) matching, which wasn't working. ---------------------------------------------------------------------------- + Version 3.0.2 (3 September, 2008) - Changed epydoc markup to use reStructuredText. @@ -41,12 +51,13 @@ Version 3.0.2 (3 September, 2008) - Added --version option. - Now properly bundles ez_setup.py ---------------------------------------------------------------------------- + Version 3.0.1 (20 May, 2008) - Updated to correspond to changes in the dependent Grizzled API. ---------------------------------------------------------------------------- + Version 3.0 (3 April, 2008) -- Initial version posted to the web. +- Python version posted to the web. (Previous versions were implemented + in Perl and C.) diff --git a/paragrep/__init__.py b/paragrep/__init__.py index fe3527b..6b95b79 100644 --- a/paragrep/__init__.py +++ b/paragrep/__init__.py @@ -184,7 +184,7 @@ __docformat__ = 'restructuredtext' # Info about the module -__version__ = '3.0.8' +__version__ = '3.1.0' __author__ = 'Brian M. Clapper' __email__ = 'bmc@clapper.org' __url__ = 'http://software.clapper.org/paragrep/' @@ -234,6 +234,7 @@ def __init__(self): self.case_blind = False self.negate = False self.show_version = False + self.print_eop = False self.__print_file_name = False self.__print_file_header = False @@ -266,6 +267,17 @@ def _search(self, f, filename=None): paragraph = [] last_empty = False found = False + eop_line = None + + def print_paragraph(paragraph): + if self.__print_file_header: + print '::::::::::\n%s\n::::::::::\n' % filename + self.__print_file_header = False + print '\n'.join(paragraph) + if self.print_eop and (eop_line is not None): + print eop_line + else: + print "" for line in f: if self.eop_regexp.match(line): @@ -274,14 +286,20 @@ def _search(self, f, filename=None): # the end of the paragraph, search the accumulated lines of # the paragraph. + if line[-1] == '\n': + eop_line = line[:-1] + else: + eop_line = line + if not last_empty: last_empty = True - found = self._search_paragraph(paragraph, filename) + found = self._search_paragraph(paragraph) + if found: + print_paragraph(paragraph) paragraph = [] else: # Save this line in the current paragraph buffer - if line[-1] == '\n': line = line[:-1] paragraph += [line] @@ -290,21 +308,18 @@ def _search(self, f, filename=None): # We might have a paragraph left in the buffer. If so, search it. if not last_empty: - if self._search_paragraph(paragraph, filename): + if self._search_paragraph(paragraph): found = True + print_paragraph(paragraph) return found - def _search_paragraph(self, paragraph, filename): + def _search_paragraph(self, paragraph): found_count_must_be = 1 if self.anding: # If ANDing, must match ALL the regular expressions. found_count_must_be = len(self.regexps) - paragraph_as_one_string = ' '.join(paragraph) - if self.case_blind: - paragraph_as_one_string = paragraph_as_one_string.lower() - total_found = 0 for re in self.regexps: for line in paragraph: @@ -312,13 +327,10 @@ def _search_paragraph(self, paragraph, filename): total_found += 1 break - if ((total_found == found_count_must_be) and (not self.negate)) or \ - ((total_found != found_count_must_be) and self.negate): + if (not self.negate) and (total_found >= found_count_must_be): + found = True + elif self.negate and (total_found != found_count_must_be): found = True - if self.__print_file_header: - print '::::::::::\n%s\n::::::::::\n' % filename - self.__print_file_header = False - print '\n'.join(paragraph) + '\n' else: found = False @@ -370,6 +382,10 @@ def _parse_params(paragrepper, argv): dest='eop_regexp', default=r'^\s*$', metavar='eop_regexp', help=r'Specify an alternate regular expression ' \ 'to match end-of-paragraph. Default: %default') + parser.add_option('-P', '--print-eop', action='store_true', + dest='print_eop', default=False, metavar='print_eop', + help=r'Print the line that marks the end of each. ' \ + 'paragraph. Default: %default') parser.add_option('-v', '--negate', action='store_true', dest='negate', help='Negate the sense of the match.') @@ -380,6 +396,7 @@ def _parse_params(paragrepper, argv): paragrepper.anding = options.anding paragrepper.case_blind = options.caseblind paragrepper.negate = options.negate + paragrepper.print_eop = options.print_eop # Figure out where to get the regular expressions to find.