ajack 2003/10/16 13:22:04
Modified: python/gump launcher.py tools.py
Log:
For once managed to create a unit test (for tail file to string)
Revision Changes Path
1.15 +1 -1 jakarta-gump/python/gump/launcher.py
Index: launcher.py
===================================================================
RCS file: /home/cvs/jakarta-gump/python/gump/launcher.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- launcher.py 16 Oct 2003 20:07:42 -0000 1.14
+++ launcher.py 16 Oct 2003 20:22:04 -0000 1.15
@@ -247,7 +247,7 @@
tail = "---------------------------------------------"
if self.output:
- tail += gump.tools.tail(self.output,lines)
+ tail += gump.tools.tailFileToString(self.output,lines)
else:
tail += "No output"
1.5 +19 -8 jakarta-gump/python/gump/tools.py
Index: tools.py
===================================================================
RCS file: /home/cvs/jakarta-gump/python/gump/tools.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- tools.py 16 Oct 2003 20:07:42 -0000 1.4
+++ tools.py 16 Oct 2003 20:22:04 -0000 1.5
@@ -114,7 +114,7 @@
return work
-def tail(file,lines):
+def tailFile(file,lines):
""" Return the last N lines of a file as a list """
taillines=[]
try:
@@ -123,19 +123,27 @@
o=open(file, 'r')
line=o.readline()
- # Store the lines
- taillines.append(line)
+ while line:
+ # Store the lines
+ taillines.append(line)
- # But dump any before 'lines'
- size=len(taillines)
- if size > lines:
- del taillines[0:size-lines]
+ # But dump any before 'lines'
+ size=len(taillines)
+ if size > lines:
+ del taillines[0:(size-lines)]
+
+ # Read next...
+ line=o.readline()
+
finally:
if o: o.close()
except:
x.write('Failed to tail :' + file)
return taillines
+
+def tailFileToString(file,lines):
+ return "".join(tailFile(file,lines))
if __name__=='__main__':
@@ -145,5 +153,8 @@
#set verbosity to show all messages of severity >= default.logLevel
log.setLevel(default.logLevel)
- dump(log)
+ # dump(log)
+
+ if len(sys.argv) > 0:
+ print tailFileToString(sys.argv[1], 5 )
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]