-
Notifications
You must be signed in to change notification settings - Fork 112
/
pypi.py
62 lines (49 loc) · 2.01 KB
/
pypi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import datetime
import logging
import xmlrpclib
from localshop.packages import models
logger = logging.getLogger(__name__)
def get_package_urls(name, package=None):
"""Retrieve metadata information for the given package name"""
if not package:
package = models.Package(name=name)
releases = {}
else:
releases = package.get_all_releases()
client = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
versions = client.package_releases(package.name, True)
# package_releases() method is case-sensitive, if nothing found
# then we search for it
# XXX: Ask pypi to make it case-insensitive?
if not versions:
for item in client.search({'name': name}):
if name.lower() == item['name'].lower():
package.name = name = item['name']
break
else:
logger.info("No packages found matching %r", name)
return
# Retry retrieving the versions with the new/correct name
versions = client.package_releases(package.name, True)
# Save the package if it is new
if not package.pk:
package.save()
for version in versions:
release, files = releases.get(version, (None, {}))
if not release:
release = models.Release(package=package, version=version)
release.save()
release_files = client.package_urls(package.name, release.version)
for info in release_files:
release_file = files.get(info['filename'])
if not release_file:
release_file = models.ReleaseFile(
release=release, filename=info['filename'])
release_file.python_version = info['python_version']
release_file.filetype = info['packagetype']
release_file.url = info['url']
release_file.size = info['size']
release_file.md5_digest = info['md5_digest']
release_file.save()
package.update_timestamp = datetime.datetime.utcnow()
return package