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

Switch to unified view

a/codesys-ide/scripts/helper.py b/codesys-ide/scripts/helper.py
1
###########################################################################################
1
###########################################################################################
2
# Helper classes for the different CI commands
2
# Helper classes for the different CI commands
3
###########################################################################################
3
###########################################################################################
4
import sys, os
4
import sys, os, re
5
import shutil
5
import shutil
6
from System.Net import WebClient
6
from System.Net import WebClient
7
7
8
class SearchBuild:
8
class SearchBuild:
9
    def __init__(self):
9
    def __init__(self):
...
...
45
        return
45
        return
46
    
46
    
47
    downloaddir = os.path.join(os.environ["USERPROFILE"], "downloads")
47
    downloaddir = os.path.join(os.environ["USERPROFILE"], "downloads")
48
    if not os.path.exists(downloaddir):
48
    if not os.path.exists(downloaddir):
49
        os.makedirs(downloaddir)
49
        os.makedirs(downloaddir)
50
    localname = os.path.join(downloaddir, "dl.library")
50
    basename, extension = os.path.splitext(url)
51
    localname = os.path.join(downloaddir, "dl" + extension)
51
    print("*** download %s to %s\n" % (url, localname))
52
    print("*** download %s to %s\n" % (url, localname))
52
53
53
    web_client = WebClient()
54
    web_client = WebClient()
54
    web_client.DownloadFile(url, localname)
55
    web_client.DownloadFile(url, localname)
55
    repo = librarymanager.repositories[0]
56
    repo = librarymanager.repositories[0]
...
...
69
    if os.path.isfile(reqfilename):
70
    if os.path.isfile(reqfilename):
70
        reqfile = open(reqfilename, "r")
71
        reqfile = open(reqfilename, "r")
71
        
72
        
72
        for req in reqfile:
73
        for req in reqfile:
73
            install_library(req, librarymanager)
74
            install_library(req, librarymanager)
74
75
76
#
77
# search for missing libraries in current primary project
78
#
79
def install_missing_libraries(proj, librarymanager):
80
    print("*** install missing libraries")
81
    
82
    # compile a regular expression to match lib placeholders
83
    p = re.compile('[^,]+, [^(]+\([^)]+\)')
84
    
85
    # search for libman
86
    objects = proj.get_children(recursive=True)
87
    for object in objects:
88
        if object.is_libman:
89
            print("*** found library manager")
90
            for libref in iter(object):
91
                libInfo = str(libref)
92
                if libref.is_placeholder:
93
                    if libref.effective_resolution is None and libref.default_resolution is not None:
94
                        libInfo = str(libref.default_resolution)
95
                        m = re.findall('([^,]+), ([^(]+) \(([^)]+)\)', libInfo)
96
                        if len(m) > 0:
97
                            libname, libversion, libvendor = m[0]
98
                            indexurl = "https://store.codesys.com/CODESYSLibs/%s/%s/%s/index" % (libvendor, libname, libversion)
99
                            web_client = WebClient()
100
                            try:
101
                                filename = web_client.DownloadString(indexurl).rstrip()
102
                            except:
103
                                filename = None
104
105
                            if filename != None:
106
                                liburl = "https://store.codesys.com/CODESYSLibs/%s/%s/%s/%s" % (libvendor, libname, libversion, filename)
107
                                install_library(liburl, librarymanager)
108
109
110
#
111
# update all devices in project
112
#
113
def update_device(proj, device_repository):
114
    print("*** update device")
115
    
116
    # search for devices to update
117
    objects = proj.get_children(recursive=True)
118
    for object in objects:
119
        if object.is_device:
120
            print("*** found device")
121
            DeviceId = object.get_device_identification()
122
            devices = device_repository.get_all_devices()
123
            for device in devices:
124
                if device.device_id.type == DeviceId.type and device.device_id.id == DeviceId.id:
125
                    deviceToUpdate = device
126
            if deviceToUpdate != None:
127
                print ("*** found device to update %s" % deviceToUpdate.device_id)
128
                object.update(device=deviceToUpdate.device_id)
129
130