Diff of /codesys-ide/scripts/helper.py [ed9c30] .. [7c4eb7]  Maximize  Restore

Switch to side-by-side view

--- a/codesys-ide/scripts/helper.py
+++ b/codesys-ide/scripts/helper.py
@@ -1,7 +1,7 @@
 ###########################################################################################
 # Helper classes for the different CI commands
 ###########################################################################################
-import sys, os
+import sys, os, re
 import shutil
 from System.Net import WebClient
 
@@ -47,7 +47,8 @@
     downloaddir = os.path.join(os.environ["USERPROFILE"], "downloads")
     if not os.path.exists(downloaddir):
         os.makedirs(downloaddir)
-    localname = os.path.join(downloaddir, "dl.library")
+    basename, extension = os.path.splitext(url)
+    localname = os.path.join(downloaddir, "dl" + extension)
     print("*** download %s to %s\n" % (url, localname))
 
     web_client = WebClient()
@@ -71,3 +72,59 @@
         
         for req in reqfile:
             install_library(req, librarymanager)
+
+#
+# search for missing libraries in current primary project
+#
+def install_missing_libraries(proj, librarymanager):
+    print("*** install missing libraries")
+    
+    # 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:
+            print("*** found library manager")
+            for libref in iter(object):
+                libInfo = str(libref)
+                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)
+
+
+#
+# update all devices in project
+#
+def update_device(proj, device_repository):
+    print("*** update device")
+    
+    # search for devices to update
+    objects = proj.get_children(recursive=True)
+    for object in objects:
+        if object.is_device:
+            print("*** found device")
+            DeviceId = object.get_device_identification()
+            devices = device_repository.get_all_devices()
+            for device in devices:
+                if device.device_id.type == DeviceId.type and device.device_id.id == DeviceId.id:
+                    deviceToUpdate = device
+            if deviceToUpdate != None:
+                print ("*** found device to update %s" % deviceToUpdate.device_id)
+                object.update(device=deviceToUpdate.device_id)
+
+