def details_library(entity_name, library_name): channel_request = request.args.get("channel", default=None, type=str) package = get_package(entity_name, channel_request, FIELDS) libraries = logic.process_libraries( publisher_api.get_charm_libraries(entity_name)) library_id = logic.get_library(library_name, libraries) if not library_id: abort(404) library = publisher_api.get_charm_library(entity_name, library_id) docstrings = logic.process_python_docs(library, module_name=library_name) if "source-code" in request.path[1:]: template = "details/libraries/source-code.html" else: template = "details/libraries/docstring.html" return render_template( template, entity_name=entity_name, package=package, libraries=libraries, library=library, docstrings=docstrings, channel_requested=channel_request, library_name=library_name, creation_date=logic.convert_date(library["created-at"]), )
def download_library(entity_name, library_name): lib_parts = library_name.split(".") if len(lib_parts) > 2: group_name = ".".join(lib_parts[:-2]) lib_name = "." + ".".join(lib_parts[-2:]) else: group_name = "others" lib_name = library_name libraries = logic.process_libraries( publisher_api.get_charm_libraries(entity_name)) library = next( (lib for lib in libraries.get(group_name, {}) if lib.get("name") == lib_name), None, ) if not library: abort(404) library = publisher_api.get_charm_library(entity_name, library["id"]) return Response( library["content"], mimetype="text/x-python", headers={ "Content-disposition": "attachment; " f"filename={library['library-name']}.py" }, )
def details_libraries(entity_name): channel_request = request.args.get("channel", default=None, type=str) package = get_package(entity_name, channel_request, FIELDS) libraries = logic.process_libraries( publisher_api.get_charm_libraries(entity_name)) return render_template( "details/libraries/introduction.html", entity_name=entity_name, package=package, libraries=libraries, channel_requested=channel_request, )