def configure(root=None, redirect_to_fallback=True, fallback_url=None, password_file=None, overwrite=False): global packages if root is None: root = os.path.expanduser("~/packages") if fallback_url is None: fallback_url = "http://pypi.python.org/simple" if not isinstance(root, (list, tuple)): roots = [root] else: roots = root roots = [os.path.abspath(r) for r in roots] for r in roots: try: os.listdir(r) except Exception: err = sys.exc_info()[1] sys.exit("Error: while trying to list %r: %s" % (r, err)) packages = lambda: itertools.chain(*[listdir(r) for r in roots]) packages.root = roots[0] config.redirect_to_fallback = redirect_to_fallback config.fallback_url = fallback_url if password_file: from passlib.apache import HtpasswdFile config.htpasswdfile = HtpasswdFile(password_file) config.overwrite = overwrite
def iter_packages(self) -> t.Iterator[core.PkgFile]: """Iterate over packages in root directories.""" yield from ( itertools.chain.from_iterable( core.listdir(str(r)) for r in self.roots ) )
def configure(root=None, redirect_to_fallback=True, fallback_url=None, password_file=None, html=None): global packages global index if root is None: root = os.path.expanduser("~/packages") if fallback_url is None: fallback_url = "http://pypi.python.org/simple" if not isinstance(root, (list, tuple)): roots = [root] else: roots = root roots = [os.path.abspath(r) for r in roots] for r in roots: try: os.listdir(r) except Exception: err = sys.exc_info()[1] sys.exit("Error: while trying to list %r: %s" % (r, err)) packages = lambda: itertools.chain(*[listdir(r) for r in roots]) packages.root = roots[0] config.redirect_to_fallback = redirect_to_fallback config.fallback_url = fallback_url if password_file: from passlib.apache import HtpasswdFile config.htpasswdfile = HtpasswdFile(password_file) print 'html is ' + str(html) if html is None: index = pkg_resources.resource_string('pypiserver', 'html/index.html') else: with open(html, 'r') as html: index = html.read()
def test_listdir_bad_name(tmpdir): tmpdir.join("foo.whl").ensure() res = list(core.listdir(tmpdir.strpath)) assert res == []
def configure(root=None, redirect_to_fallback=True, fallback_url=None, authenticated=None, password_file=None, overwrite=False, log_req_frmt=None, log_res_frmt=None, log_err_frmt=None, welcome_file=None, cache_control=None, ): global packages log.info("Starting(%s)", dict(root=root, redirect_to_fallback=redirect_to_fallback, fallback_url=fallback_url, authenticated=authenticated, password_file=password_file, overwrite=overwrite, welcome_file=welcome_file, log_req_frmt=log_req_frmt, log_res_frmt=log_res_frmt, log_err_frmt=log_err_frmt, cache_control=cache_control)) config.authenticated = authenticated or [] if root is None: root = os.path.expanduser("~/packages") if fallback_url is None: fallback_url = "http://pypi.python.org/simple" if not isinstance(root, (list, tuple)): roots = [root] else: roots = root roots = [os.path.abspath(r) for r in roots] for r in roots: try: os.listdir(r) except OSError: err = sys.exc_info()[1] sys.exit("Error: while trying to list %r: %s" % (r, err)) packages = lambda: itertools.chain(*[listdir(r) for r in roots]) packages.root = roots[0] config.redirect_to_fallback = redirect_to_fallback config.fallback_url = fallback_url config.cache_control = cache_control if password_file: from passlib.apache import HtpasswdFile config.htpasswdfile = HtpasswdFile(password_file) config.overwrite = overwrite ## Read welcome-msg from external file, # or failback to the embedded-msg (ie. in standalone mode). # try: if not welcome_file: welcome_file = pkg_resources.resource_filename(__name__, "welcome.html") # @UndefinedVariable config.welcome_file = welcome_file with io.open(config.welcome_file, 'r', encoding='utf-8') as fd: config.welcome_msg = fd.read() except Exception: log.warning("Could not load welcome-file(%s)!", welcome_file, exc_info=1) if not config.welcome_msg: from textwrap import dedent config.welcome_msg = dedent("""\ <html><head><title>Welcome to pypiserver!</title></head><body> <h1>Welcome to pypiserver!</h1> <p>This is a PyPI compatible package index serving {{NUMPKGS}} packages.</p> <p> To use this server with pip, run the the following command: <blockquote><pre> pip install -i {{URL}}simple/ PACKAGE [PACKAGE2...] </pre></blockquote></p> <p> To use this server with easy_install, run the the following command: <blockquote><pre> easy_install -i {{URL}}simple/ PACKAGE </pre></blockquote></p> <p>The complete list of all packages can be found <a href="{{PACKAGES}}">here</a> or via the <a href="{{SIMPLE}}">simple</a> index.</p> <p>This instance is running version {{VERSION}} of the <a href="http://pypi.python.org/pypi/pypiserver">pypiserver</a> software.</p> </body></html>\ """) config.log_req_frmt = log_req_frmt config.log_res_frmt = log_res_frmt config.log_err_frmt = log_err_frmt