1
0
mirror of https://github.com/pypiserver/pypiserver synced 2024-11-09 16:45:51 +01:00

Merge pull request #73 from ankostis/PEP8

Pep8 changes
This commit is contained in:
Kostis Anagnostopoulos 2015-02-17 00:51:24 +01:00
commit 6be20d7d99
4 changed files with 45 additions and 22 deletions

@ -1,4 +1,11 @@
import sys, os, io, itertools, zipfile, mimetypes, logging, pkg_resources import sys
import os
import io
import itertools
import zipfile
import mimetypes
import logging
import pkg_resources
try: try:
from io import BytesIO from io import BytesIO
@ -18,7 +25,7 @@ log = logging.getLogger('pypiserver.http')
packages = None packages = None
class configuration(object): class Configuration(object):
def __init__(self): def __init__(self):
self.fallback_url = "http://pypi.python.org/simple" self.fallback_url = "http://pypi.python.org/simple"
self.redirect_to_fallback = True self.redirect_to_fallback = True
@ -26,7 +33,7 @@ class configuration(object):
self.welcome_file = None self.welcome_file = None
self.welcome_msg = None self.welcome_msg = None
config = configuration() config = Configuration()
def validate_user(username, password): def validate_user(username, password):
@ -97,7 +104,7 @@ def configure(root=None,
for r in roots: for r in roots:
try: try:
os.listdir(r) os.listdir(r)
except Exception: except OSError:
err = sys.exc_info()[1] err = sys.exc_info()[1]
sys.exit("Error: while trying to list %r: %s" % (r, err)) sys.exit("Error: while trying to list %r: %s" % (r, err))
@ -215,7 +222,7 @@ def update():
zip_data = content.file.read() zip_data = content.file.read()
try: try:
zf = zipfile.ZipFile(BytesIO(zip_data)) zf = zipfile.ZipFile(BytesIO(zip_data))
info = zf.getinfo('index.html') zf.getinfo('index.html')
except Exception: except Exception:
raise HTTPError(400, output="not a zip file") raise HTTPError(400, output="not a zip file")
return "" return ""
@ -283,8 +290,8 @@ def simple(prefix=""):
if config.redirect_to_fallback: if config.redirect_to_fallback:
return redirect("%s/%s/" % (config.fallback_url.rstrip("/"), prefix)) return redirect("%s/%s/" % (config.fallback_url.rstrip("/"), prefix))
return HTTPError(404) return HTTPError(404)
res = ["<html><head><title>Links for %s</title></head><body>\n" % prefix] res = ["<html><head><title>Links for %s</title></head><body>\n" % prefix,
res.append("<h1>Links for %s</h1>\n" % prefix) "<h1>Links for %s</h1>\n" % prefix]
for x in files: for x in files:
abspath = urljoin(fp, "../../packages/%s" % x.replace("\\", "/")) abspath = urljoin(fp, "../../packages/%s" % x.replace("\\", "/"))
@ -301,7 +308,8 @@ def list_packages():
if not fp.endswith("/"): if not fp.endswith("/"):
fp += "/" fp += "/"
files = [x.relfn for x in sorted(find_packages(packages()), key=lambda x: (os.path.dirname(x.relfn), x.pkgname, x.parsed_version))] files = [x.relfn for x in sorted(find_packages(packages()),
key=lambda x: (os.path.dirname(x.relfn), x.pkgname, x.parsed_version))]
res = ["<html><head><title>Index of packages</title></head><body>\n"] res = ["<html><head><title>Index of packages</title></head><body>\n"]
for x in files: for x in files:

@ -1,10 +1,18 @@
#! /usr/bin/env python #! /usr/bin/env python
"""minimal PyPI like server for use with pip/easy_install""" """minimal PyPI like server for use with pip/easy_install"""
import os, sys, getopt, re, mimetypes, warnings, itertools, logging import os
import sys
import getopt
import re
import mimetypes
import warnings
import itertools
import logging
warnings.filterwarnings("ignore", "Python 2.5 support may be dropped in future versions of Bottle") warnings.filterwarnings("ignore", "Python 2.5 support may be dropped in future versions of Bottle")
from pypiserver import bottle, __version__, app from pypiserver import bottle, __version__, app
sys.modules["bottle"] = bottle sys.modules["bottle"] = bottle
from bottle import run, server_names from bottle import run, server_names
@ -32,7 +40,7 @@ def _parse_version_parts(s):
if part in ['', '.']: if part in ['', '.']:
continue continue
if part[:1] in '0123456789': if part[:1] in '0123456789':
yield part.zfill(8) # pad for numeric comparison yield part.zfill(8) # pad for numeric comparison
else: else:
yield '*' + part yield '*' + part
@ -51,7 +59,9 @@ def parse_version(s):
# -- end of distribute's code # -- end of distribute's code
_archive_suffix_rx = re.compile(r"(\.zip|\.tar\.gz|\.tgz|\.tar\.bz2|-py[23]\.\d-.*|\.win-amd64-py[23]\.\d\..*|\.win32-py[23]\.\d\..*|\.egg)$", re.IGNORECASE) _archive_suffix_rx = re.compile(
r"(\.zip|\.tar\.gz|\.tgz|\.tar\.bz2|-py[23]\.\d-.*|\.win-amd64-py[23]\.\d\..*|\.win32-py[23]\.\d\..*|\.egg)$",
re.IGNORECASE)
wheel_file_re = re.compile( wheel_file_re = re.compile(
r"""^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?)) r"""^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))
@ -102,7 +112,7 @@ def is_allowed_path(path_part):
return not (p.startswith(".") or "/." in p) return not (p.startswith(".") or "/." in p)
class pkgfile(object): class PkgFile(object):
def __init__(self, **kw): def __init__(self, **kw):
self.__dict__.update(kw) self.__dict__.update(kw)
@ -122,11 +132,11 @@ def listdir(root):
continue continue
res = guess_pkgname_and_version(x) res = guess_pkgname_and_version(x)
if not res: if not res:
##Seems the current file isn't a proper package # #Seems the current file isn't a proper package
continue continue
pkgname, version = res pkgname, version = res
if pkgname: if pkgname:
yield pkgfile(fn=fn, root=root, relfn=fn[len(root) + 1:], yield PkgFile(fn=fn, root=root, relfn=fn[len(root) + 1:],
pkgname=pkgname, pkgname=pkgname,
version=version, version=version,
parsed_version=parse_version(version)) parsed_version=parse_version(version))
@ -409,6 +419,7 @@ def main(argv=None):
if command == "update": if command == "update":
packages = frozenset(itertools.chain(*[listdir(r) for r in roots])) packages = frozenset(itertools.chain(*[listdir(r) for r in roots]))
from pypiserver import manage from pypiserver import manage
manage.update(packages, update_directory, update_dry_run, stable_only=update_stable_only) manage.update(packages, update_directory, update_dry_run, stable_only=update_stable_only)
return return
@ -424,7 +435,8 @@ def main(argv=None):
cache_control=cache_control, cache_control=cache_control,
) )
server = server or "auto" server = server or "auto"
sys.stdout.write("This is pypiserver %s serving %r on http://%s:%s\n\n" % (__version__, ", ".join(roots), host, port)) sys.stdout.write(
"This is pypiserver %s serving %r on http://%s:%s\n\n" % (__version__, ", ".join(roots), host, port))
sys.stdout.flush() sys.stdout.flush()
run(app=a, host=host, port=port, server=server) run(app=a, host=host, port=port, server=server)

@ -1,8 +1,10 @@
import sys
import sys, os import os
from pypiserver import core
from subprocess import call from subprocess import call
from pypiserver import core
if sys.version_info >= (3, 0): if sys.version_info >= (3, 0):
from xmlrpc.client import Server from xmlrpc.client import Server
@ -10,7 +12,8 @@ if sys.version_info >= (3, 0):
return Server(url) return Server(url)
else: else:
from xmlrpclib import Server, Transport from xmlrpclib import Server, Transport
import httplib, urllib import httplib
import urllib
class ProxiedTransport(Transport): class ProxiedTransport(Transport):
@ -79,7 +82,7 @@ def build_releases(pkg, versions):
for x in versions: for x in versions:
parsed_version = core.parse_version(x) parsed_version = core.parse_version(x)
if parsed_version > pkg.parsed_version: if parsed_version > pkg.parsed_version:
yield core.pkgfile(version=x, yield core.PkgFile(version=x,
parsed_version=parsed_version, parsed_version=parsed_version,
pkgname=pkg.pkgname, pkgname=pkg.pkgname,
replaces=pkg) replaces=pkg)

@ -1,7 +1,7 @@
#! /usr/bin/env py.test #! /usr/bin/env py.test
import pytest, py import pytest, py
from pypiserver.core import parse_version, pkgfile, guess_pkgname_and_version from pypiserver.core import parse_version, PkgFile, guess_pkgname_and_version
from pypiserver.manage import is_stable_version, build_releases, filter_stable_releases, filter_latest_pkgs from pypiserver.manage import is_stable_version, build_releases, filter_stable_releases, filter_latest_pkgs
@ -13,7 +13,7 @@ def touch_files(root, files):
def pkgfile_from_path(fn): def pkgfile_from_path(fn):
pkgname, version = guess_pkgname_and_version(fn) pkgname, version = guess_pkgname_and_version(fn)
return pkgfile(root=py.path.local(fn).parts()[1].strpath, return PkgFile(root=py.path.local(fn).parts()[1].strpath,
fn=fn, pkgname=pkgname, version=version, parsed_version=parse_version(version)) fn=fn, pkgname=pkgname, version=version, parsed_version=parse_version(version))