Page 1 of 1

Creating a WAPT Cleaner package

Published: October 15, 2018 - 12:08 PM
by renaud.counhaye
Hey everyone, :)

I've performed a WAPT server migration, from machines on server "A" (WAPT 1.3) to server "X" (WAPT 1.5, which was later updated to 1.6).

The problem with this migration is that the machines that underwent the change via waptdeploy reverted their inventory from 1.3 to 1.5, and some package names changed, while other packages disappeared.
However, their inventory remains valid to the client and the console.

I'd like some help creating a cleanup script. I'm wondering if you have a better suggestion than this:

The script runs a `wapt-get list` and then, using a loop, searches for exceptions that I would have listed earlier in a variable.
If it finds the package, it runs a simple `wapt-get forget xxxxxx` followed by a `wapt-get install zzzzz` with the replacement package.

Perhaps I missed a step in waptdeploy to clean up post- or pre-installation. Or perhaps you're looking for some kind of package already available for a similar process?

Thanks in advance :)

(I'll probably make progress on the system mentioned above and share it with you once it's finished).

Re: Creating a WAPT Cleaner package

Published: October 15, 2018 - 8:12 PM
by dcardon
Good evening Renaud,
renaud.counhaye wrote: Oct 15, 2018 - 12:08 PM I performed a WAPT server migration, from machines on server "A" WAPT 1.3 to server "X" WAPT 1.5 (which was subsequently updated to 1.6).

The problem with this migration is that the machines that underwent the change via waptdeploy reverted their inventory from 1.3 to 1.5, and some package names changed, while other packages disappeared.
However, their inventory remains valid in the eyes of the client and the console.
From the system's perspective, it's up to date: there are no packages newer than the one already installed on the machine. So it's not incorrect, even if it's not exactly what you wanted.
renaud.counhaye wrote: Oct 15, 2018 - 12:08 PM I would like some help creating a cleaning script. I'd like to know if you have anything better to suggest than this:
If not too many packages are affected, you can simply type the name of the package in question into the search textbox ("search keyword"), for example, xyz-firefox, and the machines that have the package will be listed. Note: be aware that the search matches substrings, so searching for xyz-firefox will also return machines that have xyz-firefox-esr.
  • Next you select "remove dependencies on packages or groups of packages" to remove the dependencies on the packages in question;
  • Then you can delete or forget the package by selecting the machines concerned and, in the list of packages on the right, right-click and "forget packages"
Sincerely,

Denis

Re: Creating a WAPT Cleaner package

Published: October 19, 2018 - 10:59 AM
by renaud.counhaye
Hello Denis,

Unfortunately, there are a large number of machines that are impacted by this phantom inventory.
That's why I was looking for a way to automate it, given the impossibility of easily cleaning the inventory of a machine after a server migration.

So I came up with this very simple code:
It is possible to forget a package known only to the client since it is not registered in the packages assigned to the machine on the console, therefore no reinstallation.

Code: Select all

# -----------------------------------------------------------------------
# This script was made in an effort to manage previous WAPT registred packages.
# Made by Renaud Counhaye for Ymagis.
# -----------------------------------------------------------------------
from setuphelpers import *

list_replaces=["chrome-fr","firefox-esr-fr","adobereader-mui"] #liste de vieux paquet aillant un remplacant
list_replaced=["chrome","firefox","adobereader"] #liste des paquets remaplcants les anciens! attention doit être dans le meme ordre!

#list de paquets à oublier tout simplement.
list_forgets=["check-viscosity","fr-standard-applications","apple-software-update","ie11","fr04-fr-Office365-and-Standard-applications","fr-web-browsers","deploy-ymagis-nxt","trend-micro-security-agent"]

uninstallkey = []

#def main():
def install():
    #check si le fichier précédent existe, si oui, kill
    if(isfile(makepath('C:','sys','logs','waptgetlist.txt'))):
        print('previous file is present')
        remove_file(makepath('C:','sys','logs','waptgetlist.txt'))
    print('start...')
    run('cmd /c wapt-get list > C:\sys\logs\waptgetlist.txt') #creation d'un fichier contenant la lsite des packets actif sur la machine
    if(isfile(makepath('C:','sys','logs','waptgetlist.txt'))):
       print('file is present')
       f=open(makepath('C:','sys','logs','waptgetlist.txt'), "r") 
       if f.mode == 'r':
            f1 = f.readlines() #lecture ligne par ligne du fichier
            for line in f1:
                data = line.split(" ")
                package = data[0]
                if package in list_replaces:
                    print '--in replaces' #si le paquet lu est dans la liste des pack a remplacer, on forget puis wapt.install 
                    point=list_replaces.index(package)
                    if(point != -1):
                        cmd = "cmd /c wapt-get forget "+package+" --force"
                        run(cmd)
                        WAPT.install(list_replaced[point],force=WAPT.options.force)
                else:
                    if package in list_forgets:
                        print '--in forgets' #si le paquet lu est dans la liste des pack a oublier, on forget 
                        point = list_forgets.index(package)
                        if(point != -1):
                            print str(point)+' found forgets'
                            cmd = "cmd /c wapt-get forget "+package+" --force"
                            run(cmd)
                        else:
                            print '++not found'
            print 'end.'

if __name__ == '__main__': #run debug
    install()
PS: It would be interesting to allow a WAPT package with a special key to force a package to be unassigned from the machine on which it is running.

Good day,

Re: Creating a WAPT Cleaner package

Published: October 19, 2018 - 1:57 PM
by sfonteneau
Simpler :

https://wapt.lesfourmisduweb.org/detail ... 9_all.wapt

Code: Select all

import platform
from setuphelpers import *

uninstallkey=[]

def install():
    prefixpkg = control.package.split('-',1)[0]
    reader = WAPT.is_installed('%s-pdfcreator'% prefixpkg)
    if reader and Version(reader.version.split('-',1)[0]) == Version('3.2.1'):
        WAPT.forget_packages(reader.package)
        WAPT.install('%s-pdfcreator'% prefixpkg)