Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Install library in V3

2011-06-07
2012-04-23
  • Frank Jepsen - 2011-06-07

    Hi,

    Is there a way to install new libraries in CoDeSys V3 from the script engine?

    The documentation states that it is possible to add_library to a project, but I cannot find a command to install the libraries so they can be added afterwards.

    I am using CoDeSys V3.4 SP3 Patch 1.

    Best regards,
    Frank Jepsen
    kk-electronic a/s

     
  • Anonymous - 2011-06-07

    Originally created by: M.Schaber

    Hi,

    Currently, this functionality is not available.

    But there is a workaround: Pack the library into a project archive, and open that archive using open_archive. This should install all libraries contained in the archive.

    This workaround should solve some of the use cases.

    Regards,
    Markus

     
  • Frank Jepsen - 2011-06-07

    Ok. That sounds like a reasonable workaround. Thank you.

    // Frank

     
  • Frank Jepsen - 2012-04-23

    Hi,

    I have upgraded to V3.5 Patch 3 now and I can see that more objects has become available.

    Could you provide an example using the ILibManager to install a library?

    I would like to install e.g. "c:\myfunction.library" into the CoDeSys IDE, so I can add it to other projects.

    Regards,
    Frank

     
  • Anonymous - 2012-04-23

    Originally created by: M.Schaber

    Hi, Frank,

    Frank Jepsen hat geschrieben:
    I have upgraded to V3.5 Patch 3 now and I can see that more objects has become available.
    Could you provide an example using the ILibManager to install a library?
    I would like to install e.g. "c:\myfunction.library" into the CoDeSys IDE, so I can add it to other projects.

    I stripped one of my internal test scripts a little bit, here's the code. It demonstrates displaying all libraries, creating and deleting library repositories, and installation and uninstallation of libraries.

    from __future__ import print_function
    import os
    for repo in librarymanager.repositories:
        print(repo.name, "(", repo.root_folder, ", ", repo.editable, ")")
        for lib in librarymanager.get_all_libraries(repo):
            print("    ", lib.displayname)
            print("        Cats: ", ", ".join(map(str, lib.categories)))
            print("        Deps: ", ", ".join(map(str, lib.dependencies)))
    print("")
    oldrepocount = len(librarymanager.repositories)
    print("Trying to create repo")
    repopath = "C:\\Path\\to\\temporary\\dir\\REPO"
    os.makedirs(repopath)
        
    newrepo = librarymanager.insert_repository(repopath, "Script_Test_Repo")
    assert(len(librarymanager.repositories) == oldrepocount + 1)
    print("Trying to install library")
    libpath = "C:\\Path\\to\\Testlib.library"
    installedlib = librarymanager.install_library(libpath, repo, overwrite=True)
    print("Trying to find library")
    foundlib, repo = librarymanager.find_library("MSch Test library, 3.4.4.0 (3S Smart Software GmbH)")
    assert(repo == newrepo, "repo does not match!")
    assert(foundlib == installedlib, "lib does not match!")
    print("Uninstalling library")
    librarymanager.uninstall_library(repo, foundlib)
    print("Removing repository")
    librarymanager.remove_repository(newrepo, delete_on_disk=True)
    assert(not os.path.isdir(repopath), "repo deletion failed")
    print("script finished.")
    

    Here's a second script which installs all librarie swhich are found in a given directory. Our test department sometimes uses it to install all libraries which were ever released with CoDeSys into a fresh installation (for example, in a Virtual Machine).

    \# -*- coding: utf-8 -*.
    from __future__ import print_function
    import os
    \# The directory we want to install libraries from.
    LIBDIRS = (r"D:\WorkingCopies\LibrariesV3Tags",)
    \# Search order (compiled vs. source libraries)
    EXTENSIONS = (".compiled-library", ".library")
    \# disabling prompts for storage version upgrade
    system.prompt_answers["UnserializableDataError2"] = PromptResult.Cancel
    system.prompt_answers["LossOfDataWarning2"] = PromptResult.No
    print("searching libraries to install")
    repo = librarymanager.repositories[0]
    for libdir in LIBDIRS:
        for extension in EXTENSIONS:
            for dir, subdirs, files in os.walk(libdir):
                for filename in files:
                    if filename.endswith(extension):
                        fullpath = os.path.join(dir, filename)
                        print("installing: ", fullpath)
                        try:
                            librarymanager.install_library(fullpath, repo, overwrite=True)
                        except Exception as e:
                            print("exception: ", e)
                    
    print("script finished.")
    

    Warning: I cleaned both scripts by removing some internals, and did not re-test them in their new shape, but they should still be useful for you to get the idea.

    I hope that helps you a little...

     
  • Frank Jepsen - 2012-04-23

    Thanks Markus. Those examples really helped.

     

Log in to post a comment.