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

@ -1,10 +1,18 @@
#! /usr/bin/env python
"""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")
from pypiserver import bottle, __version__, app
sys.modules["bottle"] = bottle
from bottle import run, server_names
@ -32,7 +40,7 @@ def _parse_version_parts(s):
if part in ['', '.']:
continue
if part[:1] in '0123456789':
yield part.zfill(8) # pad for numeric comparison
yield part.zfill(8) # pad for numeric comparison
else:
yield '*' + part
@ -51,7 +59,9 @@ def parse_version(s):
# -- 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(
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)
class pkgfile(object):
class PkgFile(object):
def __init__(self, **kw):
self.__dict__.update(kw)
@ -122,11 +132,11 @@ def listdir(root):
continue
res = guess_pkgname_and_version(x)
if not res:
##Seems the current file isn't a proper package
# #Seems the current file isn't a proper package
continue
pkgname, version = res
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,
version=version,
parsed_version=parse_version(version))
@ -409,6 +419,7 @@ def main(argv=None):
if command == "update":
packages = frozenset(itertools.chain(*[listdir(r) for r in roots]))
from pypiserver import manage
manage.update(packages, update_directory, update_dry_run, stable_only=update_stable_only)
return
@ -424,7 +435,8 @@ def main(argv=None):
cache_control=cache_control,
)
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()
run(app=a, host=host, port=port, server=server)

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

@ -1,7 +1,7 @@
#! /usr/bin/env py.test
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
@ -13,7 +13,7 @@ def touch_files(root, files):
def pkgfile_from_path(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))