Commits

Anonymous committed 9c6f0c1

Updated status messages, improved comments, reversed sense of .pkl load vs. create & save, made sure alignment was correct on status printout

Comments (0)

Files changed (1)

test_pypi_versions.py

 ##  suggest_normalized_version() into PEP-386 compatible versions.
 ##
 ##  Requires : Python 2.5+
+##
+##  Written by: ssteinerX@gmail.com
 #
 
 try:
 
 from verlib import suggest_normalized_version
 
+#
+## To re-run from scratch, just delete these two .pkl files
+#
 INDEX_PICKLE_FILE = 'pypi-index.pkl'
 VERSION_PICKLE_FILE = 'pypi-version.pkl'
 
 package_info = version_info = []
 
 #
-## Get pypi full package list if the file's not found, else restore it
+## if there's a saved version of the package list
+##      restore it
+## else:
+##      pull the list down from pypi
+##      save a pickled version of it
 #
-if not os.path.exists(INDEX_PICKLE_FILE):
+if os.path.exists(INDEX_PICKLE_FILE):
+    print "Loading saved pypi data..."
+    with open(INDEX_PICKLE_FILE, 'rb') as f:
+        package_info = pickle.load(f)
+else:
     print "Retrieving pypi packages..."
     server = xmlrpclib.Server('http://pypi.python.org/pypi')
     package_info  = server.search({'name': ''})
 
-    print "Saving package info.."
+    print "Saving package info..."
     with open(INDEX_PICKLE_FILE, 'wb') as o:
         pickle.dump(package_info, o)
-else:
-    print "Loading saved pypi data..."
-    with open(INDEX_PICKLE_FILE, 'rb') as f:
-        package_info = pickle.load(f)
 
 #
-## Save pypi package's version info  Get pypi full package list if the file's
-## not found, else restore it
+## If there's a saved list of the versions from the packages
+##      restore it
+## else
+##     extract versions from the package list
+##     save a pickled version of it
 #
 versions = []
-if not os.path.exists(VERSION_PICKLE_FILE):
-    print "Number of Packages = ", len(package_info)
+if os.path.exists(VERSION_PICKLE_FILE):
+    print "Loading saved version info..."
+    with open(VERSION_PICKLE_FILE, 'rb') as f:
+        versions = pickle.load(f)
+else:
+    print "Extracting and saving version info..."
     versions = [p['version'] for p in package_info]
     with open(VERSION_PICKLE_FILE, 'wb') as o:
         pickle.dump(versions, o)
-else:
-    with open(VERSION_PICKLE_FILE, 'rb') as f:
-        versions = pickle.load(f)
 
 total_versions = len(versions)
 matches = 0.00