table-service_2.py 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. def _process_one_package(package_name, version):
  2. logger.info("Worker: Package:{} Version:{}".format(package_name, version))
  3. if not package_name or not version:
  4. logger.warn("Package_name or version was empty. Moving on as the queue had bad data")
  5. return
  6. # .6684 seconds to run. 74577 total packages
  7. package_info = PyPIPackageInformation.get_package_specific_version_info(package_name, version)
  8. if not package_info:
  9. logger.error("Worker: Package:{} Version:{} failed to get package info".format(package_name, version))
  10. return
  11. supports_python_2 = len([x for x in package_info['classifiers'] if x.startswith('Programming Language :: Python :: 2')]) > 0
  12. supports_python_3 = len([x for x in package_info['classifiers'] if x.startswith('Programming Language :: Python :: 3')]) > 0
  13. uploaded = package_info['uploaded']
  14. try:
  15. summary_entity = table_service.get_entity(config.PACKAGE_SUMMARY_TABLENAME, package_name, STATIC_ROW_KEY)
  16. except:
  17. # we don't have a summary for this entry.
  18. summary_entity = {
  19. 'PartitionKey':package_name, 'RowKey':STATIC_ROW_KEY, 'First_Published':None,
  20. 'Python2_Start':None, 'Python2_End':None, 'Python3_Start':None
  21. }
  22. table_service.insert_or_replace_entity(config.PACKAGE_SUMMARY_TABLENAME, package_name, STATIC_ROW_KEY, summary_entity)
  23. summary_entity = table_service.get_entity(config.PACKAGE_SUMMARY_TABLENAME, package_name, STATIC_ROW_KEY)
  24. # set fields using upload. Upload is none if the version has never been uploaded
  25. # Basically just filter out packages that never have content from our records.
  26. if uploaded is not None:
  27. if not hasattr(summary_entity, 'First_Published') or summary_entity.First_Published is None or summary_entity.First_Published > uploaded:
  28. # if the published date is empty or later than the current release we
  29. # are viewing update
  30. summary_entity.First_Published = uploaded
  31. if supports_python_2 and \
  32. (not hasattr(summary_entity, 'Python2_Start') or summary_entity.Python2_Start is None or summary_entity.Python2_Start > uploaded):
  33. # if the published date is empty or later than the date and it supports
  34. # python 2
  35. summary_entity.Python2_Start = uploaded
  36. if supports_python_2 and hasattr(summary_entity, 'Python2_End') and summary_entity.Python2_End is not None and summary_entity.Python2_End < uploaded:
  37. # we support python2 but it is after the date we thought python 2
  38. # support ended we must not have really ended
  39. summary_entity.Python2_End = None
  40. elif hasattr(summary_entity, 'Python2_Start') and hasattr(summary_entity, 'Python2_End') and \
  41. summary_entity.Python2_Start is not None and summary_entity.Python2_End is not None and \
  42. (summary_entity.Python2_End > uploaded and summary_entity.Python2_Start < uploaded):
  43. # if we don't support python2, and we have started supporting python2
  44. # at some point
  45. # and if the date we are saying we ended is after the start
  46. summary_entity.Python2_End = uploaded
  47. if supports_python_3 and \
  48. (not hasattr(summary_entity, 'Python3_Start') or summary_entity.Python3_Start is None or summary_entity.Python3_Start > uploaded):
  49. # if the published date is empty or later than the current release we
  50. # are viewing update
  51. summary_entity.Python3_Start = uploaded
  52. version_entity = _insert_entity_to_package_version_table(package_name, version, supports_python_2, supports_python_3, package_info['downloads'], uploaded)
  53. summary_entity = table_service.insert_or_replace_entity(config.PACKAGE_SUMMARY_TABLENAME, package_name, STATIC_ROW_KEY, summary_entity)