Skip to content

Commit

Permalink
rollback changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mosquito committed Apr 7, 2017
1 parent 74c442e commit 3cd4e15
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 45 deletions.
2 changes: 1 addition & 1 deletion pypi_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
("Dmitry Orlov", "me@mosquito.su")
]

version_info = (0, 4, '0dev')
version_info = (0, 3, 30)

__version__ = ".".join(map(str, version_info))
__author__ = ", ".join("{0} <{1}>".format(*author) for author in author_info)
Expand Down
45 changes: 7 additions & 38 deletions pypi_server/handlers/pypi/proxy/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# encoding: utf-8
import hashlib
import json
import logging
from copy import copy
from slimurl import URL
Expand All @@ -17,26 +16,6 @@
log = logging.getLogger(__name__)


def async_retrying(number, exceptions=(Exception,)):
def decorator(func):
@coroutine
def wrap(*args, **kwargs):
last_exc = None
for i in range(number):
try:
raise Return((yield func(*args, **kwargs)))
except Return:
raise
except exceptions as e:
log.exception("Error on attempt: %r", i)
last_exc = e

if last_exc:
raise last_exc
return wrap
return decorator


def normalize_package_name(name):
return name.lower().replace("_", "-").replace(".", "-")

Expand All @@ -47,20 +26,19 @@ class PYPIClient(object):
THREAD_POOL = None
INDEX = None
XMLRPC = None
RPC_URL = None
LOCK = None

@classmethod
def configure(cls, backend, thread_pool):
cls.CLIENT = AsyncHTTPClient(io_loop=IOLoop.current())
cls.BACKEND = backend
cls.THREAD_POOL = thread_pool
cls.RPC_URL = copy(backend)(path="/pypi")
cls.XMLRPC = ServerProxy(str(cls.RPC_URL))
cls.XMLRPC = ServerProxy(
str(copy(backend)(path="/pypi")),
)
cls.LOCK = Lock()

@classmethod
@async_retrying(5)
@coroutine
@Cache(HOUR, files_cache=True, ignore_self=True)
def packages(cls):
Expand All @@ -76,7 +54,6 @@ def packages(cls):
raise Return(index)

@classmethod
@async_retrying(5)
@coroutine
@Cache(4 * HOUR, files_cache=True, ignore_self=True)
def search(cls, names, descriptions, operator="or"):
Expand All @@ -85,7 +62,6 @@ def search(cls, names, descriptions, operator="or"):
raise Return(result)

@classmethod
@async_retrying(5)
@coroutine
def exists(cls, name):
try:
Expand All @@ -100,7 +76,6 @@ def exists(cls, name):
raise Return(True)

@classmethod
@async_retrying(5)
@coroutine
def find_real_name(cls, name):
if not options.pypi_proxy:
Expand All @@ -117,7 +92,6 @@ def find_real_name(cls, name):
raise Return(real_name)

@classmethod
@async_retrying(5)
@coroutine
@Cache(4 * HOUR, files_cache=True, ignore_self=True)
def releases(cls, name):
Expand Down Expand Up @@ -145,20 +119,15 @@ def releases(cls, name):
raise Return(set(res))

@classmethod
@async_retrying(5)
@coroutine
@Cache(MONTH, files_cache=True, ignore_self=True)
def release_data(cls, name, version):
url = copy(cls.RPC_URL)
url.path_append(str(name), str(version), 'json')
log.info("Gathering info %s", url)

response = json.loads((yield cls.CLIENT.fetch(str(url))).body)
info = response['info']
files = response['urls']
info, files = yield [
cls.XMLRPC.release_data(str(name), str(version)),
cls.XMLRPC.release_urls(str(name), str(version))
]

download_url = info.get('download_url')

if download_url and not files:
try:
url = URL(download_url)
Expand Down
9 changes: 3 additions & 6 deletions pypi_server/handlers/pypi/simple/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import logging

from pypi_server.cache import Cache
from pypi_server.cache import Cache, HOUR
from pypi_server.timeit import timeit
from tornado.gen import coroutine, Return
from tornado.ioloop import IOLoop
Expand Down Expand Up @@ -100,11 +100,8 @@ def release_db_save(package, rel, version_info, release_files):
@timeit
@coroutine
def release_fetch(package, rel):
try:
version_info, release_files = yield PYPIClient.release_data(package.name, rel)
raise Return((yield release_db_save(package, rel, version_info, release_files)))
except:
log.exception("Error proccess %r %r", package, rel)
version_info, release_files = yield PYPIClient.release_data(package.name, rel)
raise Return((yield release_db_save(package, rel, version_info, release_files)))


@route(r'/simple/(?P<package>[\w\.\d\-\_]+)/?')
Expand Down

0 comments on commit 3cd4e15

Please sign in to comment.