update only to stable (i.e. non alpha, beta, rc, dev) versions

...unless -u is specified
This commit is contained in:
Ralf Schmitt 2011-11-07 22:59:55 +01:00
parent d1c05dfe9e
commit 1b2bb1a924
2 changed files with 30 additions and 6 deletions

@ -222,7 +222,8 @@ The following additional options can be specified with -U:
the directory which contains the latest version of the package to
be updated.
-u
allow updating to unstable version (alpha, beta, rc, dev versions)
Visit http://pypi.python.org/pypi/pypiserver for more information.
"""
@ -240,9 +241,10 @@ def main(argv=None):
server = None
update_dry_run = True
update_directory = None
update_stable_only = True
try:
opts, roots = getopt.getopt(argv[1:], "i:p:r:d:Uxh", ["interface=", "port=", "root=", "server=", "disable-fallback", "version", "help"])
opts, roots = getopt.getopt(argv[1:], "i:p:r:d:Uuxh", ["interface=", "port=", "root=", "server=", "disable-fallback", "version", "help"])
except getopt.GetoptError, err:
sys.exit("usage error: %s" % (err,))
@ -266,6 +268,8 @@ def main(argv=None):
command = "update"
elif k == "-x":
update_dry_run = False
elif k == "-u":
update_stable_only = False
elif k == "-d":
update_directory = v
elif k in ("-h", "--help"):
@ -288,7 +292,7 @@ def main(argv=None):
if command == "update":
from pypiserver import manage
manage.update(packages, update_directory, update_dry_run)
manage.update(packages, update_directory, update_dry_run, stable_only=update_stable_only)
return
server = server or "auto"

@ -10,7 +10,24 @@ class pkgfile(object):
self.version_info = pkg_resources.parse_version(self.version)
def find_updates(pkgset):
def is_stable_version(pversion):
for x in pversion:
if x.startswith("*final"):
return True
if x.startswith("*"):
return False
return False
def filter_stable_releases(releases):
res = []
for pversion, version in releases:
if is_stable_version(pversion):
res.append((pversion, version))
return res
def find_updates(pkgset, stable_only=True):
no_releases = set()
def write(s):
@ -38,6 +55,9 @@ def find_updates(pkgset):
releases = pypi.package_releases(pkgname)
releases = [(pkg_resources.parse_version(x), x) for x in releases]
if stable_only:
releases = filter_stable_releases(releases)
status = "."
if releases:
m = max(releases)
@ -61,8 +81,8 @@ def find_updates(pkgset):
return need_update
def update(pkgset, destdir=None, dry_run=False):
need_update = find_updates(pkgset)
def update(pkgset, destdir=None, dry_run=False, stable_only=True):
need_update = find_updates(pkgset, stable_only=stable_only)
for x in need_update:
print "# update", x.pkgname, "from", x.version, "to", x.latest_version