Example #1
0
def main():
    parser = argparse.ArgumentParser(
        description="A PYPI cache",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )
    parser.add_argument("prefix", help="Package prefix, e.g. /tmp/packages")
    parser.add_argument("--address", default="0.0.0.0", help="Address to bind to.")
    parser.add_argument("--port", default=8080, type=int, help="Port to listen on.")
    parser.add_argument("--debug", default=False, action="store_true", help="Turn on debugging logging and output.")
    parser.add_argument("--reload", default=False, action="store_true", help="Turn on automatic reloading on code changes.")
    parser.add_argument("--processes", default=1, type=int, help="Number of processes to run")
    parser.add_argument("--upstream", default="http://pypi.python.org/", help="Upstream package server to use")
    args = parser.parse_args()

    loglevel = logging.DEBUG if args.debug else logging.INFO

    logging.basicConfig(
        level=loglevel,
        format="%(asctime)s [%(levelname)s] [%(processName)s-%(threadName)s] [%(name)s] [%(filename)s:%(lineno)d] %(message)s",
        datefmt="%Y-%m-%d %H:%M:%S%z"
    )
    logging.info("Debugging: {0!r}".format(args.debug))
    logging.info("Reloading: {0!r}".format(args.reload))

    pypi_server = pypi.PyPI(pypi_server=args.upstream)
    package_store = disk.DiskPackageStore(args.prefix)
    package_cache = cache.PackageCache(package_store, pypi_server)
    app = server.configure_app(pypi_server, package_store, package_cache, debug=args.debug)
    app.run(host=args.address, port=args.port, debug=args.debug, use_reloader=args.reload, processes=args.processes)
Example #2
0
 def setUp(self):
     self.mock_packagecache = mock.Mock(spec=cache.PackageCache)
     self.mock_packagestore = mock.Mock(spec=disk.DiskPackageStore)
     self.mock_pypi = mock.Mock(spec=pypi.PyPI)
     self.app = TestApp(
         server.configure_app(self.mock_pypi,
                              self.mock_packagestore,
                              self.mock_packagecache,
                              testing=True))
Example #3
0
 def setUp(self):
     self.mock_packagecache = mock.Mock(spec=cache.PackageCache)
     self.mock_packagestore = mock.Mock(spec=disk.DiskPackageStore)
     self.mock_pypi = mock.Mock(spec=pypi.PyPI)
     self.app = TestApp(server.configure_app(self.mock_pypi, self.mock_packagestore, self.mock_packagecache, testing=True))
Example #4
0
# ensure the virtualenv for this instance is added
python = 'python%d.%d' % (sys.version_info[0], sys.version_info[1])
site.addsitedir(
    path.join(vcs_root_dir, relative_ve_dir, 'lib', python, 'site-packages'))

sys.path.append(path.join(vcs_root_dir, relative_django_dir))

class Config(object):
	debug = True
	reload = False
	prefix = '/var/cache/pypicache'
args = Config()

import logging
loglevel = logging.DEBUG if args.debug else logging.INFO

logging.basicConfig(
    level=loglevel,
    format="%(asctime)s [%(levelname)s] [%(processName)s-%(threadName)s] [%(name)s] [%(filename)s:%(lineno)d] %(message)s",
    datefmt="%Y-%m-%d %H:%M:%S%z"
)
logging.info("Debugging: {0!r}".format(args.debug))
logging.info("Reloading: {0!r}".format(args.reload))

from pypicache import cache, disk, pypi, server
pypi_server = pypi.PyPI()
package_store = disk.DiskPackageStore(args.prefix)
package_cache = cache.PackageCache(package_store, pypi_server)
application = server.configure_app(pypi_server, package_store, package_cache, debug=args.debug)