--- a/codesys-ide/scripts/helper.py +++ b/codesys-ide/scripts/helper.py @@ -3,6 +3,7 @@ ########################################################################################### import sys, os import shutil +from System.Net import WebClient class SearchBuild: def __init__(self): @@ -35,3 +36,38 @@ def doit(self, filename): artifacts = list() return artifacts + +# +# 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) + localname = os.path.join(downloaddir, "dl.library") + 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) + + +# +# Check if there is a *.requirements file, and install +# all requirements from there. The parameter is a library +# URL, while we are checking if a *.requirements file exists +# beside this library. +# +def install_requirements(library_filename, librarymanager): + reqfilename = os.path.splitext(library_filename)[0] + ".requirements" + + if os.path.isfile(reqfilename): + reqfile = open(reqfilename, "r") + + for req in reqfile: + install_library(req, librarymanager)