diff options
author | Michael Elkins <melkins@tislabs.com> | 2013-04-03 22:22:34 +0000 |
---|---|---|
committer | Michael Elkins <melkins@tislabs.com> | 2013-04-03 22:22:34 +0000 |
commit | 07fa0b0c9dcb9c2b1b2e1ad982bf3005e2195e8e (patch) | |
tree | 8a342684244fca72739e45556ef25c2618f784b6 /rpkid/rpki/gui/routeview/util.py | |
parent | 01f2d809570964c09408c3c81d642d5d4c6382e4 (diff) |
add support for automatically fetching routeviews.org dumps specified by URL
see #502
svn path=/trunk/; revision=5266
Diffstat (limited to 'rpkid/rpki/gui/routeview/util.py')
-rw-r--r-- | rpkid/rpki/gui/routeview/util.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/rpkid/rpki/gui/routeview/util.py b/rpkid/rpki/gui/routeview/util.py index e894767b..589a7714 100644 --- a/rpkid/rpki/gui/routeview/util.py +++ b/rpkid/rpki/gui/routeview/util.py @@ -21,6 +21,8 @@ import os.path import subprocess import time import logging +import urlparse +from urllib import urlretrieve, unquote from django.db import transaction, connection @@ -172,6 +174,19 @@ def import_routeviews_dump(filename, filetype='auto'): """ start_time = time.time() + if filename.startswith('http://'): + #get filename from the basename of the URL + u = urlparse.urlparse(filename) + bname = os.path.basename(unquote(u.path)) + tmpname = os.path.join('/tmp', bname) + + logger.info("Downloading %s to %s" % (filename, tmpname)) + if os.path.exists(tmpname): + os.remove(tmpname) + # filename is replaced with a local filename containing cached copy of + # URL + filename, headers = urlretrieve(filename, tmpname) + if filetype == 'auto': # try to determine input type from filename, based on the default # filenames from archive.routeviews.org |