From 07fa0b0c9dcb9c2b1b2e1ad982bf3005e2195e8e Mon Sep 17 00:00:00 2001 From: Michael Elkins Date: Wed, 3 Apr 2013 22:22:34 +0000 Subject: add support for automatically fetching routeviews.org dumps specified by URL see #502 svn path=/trunk/; revision=5266 --- rpkid/rpki/gui/routeview/util.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'rpkid/rpki/gui/routeview/util.py') 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 -- cgit v1.2.3