Package pysys :: Package utils :: Module filegrep
[hide private]
[frames] | no frames]

Module filegrep

source code

Functions [hide private]
list
getmatches(file, regexpr, ignores=None)
Look for matches on a regular expression in an input file, return a sequence of the matches.
source code
integer
filegrep(file, expr, ignores=None, returnMatch=False)
Search for matches to a regular expression in an input file, returning true if a match occurs.
source code
integer
lastgrep(file, expr, ignore=[], include=[])
Search for matches to a regular expression in the last line of an input file, returning true if a match occurs.
source code
integer
orderedgrep(file, exprList)
Seach for ordered matches to a set of regular expressions in an input file, returning true if the matches occur in the correct order.
source code
 
logContents(message, list)
Log a list of strings, prepending the line number to each line in the log output.
source code
Variables [hide private]
  __package__ = 'pysys.utils'
Function Details [hide private]

getmatches(file, regexpr, ignores=None)

source code 

Look for matches on a regular expression in an input file, return a sequence of the matches.

Parameters:
  • file - The full path to the input file
  • regexpr - The regular expression used to search for matches
  • ignores - A list of regexes which will cause matches to be discarded
Returns: list
A list of the match objects
Raises:

filegrep(file, expr, ignores=None, returnMatch=False)

source code 

Search for matches to a regular expression in an input file, returning true if a match occurs.

Parameters:
  • file - The full path to the input file
  • expr - The regular expression (uncompiled) to search for in the input file
  • ignores - Optional list of regular expression strings to ignore when searching file.
  • returnMatch - return the regex match object instead of a simple boolean
Returns: integer
success (True / False), unless returnMatch=True in which case it returns the regex match object (or None if not matched)
Raises:

lastgrep(file, expr, ignore=[], include=[])

source code 

Search for matches to a regular expression in the last line of an input file, returning true if a match occurs.

Parameters:
  • file - The full path to the input file
  • expr - The regular expression (uncompiled) to search for in the last line of the input file
  • ignore - A list of regular expressions which remove entries in the input file contents before making the grep
  • include - A list of regular expressions used to select lines from the input file contents to use in the grep
Returns: integer
success (True / False)
Raises:

orderedgrep(file, exprList)

source code 

Seach for ordered matches to a set of regular expressions in an input file, returning true if the matches occur in the correct order.

The ordered grep method will only return true if matches to the set of regular expression in the expression list occur in the input file in the order they appear in the expression list. Matches to the regular expressions do not have to be across sequential lines in the input file, only in the correct order. For example, for a file with contents :

   A is for apple 
   B is for book
   C is for cat
   D is for dog

an expression list of ["^A.*$", "^C.*$", "^D.*$"] will return true, whilst an expression list of ["^A.*$", "^C.$", "^B.$"] will return false.

Parameters:
  • file - The full path to the input file
  • exprList - A list of regular expressions (uncompiled) to search for in the input file
Returns: integer
success (True / False)
Raises:

logContents(message, list)

source code 

Log a list of strings, prepending the line number to each line in the log output.

Parameters:
  • list - The list of strings to log