CODESYS - the IEC 61131-3 automation software
https://forum.codesys.com/

Remove library from library repository by script
https://forum.codesys.com/viewtopic.php?f=18&t=8010
Page 1 of 1

Author:  DBaur [ Wed Jul 19, 2017 10:37 am ]
Post subject:  Remove library from library repository by script

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...

Author:  Hermsen [ Wed Jul 19, 2017 6:05 pm ]
Post subject:  Re: Remove library from library repository by script

I am also interested in such an example

Author:  M.Keller [ Thu Jul 20, 2017 9:19 am ]
Post subject:  Re: Remove library from library repository by script

Hi DBaur.

DBaur wrote:
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:
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

Author:  feragfh6 [ Wed Apr 04, 2018 7:29 pm ]
Post subject:  Re: Remove library from library repository by script

Hi Martin

Is it possible to find a library only by company?
So I can uninstall all libraries form one company.
Code:
found = librarymanager.find_library("*, * (Siemens)")


Thanks

Author:  XopHeT [ Tue May 29, 2018 3:24 pm ]
Post subject:  Re: Remove library from library repository by script

feragfh6 wrote:
Hi Martin

Is it possible to find a library only by company?
So I can uninstall all libraries form one company.
Code:
found = librarymanager.find_library("*, * (Siemens)")


Thanks



I might be too late, but here it is:
Code:
#-*- 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:
Code:
if sCompanyName in library.company.upper():

Author:  feragfh6 [ Wed May 30, 2018 11:06 am ]
Post subject:  Re: Remove library from library repository by script

Works. Thanks.

Page 1 of 1 All times are UTC+01:00
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/