Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for cache freshness #19

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions yolk/pypi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

"""

pypi.py
Expand Down Expand Up @@ -26,6 +25,7 @@
import xmlrpc.client as xmlrpclib
import pickle
import urllib.request as urllib2
import sys
import os
import time
import logging
Expand Down Expand Up @@ -208,9 +208,18 @@ def query_cached_package_list(self):
def fetch_pkg_list(self):
"""Fetch and cache master list of package names from PYPI"""
self.logger.debug("DEBUG: Fetching package name list from PyPI")
package_list = self.list_packages()
cPickle.dump(package_list, open(self.pkg_cache_file, "w"))
self.pkg_list = package_list

if os.path.exists(self.pkg_cache_file):
st = os.stat(self.pkg_cache_file)
age = time.time() - st.st_mtime
else:
age = sys.maxint

# Only fetch from PyPI if cache older than an hour
if age > 60 * 60:
package_list = self.list_packages()
cPickle.dump(package_list, open(self.pkg_cache_file, "w"))
self.pkg_list = package_list

def search(self, spec, operator):
'''Query PYPI via XMLRPC interface using search spec'''
Expand Down