[fix] unzip_file checks status code
This commit is contained in:
@@ -13,7 +13,7 @@ def download_file(url, dest, retries=3, retry_delay=5):
|
|||||||
|
|
||||||
def unzip_file(filename, dest):
|
def unzip_file(filename, dest):
|
||||||
ensure_dir(dest)
|
ensure_dir(dest)
|
||||||
subprocess.call(['unzip', '-o', filename, '-d', dest])
|
return subprocess.check_call(['unzip', '-o', filename, '-d', dest]) == 0
|
||||||
|
|
||||||
|
|
||||||
def remove_file(filename):
|
def remove_file(filename):
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ sys.path.append(os.path.realpath(os.path.join(os.pardir, os.pardir)))
|
|||||||
|
|
||||||
from geodata.openaddresses.config import openaddresses_config
|
from geodata.openaddresses.config import openaddresses_config
|
||||||
from geodata.csv_utils import unicode_csv_reader
|
from geodata.csv_utils import unicode_csv_reader
|
||||||
from geodata.file_utils import ensure_dir, download_file, cd, remove_file
|
from geodata.file_utils import ensure_dir, download_file, unzip_file, cd, remove_file
|
||||||
from geodata.encoding import safe_encode, safe_decode
|
from geodata.encoding import safe_encode, safe_decode
|
||||||
|
|
||||||
BASE_OPENADDRESSES_DATA_URL = 'http://results.openaddresses.io'
|
BASE_OPENADDRESSES_DATA_URL = 'http://results.openaddresses.io'
|
||||||
@@ -29,7 +29,7 @@ def download_and_unzip_file(url, out_dir):
|
|||||||
zip_filename = url.rsplit('/', 1)[-1].strip()
|
zip_filename = url.rsplit('/', 1)[-1].strip()
|
||||||
zip_local_path = os.path.join(out_dir, zip_filename)
|
zip_local_path = os.path.join(out_dir, zip_filename)
|
||||||
|
|
||||||
success = download_file(url, zip_local_path) and subprocess.check_call(['unzip', '-o', zip_local_path, '-d', out_dir]) == 0
|
success = download_file(url, zip_local_path) and unzip_file(zip_local_path, out_dir)
|
||||||
|
|
||||||
if os.path.exists(zip_local_path):
|
if os.path.exists(zip_local_path):
|
||||||
remove_file(zip_local_path)
|
remove_file(zip_local_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user