1. anatoly techtonik
  2. python-stdlib

Commits

anatoly techtonik  committed 1663920

Caching for issue files

  • Participants
  • Parent commits e5bb023
  • Branches default

Comments (0)

Files changed (1)

File modstats.py

View file
 
 """
 
+from os import makedirs
+from os.path import abspath, exists, dirname
+from sys import version_info
+
+PY3K = version_info >= (3, 0)
+if PY3K:
+  import urllib.request as urllib
+  import xmlrpc.client as xmlrpclib
+else:
+  import urllib
+  import xmlrpclib
+  print('NOTE: MinGW unpack requires `lzma` module available from '
+        'Python 3.3+')
+
+ROOT = abspath(dirname(__file__))
+CACHE = ROOT + '/.filecache/'
+if not exists(CACHE):
+  print("Creating cache directory")
+  makedirs(CACHE)
+
 # -- 1. Get list of all open issues with patches --
 #
 # Using http://roundup.sourceforge.net/docs/xmlrpc.html
 #   [ ] filter patches
 #
 
-try:
-  import xmlrpclib
-except ImportError:  # Python 3
-  import xmlrpc.client as xmlrpclib
-
 bpo = xmlrpclib.ServerProxy('http://bugs.python.org', allow_none=True)
 
 open_status = [bpo.lookup('status', x) for x in bpo.list('status')
 files_attached = 0
 files_patches = []
 
+# [x] implement caching for issue files
+#  [ ] check what urlretrieve does for incomplete files
+def fileget(number):
+  if not exists(CACHE + number):
+    print('  ' + number)
+    urllib.urlretrieve('http://bugs.python.org/file' + number + '/', CACHE + number)
+  else:
+    print('  ' + number + ' (cached)')
+      
+
+issue_patches = {}  # 'number' => []
 for issue in open_issues:
   print(issue)
-  for filename in bpo.display('issue'+issue, 'files')['files']:
-    print("  " + filename)
+  issue_patches[issue] = bpo.display('issue'+issue, 'files')['files']
+  for filen in issue_patches[issue]:
     files_attached += 1
+    fileget(filen)