forked from github.com/pypiserver
commit
47b80b414a
@ -249,7 +249,7 @@ Running ``pypi-server -h`` will print a detailed usage message::
|
||||
uses the ASCII contents of HTML_FILE as welcome message response.
|
||||
|
||||
-v
|
||||
enable INFO logging; repeate for more verbosity.
|
||||
enable INFO logging; repeat for more verbosity.
|
||||
|
||||
--log-conf <FILE>
|
||||
read logging configuration from FILE.
|
||||
|
@ -7,20 +7,21 @@ def app(root=None,
|
||||
fallback_url=None,
|
||||
authenticated=None,
|
||||
password_file=None,
|
||||
overwrite=False,
|
||||
log_req_frmt="%(bottle.request)s",
|
||||
log_res_frmt="%(status)s",
|
||||
log_err_frmt="%(body)s: %(exception)s \n%(traceback)s",
|
||||
overwrite=None,
|
||||
log_req_frmt=None,
|
||||
log_res_frmt=None,
|
||||
log_err_frmt=None,
|
||||
welcome_file=None,
|
||||
cache_control=None,
|
||||
):
|
||||
import sys, os
|
||||
import sys
|
||||
import os
|
||||
from pypiserver import core
|
||||
sys.modules.pop("pypiserver._app", None)
|
||||
__import__("pypiserver._app")
|
||||
_app = sys.modules["pypiserver._app"]
|
||||
|
||||
import bottle
|
||||
from . import bottle
|
||||
|
||||
if root is None:
|
||||
root = os.path.expanduser("~/packages")
|
||||
@ -55,7 +56,8 @@ def paste_app_factory(global_config, **local_conf):
|
||||
else:
|
||||
roots = None
|
||||
|
||||
redirect_to_fallback = local_conf.get("redirect_to_fallback", "").lower() in ("yes", "on", "1")
|
||||
redirect_to_fallback = local_conf.get(
|
||||
"redirect_to_fallback", "").lower() in ("yes", "on", "1")
|
||||
fallback_url = local_conf.get("fallback_url")
|
||||
password_file = local_conf.get("password_file")
|
||||
return app(root=roots, redirect_to_fallback=redirect_to_fallback, fallback_url=fallback_url, password_file=password_file)
|
||||
|
@ -12,20 +12,21 @@ try:
|
||||
except ImportError:
|
||||
from StringIO import StringIO as BytesIO
|
||||
|
||||
try: #PY3
|
||||
try: # PY3
|
||||
from urllib.parse import urljoin
|
||||
except ImportError: #PY2
|
||||
except ImportError: # PY2
|
||||
from urlparse import urljoin
|
||||
|
||||
from bottle import static_file, redirect, request, response, HTTPError, Bottle, template
|
||||
from pypiserver import __version__
|
||||
from pypiserver.core import listdir, find_packages, store, get_prefixes, exists
|
||||
from .bottle import static_file, redirect, request, response, HTTPError, Bottle, template
|
||||
from . import __version__
|
||||
from .core import listdir, find_packages, store, get_prefixes, exists
|
||||
|
||||
log = logging.getLogger('pypiserver.http')
|
||||
packages = None
|
||||
|
||||
|
||||
class Configuration(object):
|
||||
|
||||
def __init__(self):
|
||||
self.fallback_url = "http://pypi.python.org/simple"
|
||||
self.redirect_to_fallback = True
|
||||
@ -53,7 +54,8 @@ class auth(object):
|
||||
def protector(*args, **kwargs):
|
||||
if self.action in config.authenticated:
|
||||
if not request.auth or request.auth[1] is None:
|
||||
raise HTTPError(401, header={"WWW-Authenticate": 'Basic realm="pypi"'})
|
||||
raise HTTPError(
|
||||
401, header={"WWW-Authenticate": 'Basic realm="pypi"'})
|
||||
if not validate_user(*request.auth):
|
||||
raise HTTPError(403)
|
||||
return method(*args, **kwargs)
|
||||
@ -115,21 +117,23 @@ def configure(root=None,
|
||||
config.fallback_url = fallback_url
|
||||
config.cache_control = cache_control
|
||||
if password_file:
|
||||
from passlib.apache import HtpasswdFile
|
||||
from passlib.apache import HtpasswdFile # @UnresolvedImport
|
||||
config.htpasswdfile = HtpasswdFile(password_file)
|
||||
config.overwrite = overwrite
|
||||
|
||||
## Read welcome-msg from external file,
|
||||
# Read welcome-msg from external file,
|
||||
# or failback to the embedded-msg (ie. in standalone mode).
|
||||
#
|
||||
try:
|
||||
if not welcome_file:
|
||||
welcome_file = pkg_resources.resource_filename(__name__, "welcome.html") # @UndefinedVariable
|
||||
welcome_file = pkg_resources.resource_filename( # @UndefinedVariable
|
||||
__name__, "welcome.html") # @UndefinedVariable
|
||||
config.welcome_file = welcome_file
|
||||
with io.open(config.welcome_file, 'r', encoding='utf-8') as fd:
|
||||
config.welcome_msg = fd.read()
|
||||
except Exception:
|
||||
log.warning("Could not load welcome-file(%s)!", welcome_file, exc_info=1)
|
||||
log.warning(
|
||||
"Could not load welcome-file(%s)!", welcome_file, exc_info=1)
|
||||
if not config.welcome_msg:
|
||||
from textwrap import dedent
|
||||
config.welcome_msg = dedent("""\
|
||||
@ -167,7 +171,7 @@ def log_request():
|
||||
|
||||
@app.hook('after_request')
|
||||
def log_response():
|
||||
log.info(config.log_res_frmt, #vars(response)) ## DOES NOT WORK!
|
||||
log.info(config.log_res_frmt, # vars(response)) ## DOES NOT WORK!
|
||||
dict(
|
||||
response=response,
|
||||
status=response.status, headers=response.headers,
|
||||
@ -194,7 +198,8 @@ def root():
|
||||
except:
|
||||
numpkgs = 0
|
||||
|
||||
msg = config.welcome_msg + '\n' ## Ensure template() does not consider `msg` as filename!
|
||||
# Ensure template() does not consider `msg` as filename!
|
||||
msg = config.welcome_msg + '\n'
|
||||
return template(msg,
|
||||
URL=request.url,
|
||||
VERSION=__version__,
|
||||
@ -297,13 +302,15 @@ def simple(prefix=""):
|
||||
if not fp.endswith("/"):
|
||||
fp += "/"
|
||||
|
||||
files = [x.relfn for x in sorted(find_packages(packages(), prefix=prefix), key=lambda x: (x.parsed_version, x.relfn))]
|
||||
files = [x.relfn for x in sorted(find_packages(
|
||||
packages(), prefix=prefix), key=lambda x: (x.parsed_version, x.relfn))]
|
||||
if not files:
|
||||
if config.redirect_to_fallback:
|
||||
return redirect("%s/%s/" % (config.fallback_url.rstrip("/"), prefix))
|
||||
return HTTPError(404)
|
||||
|
||||
links = [(os.path.basename(f), urljoin(fp, "../../packages/%s" % f.replace("\\", "/"))) for f in files]
|
||||
links = [(os.path.basename(f), urljoin(fp, "../../packages/%s" %
|
||||
f.replace("\\", "/"))) for f in files]
|
||||
tmpl = """\
|
||||
<html>
|
||||
<head>
|
||||
@ -352,9 +359,11 @@ def server_static(filename):
|
||||
for x in entries:
|
||||
f = x.relfn.replace("\\", "/")
|
||||
if f == filename:
|
||||
response = static_file(filename, root=x.root, mimetype=mimetypes.guess_type(filename)[0])
|
||||
response = static_file(
|
||||
filename, root=x.root, mimetype=mimetypes.guess_type(filename)[0])
|
||||
if config.cache_control:
|
||||
response.set_header("Cache-Control", "public, max-age=%s" % config.cache_control)
|
||||
response.set_header(
|
||||
"Cache-Control", "public, max-age=%s" % config.cache_control)
|
||||
return response
|
||||
|
||||
return HTTPError(404)
|
||||
|
@ -242,7 +242,7 @@ pypi-server understands the following options:
|
||||
uses the ASCII contents of HTML_FILE as welcome message response.
|
||||
|
||||
-v
|
||||
enable verbose logging; repeate for more verbosity.
|
||||
enable verbose logging; repeat for more verbosity.
|
||||
|
||||
--log-file <FILE>
|
||||
write logging info into this FILE.
|
||||
@ -314,10 +314,10 @@ def main(argv=None):
|
||||
overwrite = False
|
||||
verbosity = 1
|
||||
log_file = None
|
||||
log_frmt = None
|
||||
log_req_frmt = None
|
||||
log_res_frmt = None
|
||||
log_err_frmt = None
|
||||
log_frmt = "g%(asctime)s|%(levelname)s|%(thread)d|%(message)s"
|
||||
log_req_frmt = "%(bottle.request)s"
|
||||
log_res_frmt = "%(status)s"
|
||||
log_err_frmt = "%(body)s: %(exception)s \n%(traceback)s"
|
||||
welcome_file = None
|
||||
cache_control = None
|
||||
|
||||
|
@ -4,15 +4,14 @@ from subprocess import call
|
||||
|
||||
from pypiserver import core
|
||||
|
||||
|
||||
if sys.version_info >= (3, 0):
|
||||
from xmlrpc.client import Server
|
||||
|
||||
def make_pypi_client(url):
|
||||
return Server(url)
|
||||
else:
|
||||
from xmlrpclib import Server, Transport
|
||||
import httplib
|
||||
from xmlrpclib import Transport # @UnresolvedImport
|
||||
import httplib # @UnresolvedImport
|
||||
import urllib
|
||||
|
||||
class ProxiedTransport(Transport):
|
||||
@ -29,7 +28,8 @@ else:
|
||||
return _http_connection(self.proxy)
|
||||
|
||||
def send_request(self, connection, handler, request_body):
|
||||
connection.putrequest("POST", 'http://%s%s' % (self.realhost, handler))
|
||||
connection.putrequest(
|
||||
"POST", 'http://%s%s' % (self.realhost, handler))
|
||||
|
||||
def send_host(self, connection, host):
|
||||
connection.putheader('Host', self.realhost)
|
||||
@ -38,7 +38,8 @@ else:
|
||||
http_proxy_url = urllib.getproxies().get("http", "")
|
||||
|
||||
if http_proxy_url:
|
||||
http_proxy_spec = urllib.splithost(urllib.splittype(http_proxy_url)[1])[0]
|
||||
http_proxy_spec = urllib.splithost(
|
||||
urllib.splittype(http_proxy_url)[1])[0]
|
||||
transport = ProxiedTransport()
|
||||
transport.set_proxy(http_proxy_spec)
|
||||
else:
|
||||
@ -98,7 +99,8 @@ def find_updates(pkgset, stable_only=True):
|
||||
|
||||
latest_pkgs = frozenset(filter_latest_pkgs(pkgset))
|
||||
|
||||
sys.stdout.write("checking %s packages for newer version\n" % len(latest_pkgs),)
|
||||
sys.stdout.write(
|
||||
"checking %s packages for newer version\n" % len(latest_pkgs),)
|
||||
need_update = set()
|
||||
|
||||
pypi = make_pypi_client("https://pypi.python.org/pypi/")
|
||||
@ -125,7 +127,8 @@ def find_updates(pkgset, stable_only=True):
|
||||
write("\n\n")
|
||||
|
||||
if no_releases:
|
||||
sys.stdout.write("no releases found on pypi for %s\n\n" % (", ".join(sorted(no_releases)),))
|
||||
sys.stdout.write("no releases found on pypi for %s\n\n" %
|
||||
(", ".join(sorted(no_releases)),))
|
||||
|
||||
return need_update
|
||||
|
||||
@ -133,7 +136,8 @@ def find_updates(pkgset, stable_only=True):
|
||||
def update(pkgset, destdir=None, dry_run=False, stable_only=True):
|
||||
need_update = find_updates(pkgset, stable_only=stable_only)
|
||||
for pkg in sorted(need_update, key=lambda x: x.pkgname):
|
||||
sys.stdout.write("# update %s from %s to %s\n" % (pkg.pkgname, pkg.replaces.version, pkg.version))
|
||||
sys.stdout.write("# update %s from %s to %s\n" %
|
||||
(pkg.pkgname, pkg.replaces.version, pkg.version))
|
||||
|
||||
cmd = ["pip", "-q", "install", "--no-deps", "-i", "https://pypi.python.org/simple",
|
||||
"-d", destdir or os.path.dirname(pkg.replaces.fn),
|
||||
|
Loading…
Reference in New Issue
Block a user