aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJauhien Piatlicki <jauhien@gentoo.org>2015-08-18 20:07:55 +0200
committerJauhien Piatlicki <jauhien@gentoo.org>2015-08-18 20:50:20 +0200
commit7716920fcfcf1595f6b575e1fe41c733c5ec7ab2 (patch)
tree6932ea732b7bb50753da4f8565334d6500b6df9b
parent[g_sorcery/fileutils] set wget timeout to 2 seconds (diff)
downloadg-sorcery-7716920fcfcf1595f6b575e1fe41c733c5ec7ab2.tar.gz
g-sorcery-7716920fcfcf1595f6b575e1fe41c733c5ec7ab2.tar.bz2
g-sorcery-7716920fcfcf1595f6b575e1fe41c733c5ec7ab2.zip
[g_sorcery/fileutils] make wget timeout optional0.2.1
-rw-r--r--g_sorcery/fileutils.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/g_sorcery/fileutils.py b/g_sorcery/fileutils.py
index 235eaec..3440ec7 100644
--- a/g_sorcery/fileutils.py
+++ b/g_sorcery/fileutils.py
@@ -135,7 +135,7 @@ def copy_all(src, dst):
"""
os.system("cp -rv " + src + "/* " + dst)
-def wget(uri, directory, output=""):
+def wget(uri, directory, output="", timeout = None):
"""
Fetch a file.
@@ -143,15 +143,21 @@ def wget(uri, directory, output=""):
uri: URI.
directory: Directory where file should be saved.
output: Name of output file.
+ timeout: Timeout for wget.
Returns:
Nonzero in case of a failure.
"""
+ if timeout is None:
+ timeout_str = ' '
+ else:
+ timeout_str = ' -T ' + str(timeout)
+
if output:
ret = os.system('wget ' + uri +
- ' -O ' + os.path.join(directory, output) + ' -T 2')
+ ' -O ' + os.path.join(directory, output) + timeout_str)
else:
- ret = os.system('wget -P ' + directory + ' ' + uri + ' -T 2')
+ ret = os.system('wget -P ' + directory + ' ' + uri + timeout_str)
return ret
def get_pkgpath(root = None):
@@ -255,7 +261,7 @@ def _call_parser(f_name, parser, open_file = True, open_mode = 'r'):
return {os.path.basename(f_name): data}
-def load_remote_file(uri, parser, open_file = True, open_mode='r', output=""):
+def load_remote_file(uri, parser, open_file = True, open_mode = 'r', output = "", timeout = None):
"""
Load files from an URI.
@@ -264,7 +270,8 @@ def load_remote_file(uri, parser, open_file = True, open_mode='r', output=""):
parser: Parser that will be applied to downloaded files.
open_file: Whether parser accepts a file descriptor.
open_mode: Open mode for a file.
- output: What output name should downloaded file have
+ output: What output name should downloaded file have.
+ timeout: URI access timeout.
(it will be a key identifying data loaded from this file)
Returns:
@@ -272,7 +279,7 @@ def load_remote_file(uri, parser, open_file = True, open_mode='r', output=""):
"""
download_dir = TemporaryDirectory()
loaded_data = {}
- if wget(uri, download_dir.name, output):
+ if wget(uri, download_dir.name, output, timeout=timeout):
raise DownloadingError("wget failed: " + uri)
for f_name in glob.glob(os.path.join(download_dir.name, "*")):
if tarfile.is_tarfile(f_name):