release.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # -*- coding: utf-8 -*-
  2. # (The MIT License)
  3. #
  4. # Copyright (c) 2014 Kura
  5. #
  6. # Permission is hereby granted, free of charge, to any person obtaining a copy
  7. # of this software and associated documentation files (the 'Software'), to deal
  8. # in the Software without restriction, including without limitation the rights
  9. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. # copies of the Software, and to permit persons to whom the Software is
  11. # furnished to do so, subject to the following conditions:
  12. #
  13. # The above copyright notice and this permission notice shall be included in
  14. # all copies or substantial portions of the Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. # SOFTWARE.
  23. from datetime import datetime
  24. class Release(object):
  25. """
  26. A release file from PyPI.
  27. :param release_id: A release id.
  28. :param pypi_dict: A dictionary of a release file.
  29. """
  30. def __init__(self, release_id, pypi_dict):
  31. self._release = pypi_dict
  32. self._release['release_id'] = release_id
  33. def __repr__(self):
  34. return "<Release {0}>".format(self.release_id)
  35. @property
  36. def release_id(self):
  37. """
  38. >>> package = yarg.get('yarg')
  39. >>> v = "0.1.0"
  40. >>> r = package.release(v)
  41. >>> r[0].release_id
  42. u'0.1.0'
  43. """
  44. return self._release['release_id']
  45. @property
  46. def uploaded(self):
  47. """
  48. >>> package = yarg.get('yarg')
  49. >>> v = "0.1.0"
  50. >>> r = package.release(v)
  51. >>> r.uploaded
  52. datetime.datime(2014, 8, 7, 21, 26, 19)
  53. """
  54. return datetime.strptime(self._release['upload_time'],
  55. '%Y-%m-%dT%H:%M:%S')
  56. @property
  57. def python_version(self):
  58. """
  59. >>> package = yarg.get('yarg')
  60. >>> v = "0.1.0"
  61. >>> r = package.release(v)
  62. >>> r.python_version
  63. u'2.7'
  64. """
  65. return self._release['python_version']
  66. @property
  67. def url(self):
  68. """
  69. >>> package = yarg.get('yarg')
  70. >>> v = "0.1.0"
  71. >>> r = package.release(v)
  72. >>> r.url
  73. u'https://pypi.python.org/packages/2.7/y/yarg/yarg...'
  74. """
  75. return self._release['url']
  76. @property
  77. def md5_digest(self):
  78. """
  79. >>> package = yarg.get('yarg')
  80. >>> v = "0.1.0"
  81. >>> r = package.release(v)
  82. >>> r.md5_digest
  83. u'bec88e1c1765ca6177360e8f37b44c5c'
  84. """
  85. return self._release['md5_digest']
  86. @property
  87. def filename(self):
  88. """
  89. >>> package = yarg.get('yarg')
  90. >>> v = "0.1.0"
  91. >>> r = package.release(v)
  92. >>> r.filename
  93. u'yarg-0.1.0-py27-none-any.whl'
  94. """
  95. return self._release['filename']
  96. @property
  97. def size(self):
  98. """
  99. >>> package = yarg.get('yarg')
  100. >>> v = "0.1.0"
  101. >>> r = package.release(v)
  102. >>> r.size
  103. 52941
  104. """
  105. return self._release['size']
  106. @property
  107. def package_type(self):
  108. """
  109. >>> package = yarg.get('yarg')
  110. >>> v = "0.1.0"
  111. >>> r = package.release(v)
  112. >>> r.package_type
  113. u'wheel'
  114. """
  115. mapping = {'bdist_egg': u'egg', 'bdist_wheel': u'wheel',
  116. 'sdist': u'source'}
  117. ptype = self._release['packagetype']
  118. if ptype in mapping.keys():
  119. return mapping[ptype]
  120. return ptype
  121. @property
  122. def has_sig(self):
  123. """
  124. >>> package = yarg.get('yarg')
  125. >>> v = "0.1.0"
  126. >>> r = package.release(v)
  127. >>> r.has_sig
  128. True
  129. """
  130. return self._release['has_sig']