[utils] script utils
This commit is contained in:
@@ -2,6 +2,10 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def download_file(url, dest_dir):
|
||||||
|
return subprocess.call(['wget', url, '-O', dest_dir, '--quiet']) == 0
|
||||||
|
|
||||||
|
|
||||||
def unzip_file(filename, dest_dir):
|
def unzip_file(filename, dest_dir):
|
||||||
subprocess.call(['unzip', '-o', filename, '-d', dest_dir])
|
subprocess.call(['unzip', '-o', filename, '-d', dest_dir])
|
||||||
|
|
||||||
@@ -13,3 +17,16 @@ def remove_file(filename):
|
|||||||
def ensure_dir(d):
|
def ensure_dir(d):
|
||||||
if not os.path.exists(d):
|
if not os.path.exists(d):
|
||||||
os.makedirs(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)
|
||||||
|
|||||||
Reference in New Issue
Block a user