77import os
88import subprocess # nosec
99import sys
10- import urllib2 # noqa: F401 # pylint: disable=unused-import
11- import urlparse # noqa: F401 # pylint: disable=unused-import
10+ import urllib2 # noqa: F401 # pylint: disable=import-error, unused-import
11+ import urlparse # noqa: F401 # pylint: disable=import-error, unused-import
1212
1313SCRIPT_DIR = os .path .dirname (os .path .realpath (__file__ ))
1414ZANATA_ENV_FILE = os .path .join (SCRIPT_DIR , 'zanata-env.sh' )
15+ BASH_CMD = '/bin/bash'
1516
1617
1718def logging_init (level = logging .INFO ):
@@ -26,8 +27,8 @@ def logging_init(level=logging.INFO):
2627def read_env (filename ):
2728 # type (str) -> dict
2829 """Read environment variables by sourcing a bash file"""
29- proc = subprocess .Popen (
30- ['bash' , '-c' ,
30+ proc = subprocess .Popen ( # nosec
31+ [BASH_CMD , '-c' ,
3132 "source %s && set -o posix && set" % (filename )],
3233 stdout = subprocess .PIPE )
3334 return {kv [0 ]: kv [1 ] for kv in map (
@@ -40,17 +41,21 @@ def read_env(filename):
4041
4142class HTTPBasicAuthHandler (urllib2 .HTTPBasicAuthHandler ):
4243 """Handle Basic Authentication"""
43- def http_error_401 (self , req , error_body , code , msg , headers ): # noqa: E501 # pylint: disable=unused-argument, too-many-arguments
44+ @staticmethod
45+ def http_error_401 (req , error_body , code , msg , headers ): # noqa: E501 # pylint: disable=unused-argument, too-many-arguments
4446 """retry with basic auth when facing a 401"""
4547 host = req .get_host ()
4648 realm = None
47- return self .retry_http_basic_auth (host , req , realm )
49+ return urllib2 .HTTPBasicAuthHandler .retry_http_basic_auth (
50+ host , req , realm )
4851
49- def http_error_403 (self , req , error_body , code , msg , headers ): # noqa: E501 # pylint: disable=unused-argument,too-many-arguments
52+ @staticmethod
53+ def http_error_403 (req , error_body , code , msg , headers ): # noqa: E501 # pylint: disable=unused-argument,too-many-arguments
5054 """retry with basic auth when facing a 403"""
5155 host = req .get_host ()
5256 realm = None
53- return self .retry_http_basic_auth (host , req , realm )
57+ return urllib2 .HTTPBasicAuthHandler .retry_http_basic_auth (
58+ host , req , realm )
5459
5560
5661class SshHost (object ):
@@ -94,7 +99,7 @@ def run_command(self, command, sudo=False):
9499 ('sudo ' if sudo else '' ) + command ]
95100 logging .info (' ' .join (cmd_list ))
96101
97- subprocess .check_call (cmd_list )
102+ subprocess .check_call (cmd_list ) # nosec
98103
99104 def scp_to_remote (
100105 self , source_path , dest_path ,
@@ -112,7 +117,7 @@ def scp_to_remote(
112117
113118 logging .info (' ' .join (cmd_list ))
114119
115- subprocess .check_call (cmd_list )
120+ subprocess .check_call (cmd_list ) # nosec
116121
117122
118123class UrlHelper (object ):
@@ -157,14 +162,14 @@ def download_file(url, dest_file='', dest_dir='.'):
157162 raise
158163
159164 logging .info ("Downloading to %s from %s" , target_path , url )
160- response = urllib2 .urlopen (url )
165+ response = urllib2 .urlopen (url ) # nosec
161166 chunk_count = 0
162167 with open (target_path , 'wb' ) as out_file :
163168 while True :
164- buffer = response .read (chunk )
165- if not buffer :
169+ buf = response .read (chunk )
170+ if not buf :
166171 break
167- out_file .write (buffer )
172+ out_file .write (buf )
168173 chunk_count += 1
169174 if chunk_count % 100 == 0 :
170175 sys .stderr .write ('#' )
0 commit comments