Remove library from library repository by script

DBaur
2017-07-19
2018-05-30
  • DBaur - 2017-07-19

    How can a libary be removed by python script from the CODESYS library repository?

    Can you give me an example for that?

    Thanks in advance...

     
  • hermsen

    hermsen - 2017-07-19

    I am also interested in such an example

     
  • mkeller - 2017-07-20

    Hi DBaur.

    DBaur hat geschrieben:
    How can a libary be removed by python script from the CODESYS library repository?
    Can you give me an example for that?

    Here my example code:

    print("Find library...")
    found = librarymanager.find_library("TestLib, 1.0.0.0 (3S-Smart Software Solutions GmbH)")
    if found:
       lib, repo = found
       print("Lib: " + lib.displayname)
       print("In repo: {} ({})".format(repo.name, repo.root_folder))
       print("Uninstall library...")
       librarymanager.uninstall_library(repo, lib)
       found = librarymanager.find_library("TestLib, 1.0.0.0 (3S-Smart Software Solutions GmbH)")
       if found:
          print("Error: Lib ist still there!!!")
    else:
       print("NO lib was found")
    

    BR
    Martin

     
  • fh6 - 2018-04-04

    Hi Martin

    Is it possible to find a library only by company?
    So I can uninstall all libraries form one company.

    found = librarymanager.find_library("*, * (Siemens)")
    

    Thanks

     
  • XopHeT - 2018-05-29

    feragfh6 hat geschrieben:
    Hi Martin
    Is it possible to find a library only by company?
    So I can uninstall all libraries form one company.

    found = librarymanager.find_library("*, * (Siemens)")
    

    Thanks

    I might be too late, but here it is:

    \#-*- coding: UTF-8 -*-
    from __future__ import print_function
    import sys, os
    from sys import exit
    libRepository = librarymanager
    defaultRepository = libRepository.repositories[0]
    def removeAllCompanyLibs(sCompanyName):
       sCompanyName = sCompanyName.upper()
       for repository in libRepository.repositories:
          for library in libRepository.get_all_libraries(repository):
             if sCompanyName in library.company.upper():
                system.write_message(Severity.Information, 'Lib removed: ' + library.displayname)
                libRepository.uninstall_library (repository, library)
       system.write_message(Severity.Information, 'Removing libraries done')
    removeAllCompanyLibs ('siemens')
    

    you might improve the line where library company is compared to your:

    if sCompanyName in library.company.upper():
    
     
  • fh6 - 2018-05-30

    Works. Thanks.

     

Log in to post a comment.