[java-idp-log-analysis] 04/06: Commit Peter Schober's patch to clean up some code

Ian Young ian at iay.org.uk
Mon Jan 23 11:33:04 EST 2017


This is an automated email from the git hooks/post-receive script.

iay pushed a commit to branch master
in repository java-idp-log-analysis.

View the commit online:
http://git.shibboleth.net/view/?p=java-idp-log-analysis.git;a=commit;h=37c3a825c1f39947b50ea4cf007fed11606a8bd2

commit 37c3a825c1f39947b50ea4cf007fed11606a8bd2
Author: Chad La Joie <clajoie at gmail.com>
AuthorDate: Fri Aug 6 11:50:03 2010 +0000

    Commit Peter Schober's patch to clean up some code
---
 loganalysis.py | 38 +++++++-------------------------------
 1 file changed, 7 insertions(+), 31 deletions(-)

diff --git a/loganalysis.py b/loganalysis.py
index 78a50aa..12a2dc9 100644
--- a/loganalysis.py
+++ b/loganalysis.py
@@ -15,40 +15,19 @@
 # limitations under the License.
 #
 
-"""Parse Shibboleth 2.1 Identity Provider audit logfile and generate simple stats.
+"""Parse Shibboleth 2.x Identity Provider audit logfile and generate simple stats.
    Audit log file format: https://spaces.internet2.edu/display/SHIB2/IdPLogging"""
    
-import sys
+import sys,fileinput
 from optparse import OptionParser
 from operator import itemgetter
 
-def getLines(files):
-    """Return lines from file(s) or STDIN."""
-    lines = []
-    for file in files:
-        if file != "-":
-            try:
-                for line in open(file, "r"):
-                    lines.append(line)
-            except IOError:
-                print "File '" + file + "' not found."
-                sys.exit(-1)
-        else:
-            for line in sys.stdin:
-                lines.append(line)
-    return lines
-
-def linesFromFiles(files):
-    """Return lists (events) of lists (data fields)."""
-    lines = getLines(files)
-    table = []
-    for line in lines:
-        table.append(line.rstrip().split("|"))
-    return table
-
 def parseFiles(files,options):
     """Build datastructures from lines."""
-    lines = linesFromFiles(files)
+    lines = []
+    for line in fileinput.input(files):
+        lines.append(line.rstrip().split("|"))
+
     db = {}
     db['rp'], db['users'], db['msgprof'], db['logins'] = {},{},{},0
 
@@ -171,13 +150,10 @@ def main():
         parser.error("Options -p and -n are mutually exclusive (just use one or the other).")
 
     # Make sure that at least one option is set, otherwise don't bother parsing any logfiles
-    hasOpt = False
     for value in options.__dict__.values():
         if value:
-            hasOpt = True
+            db = parseFiles(args,options)
             break
-    if hasOpt:
-        db = parseFiles(args,options)
     else:
         print "Missing option: At least one option needs to be supplied.\n"
         parser.print_help()

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list