z3c.pypimirror
==============

>>> import os, sys

First we try to get a list from pypi, to test xmlrpc connection.

>>> packageprefix = 'zope.app.c'
>>> from z3c.pypimirror.mirror import PypiPackageList, Mirror, Package
>>> pypi_pl = PypiPackageList()
>>> pypi_list = pypi_pl.list()
>>> pypi_list2 = pypi_pl.list([packageprefix + '*'])
>>> False not in [item.startswith(packageprefix) for item in pypi_list2]
True
>>> len(pypi_list) > len(pypi_list2)
True

If we got an list from pypi we try parse the output and download a
file.

>>> mirror = Mirror(join(sample_buildout, "mirror"))
>>> packagename = pypi_list2[0]
>>> package = Package(packagename)
>>> mirrorpackage = mirror.package(packagename)
>>> file = package.ls()[0]
>>> data = package.get(file)
>>> mirrorpackage.write(file[1], data)
>>> packagename in os.listdir(join(sample_buildout, 'mirror'))
True

Now we create a `index.html` for the package.

>>> mirrorpackage.index_html('http://pypi.python.org/simple')
>>> path_package_index = mirrorpackage.path('index.html')
>>> packagename in open(path_package_index, 'r').read()
True

# Is the following intemded to work?
#
#Now we create a `index2.html` for the mirror.
#
#>>> mirror.index_html()
#>>> path_index = join(mirror.base_path, 'index2.html')
#>>> packagename in open(path_index, 'r').read()
#True

If a file is not on the mirror and cleanup is activated it will
be removed. First we add a dummy file.

>>> write(mirrorpackage.path(), 'dummy.egg',
... """
... Banane
... """)
>>> ls(mirrorpackage.path())
-  dummy.egg
...
>>> mirrorpackage.cleanup([file,])
>>> 'dummy.egg' not in os.listdir(mirrorpackage.path())
True


Now we're trying everything in concert

First cleanup a bit

>>> remove(mirrorpackage.path())
>>> packagename in os.listdir(join(sample_buildout, 'mirror'))
False

Create a configuration involving our mirror path

>>> cfg = join (mirror.base_path, 'mirror.cfg')
>>> write(cfg, """
... [DEFAULT]
... mirror_file_path = %s
... package_matches =
...     %s
... """ % (mirror.base_path, packagename))

Generate a script (don't know how to use the one generated by buildout)

>>> write ('pypimirror.py',
... '''
... import sys
... sys.path[:] = [
...   "%s"
... ]
... from z3c.pypimirror.mirror import run
... run()
... ''' % '",\n  "'.join (sys.path))


