summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richard.ipsum@codethink.co.uk>2015-05-28 16:29:47 +0100
committerRichard Ipsum <richard.ipsum@codethink.co.uk>2015-05-29 15:07:30 +0100
commitaf069de3dd5e36cf60f1f81a19cca873f92e3dcf (patch)
treef03f2cd312d876f93481f6294ba17be786823b55
parentd7a58d6f837570a3873432e53dc9e91a8dd0a0ef (diff)
downloadimport-af069de3dd5e36cf60f1f81a19cca873f92e3dcf.tar.gz
Make the python ext use caching
This doesn't provide much performance benefit, since most of our queries go through xmlrpclib, but caching here does no harm. Change-Id: Id740a7ffab56defeddb3a6f3f481d81498a4411a
-rwxr-xr-xbaserockimport/exts/python.to_lorry26
1 files changed, 14 insertions, 12 deletions
diff --git a/baserockimport/exts/python.to_lorry b/baserockimport/exts/python.to_lorry
index 2c57a9b..ebde27a 100755
--- a/baserockimport/exts/python.to_lorry
+++ b/baserockimport/exts/python.to_lorry
@@ -32,20 +32,11 @@ import yaml
import pkg_resources
+from importer_base import WebServiceClient
from importer_python_common import *
from utils import warn, error
import utils
-def fetch_package_metadata(package_name):
- try:
- result = requests.get('%s/%s/json' % (PYPI_URL, package_name))
-
- # raise exception if status code is not 200 OK
- result.raise_for_status()
- except Exception as e:
- error("Couldn't fetch package metadata:", e)
-
- return result.json()
def find_repo_type(url):
@@ -162,6 +153,13 @@ class PythonLorryExtension(ImportExtension):
def __init__(self):
super(PythonLorryExtension, self).__init__()
+ self.apiclient = WebServiceClient('python_api_cache')
+
+ def fetch_package_metadata(self, package_name):
+ r = self.apiclient.request('%s/%s/json' % (PYPI_URL, package_name))
+ r.raise_for_status()
+
+ return r
def run(self):
if len(sys.argv) not in [2, 3]:
@@ -187,8 +185,12 @@ class PythonLorryExtension(ImportExtension):
logging.debug('Treating %s as %s' % (package_name, new_proj_name))
package_name = new_proj_name
- metadata = fetch_package_metadata(package_name)
- info = metadata['info']
+ try:
+ metadata = self.fetch_package_metadata(package_name)
+ except Exception as e:
+ error("Couldn't fetch package metadata: ", e)
+
+ info = metadata.json()['info']
repo_type = (find_repo_type(info['home_page'])
if 'home_page' in info else None)