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

move parse_version to core

This commit is contained in:
Ralf Schmitt 2012-12-26 01:22:00 +01:00
parent c76390e333
commit 526045eb95
2 changed files with 30 additions and 32 deletions

@ -11,6 +11,35 @@ mimetypes.add_type("application/octet-stream", ".egg")
DEFAULT_SERVER = None DEFAULT_SERVER = None
# --- the following two functions were copied from distribute's pkg_resources module
component_re = re.compile(r'(\d+ | [a-z]+ | \.| -)', re.VERBOSE)
replace = {'pre': 'c', 'preview': 'c', '-': 'final-', 'rc': 'c', 'dev': '@'}.get
def _parse_version_parts(s):
for part in component_re.split(s):
part = replace(part, part)
if part in ['', '.']:
continue
if part[:1] in '0123456789':
yield part.zfill(8) # pad for numeric comparison
else:
yield '*' + part
yield '*final' # ensure that alpha/beta/candidate are before final
def parse_version(s):
parts = []
for part in _parse_version_parts(s.lower()):
if part.startswith('*'):
# remove trailing zeros from each series of numeric parts
while parts and parts[-1] == '00000000':
parts.pop()
parts.append(part)
return tuple(parts)
# -- 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\..*)$", 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\..*)$", re.IGNORECASE)
@ -40,8 +69,6 @@ class pkgfile(object):
def listdir(root): def listdir(root):
root = os.path.abspath(root) root = os.path.abspath(root)
from pypiserver.manage import parse_version
for dirpath, dirnames, filenames in os.walk(root): for dirpath, dirnames, filenames in os.walk(root):
dirnames[:] = [x for x in dirnames if is_allowed_path(x)] dirnames[:] = [x for x in dirnames if is_allowed_path(x)]
for x in filenames: for x in filenames:

@ -7,35 +7,6 @@ if sys.version_info >= (3, 0):
else: else:
from xmlrpclib import Server from xmlrpclib import Server
# --- the following two functions were copied from distribute's pkg_resources module
component_re = re.compile(r'(\d+ | [a-z]+ | \.| -)', re.VERBOSE)
replace = {'pre': 'c', 'preview': 'c', '-': 'final-', 'rc': 'c', 'dev': '@'}.get
def _parse_version_parts(s):
for part in component_re.split(s):
part = replace(part, part)
if part in ['', '.']:
continue
if part[:1] in '0123456789':
yield part.zfill(8) # pad for numeric comparison
else:
yield '*' + part
yield '*final' # ensure that alpha/beta/candidate are before final
def parse_version(s):
parts = []
for part in _parse_version_parts(s.lower()):
if part.startswith('*'):
# remove trailing zeros from each series of numeric parts
while parts and parts[-1] == '00000000':
parts.pop()
parts.append(part)
return tuple(parts)
# -- end of distribute's code
def is_stable_version(pversion): def is_stable_version(pversion):
for x in pversion: for x in pversion:
@ -79,7 +50,7 @@ def find_updates(pkgset, stable_only=True):
releases = pypi.package_releases(pkgname) releases = pypi.package_releases(pkgname)
releases = [(parse_version(x), x) for x in releases] releases = [(core.parse_version(x), x) for x in releases]
if stable_only: if stable_only:
releases = filter_stable_releases(releases) releases = filter_stable_releases(releases)