Files
libpostal/scripts/geodata/file_utils.py
2015-03-17 18:39:08 -04:00

33 lines
678 B
Python

import os
import subprocess
def download_file(url, dest_dir):
return subprocess.call(['wget', url, '-O', dest_dir, '--quiet']) == 0
def unzip_file(filename, dest_dir):
subprocess.call(['unzip', '-o', filename, '-d', dest_dir])
def remove_file(filename):
os.unlink(filename)
def ensure_dir(d):
if not os.path.exists(d):
os.makedirs(d)
class cd:
"""Context manager for changing the current working directory"""
def __init__(self, path):
self.path = path
def __enter__(self):
self.saved_path = os.getcwd()
os.chdir(self.path)
def __exit__(self, etype, value, traceback):
os.chdir(self.saved_path)