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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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__importprint_functionimportosforrepoinlibrarymanager.repositories:Â Â print(repo.name,"(",repo.root_folder,", ",repo.editable,")")Â Â forlibinlibrarymanager.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(notos.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__importprint_functionimportos
\# 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 upgradesystem.prompt_answers["UnserializableDataError2"]=PromptResult.Cancelsystem.prompt_answers["LossOfDataWarning2"]=PromptResult.Noprint("searching libraries to install")repo=librarymanager.repositories[0]forlibdirinLIBDIRS:Â Â forextensioninEXTENSIONS:Â Â Â Â fordir,subdirs,filesinos.walk(libdir):Â Â Â Â Â Â forfilenameinfiles:Â Â Â Â Â Â Â Â iffilename.endswith(extension):Â Â Â Â Â Â Â Â Â Â fullpath=os.path.join(dir,filename)Â Â Â Â Â Â Â Â Â Â print("installing: ",fullpath)Â Â Â Â Â Â Â Â Â Â try:Â Â Â Â Â Â Â Â Â Â Â Â librarymanager.install_library(fullpath,repo,overwrite=True)Â Â Â Â Â Â Â Â Â Â exceptExceptionase:Â Â Â Â Â Â Â Â Â Â Â Â 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...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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
Ok. That sounds like a reasonable workaround. Thank you.
// Frank
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
Originally created by: M.Schaber
Hi, Frank,
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.
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).
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...
Thanks Markus. Those examples really helped.