Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
Added support for creating a Zope Toolkit index.
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed Jun 26, 2010
1 parent 9593e83 commit 0daa973
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 53 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
0.4 - unreleased
----------------

- Added support for creating a Zope Toolkit index.

- Update ``package_urls`` to ``release_urls`` as specified in
http://wiki.python.org/moin/PyPiXmlRpc.

Expand Down
10 changes: 6 additions & 4 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ Introduction
============

``zope.z2releases`` is used to generated a PyPI compatible index with
references to all pinned package versions based on the ``versions.cfg``
configuration of the Zope 2 package.
references to all pinned package versions based on a ``versions.cfg``.

It can handle both a Zope 2 release as well as a Zope Toolkit release.

Usage
=====

To generate an index, use::

z2_kgs tags/2.12.1 /srv/index/2.12.1
z2_kgs branches/2.12 /srv/index/2.12
z2_kgs tags/2.12.1 /srv/Zope2/index/2.12.1

ztk_kgs tags/1.0a1 /srv/zopetoolkit/index/1.0a1
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

setup(name='zope.z2release',
version=version,
description="Zope 2 release helper",
description="Zope release helper",
long_description=open("README.txt").read() + "\n" +
open("CHANGES.txt").read(),
classifiers=[
"Programming Language :: Python",
],
keywords='',
author='Andreas Jung',
author_email='info@zopyx.com',
author='Zope Foundation',
author_email='zope-dev@zope.org',
url='http://pypi.python.org/pypi/zope.z2release',
license='ZPL',
packages=find_packages(exclude=['ez_setup']),
Expand All @@ -23,6 +23,7 @@
'setuptools',
],
entry_points=dict(console_scripts=[
'z2_kgs=zope.z2release.cli:main'
'z2_kgs=zope.z2release.cli:main',
'ztk_kgs=zope.z2release.ztk:main'
]),
)
49 changes: 4 additions & 45 deletions zope/z2release/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,14 @@

import os
import sys
import urlparse
import urllib
from xmlrpclib import Server
from ConfigParser import RawConfigParser as ConfigParser


server = None


class CasePreservingConfigParser(ConfigParser):

def optionxform(self, option):
return option # don't flatten case!


def write_index(package, version, dirname):
print >>sys.stderr, 'Package %s==%s' % (package, version)
dest_dir = os.path.join(dirname, package)
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
index_html = os.path.join(dest_dir, 'index.html')

fp = file(index_html, 'w')
print >>fp, '<html><body>'
lst = server.release_urls(package, version)
if lst:
# package hosted on PyPI
for d in lst:
link = '<a href="%s">%s</a>' % (d['url'], d['filename'])
print >>fp, link
print >>fp, '<br/>'
else:
# for externally hosted packages we need to rely on the
# download_url metadata
rel_data = server.release_data(package, version)
download_url = rel_data['download_url']
if download_url == 'UNKNOWN':
raise RuntimeError('Incorrect download_url for package %s' % package)
filename = os.path.basename(urlparse.urlparse(download_url)[2])
link = '<a href="%s">%s</a>' % (download_url, filename)
print >>fp, link

print >>fp, '</body></html>'
fp.close()
from zope.z2release.utils import CasePreservingConfigParser
from zope.z2release.utils import write_index


def main():
global server

if len(sys.argv) != 3:
print 'Usage: z2_kgs <tag-name> <destination-dirname>'
print 'Example: z2_kgs tags/2.12.1 /var/www/download.zope.org/Zope2/index/2.12.1/'
Expand All @@ -84,12 +43,12 @@ def main():

server = Server('http://pypi.python.org/pypi')

write_index('Zope2', version, dirname)
write_index(server, 'Zope2', version, dirname)
for package in CP.options('versions'):
version = CP.get('versions', package)
if '#' in version:
version = version.split('#')[0].strip()
write_index(package, version, dirname)
write_index(server, package, version, dirname)

if __name__ == '__main__':
main()
42 changes: 42 additions & 0 deletions zope/z2release/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
import sys
import urlparse

from ConfigParser import RawConfigParser as ConfigParser


class CasePreservingConfigParser(ConfigParser):

def optionxform(self, option):
return option # don't flatten case!


def write_index(server, package, version, dirname):
print >>sys.stderr, 'Package %s==%s' % (package, version)
dest_dir = os.path.join(dirname, package)
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
index_html = os.path.join(dest_dir, 'index.html')

fp = file(index_html, 'w')
print >>fp, '<html><body>'
lst = server.release_urls(package, version)
if lst:
# package hosted on PyPI
for d in lst:
link = '<a href="%s">%s</a>' % (d['url'], d['filename'])
print >>fp, link
print >>fp, '<br/>'
else:
# for externally hosted packages we need to rely on the
# download_url metadata
rel_data = server.release_data(package, version)
download_url = rel_data['download_url']
if download_url == 'UNKNOWN':
raise RuntimeError('Incorrect download_url for package %s' % package)
filename = os.path.basename(urlparse.urlparse(download_url)[2])
link = '<a href="%s">%s</a>' % (download_url, filename)
print >>fp, link

print >>fp, '</body></html>'
fp.close()
58 changes: 58 additions & 0 deletions zope/z2release/ztk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""
Generate an index file based on the ztk-versions.cfg file of the Zope Toolkit
in order to provide a version specific index page generated to be used
in combination with easy_install -i <some_url>
Usage:
cli.py tags/1.0a1 /tmp/index/1.0a1
cli.py branches/1.0 /tmp/index/1.0
"""

import os
import sys
import urllib
from xmlrpclib import Server

from zope.z2release.utils import CasePreservingConfigParser
from zope.z2release.utils import write_index


def main():
if len(sys.argv) != 3:
print 'Usage: ztk_kgs <tag-name> <destination-dirname>'
print 'Example: ztk_kgs tags/1.0a1 /var/www/download.zope.org/zopetoolkit/index/1.0a1/'
sys.exit(1)

tag = sys.argv[1]
dirname = sys.argv[2]
if not os.path.exists(dirname):
print >>sys.stderr, 'Creating index directory: %s' % dirname
os.makedirs(dirname)

version = tag.split('/')[-1]
versions_url = 'http://svn.zope.org/*checkout*/zopetoolkit/%s/ztk-versions.cfg' % tag
print >>sys.stderr, 'Fetching %s' % versions_url
data = urllib.urlopen(versions_url).read()
version_file = os.path.join(dirname, 'ztk-versions.cfg')
file(version_file, 'w').write(data)

app_versions_url = 'http://svn.zope.org/*checkout*/zopetoolkit/%s/zopeapp-versions.cfg' % tag
print >>sys.stderr, 'Fetching %s' % app_versions_url
data = urllib.urlopen(app_versions_url).read()
app_version_file = os.path.join(dirname, 'zopeapp-versions.cfg')
file(app_version_file, 'w').write(data)

CP = CasePreservingConfigParser()
CP.read(version_file)

server = Server('http://pypi.python.org/pypi')

for package in CP.options('versions'):
version = CP.get('versions', package)
if '#' in version:
version = version.split('#')[0].strip()
write_index(server, package, version, dirname)

if __name__ == '__main__':
main()

0 comments on commit 0daa973

Please sign in to comment.