Thanks @jelle for the ideas I got from snippet [#18]. But as the snippet from @jelle was not complete, yet, a lot of transfer knowledge was necessary to use it. So after I implemented it by myself, I thought, that I should add my version here also.
It acts on the primary project. So you should open the project before calling this function.
And it uses WebClient from DotNet, because the "request" module, which was referenced in [#18] was not available.
import os, re from System.Net import WebClient # # Install a library from a URL (starting with http(s)) # def install_library(url, librarymanager): if not url.startswith("http"): return downloaddir = os.path.join(os.environ["USERPROFILE"], "downloads") if not os.path.exists(downloaddir): os.makedirs(downloaddir) basename, extension = os.path.splitext(url) localname = os.path.join(downloaddir, "dl" + extension) print("*** download %s to %s\n" % (url, localname)) web_client = WebClient() web_client.DownloadFile(url, localname) repo = librarymanager.repositories[0] print("*** installing %s\n" % url) librarymanager.install_library (localname, repo, True) # # search for missing libraries in current primary project # def install_missing_libraries(librarymanager): proj = projects.primary # compile a regular expression to match lib placeholders p = re.compile('[^,]+, [^(]+\([^)]+\)') # search for libman objects = proj.get_children(recursive=True) for object in objects: if object.is_libman: for libref in iter(object): if libref.is_placeholder: if libref.effective_resolution is None and libref.default_resolution is not None: libInfo = str(libref.default_resolution) m = re.findall('([^,]+), ([^(]+) \(([^)]+)\)', libInfo) if len(m) > 0: libname, libversion, libvendor = m[0] indexurl = "https://store.codesys.com/CODESYSLibs/%s/%s/%s/index" % (libvendor, libname, libversion) web_client = WebClient() try: filename = web_client.DownloadString(indexurl).rstrip() except: filename = None if filename != None: liburl = "https://store.codesys.com/CODESYSLibs/%s/%s/%s/%s" % (libvendor, libname, libversion, filename) install_library(liburl, librarymanager)
The function can be called like this:
install_missing_libraries(librarymanager)
The variable "librarymanager" is implicitly available in python scripts, running in CODESYS.
Diff: