16
16
# Copyright (c) 2017 Datto Inc.
17
17
#
18
18
19
- import configparser
19
+ import ConfigParser
20
20
import os
21
21
import logging
22
22
from datetime import datetime
27
27
from subprocess import PIPE
28
28
from subprocess import Popen
29
29
from sys import argv
30
- from sys import maxsize
30
+ from sys import maxint
31
31
from threading import Timer
32
32
from time import time
33
33
@@ -204,23 +204,23 @@ def run(self, options):
204
204
if needed. Run the command, and update the result object.
205
205
"""
206
206
if options .dryrun is True :
207
- print ( self )
207
+ print self
208
208
return
209
209
210
210
privcmd = self .update_cmd_privs (self .pathname , self .user )
211
211
try :
212
212
old = os .umask (0 )
213
213
if not os .path .isdir (self .outputdir ):
214
- os .makedirs (self .outputdir , mode = 0o777 )
214
+ os .makedirs (self .outputdir , mode = 0777 )
215
215
os .umask (old )
216
- except OSError as e :
216
+ except OSError , e :
217
217
fail ('%s' % e )
218
218
219
219
self .result .starttime = time ()
220
220
proc = Popen (privcmd , stdout = PIPE , stderr = PIPE )
221
221
# Allow a special timeout value of 0 to mean infinity
222
222
if int (self .timeout ) == 0 :
223
- self .timeout = maxsize
223
+ self .timeout = maxint
224
224
t = Timer (int (self .timeout ), self .kill_cmd , [proc ])
225
225
226
226
try :
@@ -274,7 +274,7 @@ def log(self, logger, options):
274
274
logger .debug ('%s%s%s' % (msga , pad , msgb ))
275
275
276
276
lines = sorted (self .result .stdout + self .result .stderr ,
277
- key = lambda x : x [0 ])
277
+ cmp = lambda x , y : cmp ( x [0 ], y [ 0 ]) )
278
278
279
279
for dt , line in lines :
280
280
logger .debug ('%s %s' % (dt .strftime ("%H:%M:%S.%f " )[:11 ], line ))
@@ -552,7 +552,7 @@ def read(self, logger, options):
552
552
in the 'DEFAULT' section. If the Test or TestGroup passes
553
553
verification, add it to the TestRun.
554
554
"""
555
- config = configparser .RawConfigParser ()
555
+ config = ConfigParser .RawConfigParser ()
556
556
if not len (config .read (options .runfile )):
557
557
fail ("Coulnd't read config file %s" % options .runfile )
558
558
@@ -608,7 +608,7 @@ def write(self, options):
608
608
609
609
defaults = dict ([(prop , getattr (options , prop )) for prop , _ in
610
610
self .defaults ])
611
- config = configparser .RawConfigParser (defaults )
611
+ config = ConfigParser .RawConfigParser (defaults )
612
612
613
613
for test in sorted (self .tests .keys ()):
614
614
config .add_section (test )
@@ -637,15 +637,14 @@ def complete_outputdirs(self):
637
637
"""
638
638
done = False
639
639
components = 0
640
- tmp_dict = dict (list (self .tests .items ()) +
641
- list (self .testgroups .items ()))
640
+ tmp_dict = dict (self .tests .items () + self .testgroups .items ())
642
641
total = len (tmp_dict )
643
642
base = self .outputdir
644
643
645
644
while not done :
646
645
paths = []
647
646
components -= 1
648
- for testfile in list ( tmp_dict .keys () ):
647
+ for testfile in tmp_dict .keys ():
649
648
uniq = '/' .join (testfile .split ('/' )[components :]).lstrip ('/' )
650
649
if uniq not in paths :
651
650
paths .append (uniq )
@@ -673,9 +672,9 @@ def setup_logging(self, options):
673
672
if options .cmd is not 'wrconfig' :
674
673
try :
675
674
old = os .umask (0 )
676
- os .makedirs (self .outputdir , mode = 0o777 )
675
+ os .makedirs (self .outputdir , mode = 0777 )
677
676
os .umask (old )
678
- except OSError as e :
677
+ except OSError , e :
679
678
fail ('%s' % e )
680
679
filename = os .path .join (self .outputdir , 'log' )
681
680
@@ -708,8 +707,8 @@ def run(self, options):
708
707
if not os .path .exists (logsymlink ):
709
708
os .symlink (self .outputdir , logsymlink )
710
709
else :
711
- print ( 'Could not make a symlink to directory %s' % (
712
- self .outputdir ))
710
+ print 'Could not make a symlink to directory %s' % (
711
+ self .outputdir )
713
712
iteration = 0
714
713
while iteration < options .iterations :
715
714
for test in sorted (self .tests .keys ()):
@@ -722,17 +721,17 @@ def summary(self):
722
721
if Result .total is 0 :
723
722
return 2
724
723
725
- print ( '\n Results Summary' )
726
- for key in list ( Result .runresults .keys () ):
724
+ print '\n Results Summary'
725
+ for key in Result .runresults .keys ():
727
726
if Result .runresults [key ] is not 0 :
728
- print ( '%s\t % 4d' % (key , Result .runresults [key ]) )
727
+ print '%s\t % 4d' % (key , Result .runresults [key ])
729
728
730
729
m , s = divmod (time () - self .starttime , 60 )
731
730
h , m = divmod (m , 60 )
732
- print ( '\n Running Time:\t %02d:%02d:%02d' % (h , m , s ) )
733
- print ( 'Percent passed:\t %.1f%%' % ((float (Result .runresults ['PASS' ]) /
734
- float (Result .total )) * 100 ))
735
- print ( 'Log directory:\t %s' % self .outputdir )
731
+ print '\n Running Time:\t %02d:%02d:%02d' % (h , m , s )
732
+ print 'Percent passed:\t %.1f%%' % ((float (Result .runresults ['PASS' ]) /
733
+ float (Result .total )) * 100 )
734
+ print 'Log directory:\t %s' % self .outputdir
736
735
737
736
if Result .runresults ['FAIL' ] > 0 :
738
737
return 1
@@ -805,7 +804,7 @@ def find_tests(testrun, options):
805
804
806
805
807
806
def fail (retstr , ret = 1 ):
808
- print ( '%s: %s' % (argv [0 ], retstr ) )
807
+ print '%s: %s' % (argv [0 ], retstr )
809
808
exit (ret )
810
809
811
810
0 commit comments