1
1
"""Support and convenience functions for tests."""
2
+ from __future__ import print_function
2
3
3
4
import errno
4
5
import os
@@ -127,9 +128,9 @@ def end_log():
127
128
def dump_log (outfile = None ):
128
129
if outfile is None :
129
130
logfile = open (_log_filename , 'r' )
130
- print '\n '
131
+ print ( '\n ' )
131
132
for line in logfile :
132
- print line .rstrip ('\n ' )
133
+ print ( line .rstrip ('\n ' ) )
133
134
logfile .close ()
134
135
else :
135
136
shutil .copy (_log_filename , outfile )
@@ -143,7 +144,7 @@ def get_stat(filename):
143
144
'''Return stat for 'filename', None if the file does not exist'''
144
145
try :
145
146
return os .stat (filename )
146
- except OSError , exc :
147
+ except OSError as exc :
147
148
if exc .errno == errno .ENOENT :
148
149
return None
149
150
raise
@@ -493,7 +494,7 @@ def __run_command(command, use_test_user, a_input, a_stdout, a_stderr, log_outpu
493
494
try :
494
495
repr (command )
495
496
except TypeError :
496
- print 'Need list or tuple, got %s' % type (command )
497
+ print ( 'Need list or tuple, got %s' % type (command ) )
497
498
if use_test_user :
498
499
command = ['runuser' , options .username , '-c' , ' ' .join (map (__prepare_shell_argument , command ))]
499
500
@@ -603,7 +604,7 @@ def el_release():
603
604
release_file .close ()
604
605
match = re .search (r"release (\d)" , release_text )
605
606
_el_release = int (match .group (1 ))
606
- except (EnvironmentError , TypeError , ValueError ), e :
607
+ except (EnvironmentError , TypeError , ValueError ) as e :
607
608
_log .write ("Couldn't determine redhat release: " + str (e ) + "\n " )
608
609
sys .exit (1 )
609
610
return _el_release
@@ -642,7 +643,7 @@ def check_file_and_perms(file_path, owner_name, permissions):
642
643
try :
643
644
file_stat = os .stat (file_path )
644
645
return (file_stat .st_uid == owner_uid and
645
- file_stat .st_mode & 07777 == permissions and
646
+ file_stat .st_mode & 0o7777 == permissions and
646
647
stat .S_ISREG (file_stat .st_mode ))
647
648
except OSError : # file does not exist
648
649
return False
@@ -684,7 +685,7 @@ def install_cert(target_key, source_key, owner_name, permissions):
684
685
os .makedirs (target_dir )
685
686
state [target_key + '-dir' ] = target_dir
686
687
os .chown (target_dir , user .pw_uid , user .pw_gid )
687
- os .chmod (target_dir , 0755 )
688
+ os .chmod (target_dir , 0o755 )
688
689
689
690
shutil .copy (source_path , target_path )
690
691
state [target_key ] = target_path
@@ -697,12 +698,12 @@ def remove_cert(target_key):
697
698
paths associated with the key, as created by the install_cert()
698
699
function.
699
700
"""
700
- if state . has_key ( target_key ) :
701
+ if target_key in state :
701
702
os .remove (state [target_key ])
702
- if state . has_key ( target_key + '-backup' ) :
703
+ if target_key + '-backup' in state :
703
704
shutil .move (state [target_key + '-backup' ],
704
705
state [target_key ])
705
- if state . has_key ( target_key + '-dir' ) :
706
+ if target_key + '-dir' in state :
706
707
target_dir = state [target_key + '-dir' ]
707
708
if len (os .listdir (target_dir )) == 0 :
708
709
os .rmdir (target_dir )
0 commit comments