This repository has been archived by the owner on Feb 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for creating a Zope Toolkit index.
- Loading branch information
Showing
6 changed files
with
117 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |