Morrowind mod management: integrating tes3cmd in Mash

Tes3cmd is a wonderful tool, but as any command line tool it would be nice to have it integrated with our preferred mod management tool.
I use a right-click command in Mash to integrate tes3cmd, so I can clean multiple (but only those I need to clean) .esp with tes3cmd using Mash as GUI.

If you are using the source version of Mash and want to give my changes a try, you can edit proper parts in your Data Files\Mopy\masher.py file as detailed below (or you can download the whole tweaked masher.py containing these and other changes).

Relevant changes are enclosed between

#--begin changes by abot
#--end changes by abot

comments, and

#--...

means "code in-between to leave unchanged".

Note: your tes3cmd.exe file should be in the Morrowind\Data Files folder.

#------------------------------------------------------------------------------
class File_Sort(Link):
    """Sort the selected files."""
    def AppendToMenu(self,menu,window,data):
        Link.AppendToMenu(self,menu,window,data)
        menuItem = wx.MenuItem(menu,self.id,_('Sort'))
        menu.AppendItem(menuItem)
        if len(data) < 2: menuItem.Enable(False)

    def Execute(self,event):
        """Handle menu selection."""
        message = _("This command will sort the selected files alphabetically, assigning them dates one minute after each other. It cannot be undone.\n\nNote that some mods need to be in a specific order to work correctly, and this sort operation may break that order.")
        if ContinueQuery(self.window,message,'mash.sortMods.continue',_('Sort Mods')) != wx.ID_OK:
            return
        #--Scan for earliest date
        fileInfos = self.window.data
        newTime = min(fileInfos[fileName].mtime for fileName in self.data)
        #--Do it
        for fileName in sorted(self.data,key=lambda a: a[:-4].lower()):
            fileInfos[fileName].setMTime(newTime)
            newTime += 60
        #--Refresh
        fileInfos.refreshDoubleTime()
        self.window.Refresh()

#--begin changes by abot

# tes3cmd.exe clean --replace [selected files]
#------------------------------------------------------------------------------
class File_tes3cmd(Link):
    def AppendToMenu(self,menu,window,data):
        Link.AppendToMenu(self,menu,window,data)
        menuItem = wx.MenuItem(menu,self.id,_('tes3cmd.exe clean --replace [selected files]'))
        menu.AppendItem(menuItem)
        if len(data) < 1: menuItem.Enable(False)

    def Execute(self,event):
        message = _("This command will call Data Files\\tes3cmd.exe clean --replace passing selected files.")
        if ContinueQuery(self.window,message,'masher.File_tes3cmd.continue',_('tes3cmd.exe clean --replace [selected files]')) != wx.ID_OK:
            return
        #--Scan
        fileInfos = self.window.data
        path = os.path.join(settings['mwDir'],'Data Files')
        exe = os.path.join(path,'tes3cmd.exe')
        args = ['tes3cmd.exe']
        args.append('clean')
        args.append('--replace')
        args.append('--hide-backups')
        for fileName in self.data:
            args.append('"' + fileName + '"')

        cwd = os.getcwd()
        os.chdir(path)
        os.spawnv(os.P_NOWAIT,exe,args)
        os.chdir(cwd)

        #--Refresh
        fileInfos.refreshDoubleTime()
        self.window.Refresh()
#--end changes by abot

#------------------------------------------------------------------------------
class File_Snapshot(Link):
    """Take a snapshot of the file."""
    def AppendToMenu(self,menu,window,data):
        Link.AppendToMenu(self,menu,window,data)
        menuItem = wx.MenuItem(menu,self.id,_('Snapshot...'))
        menu.AppendItem(menuItem)
        if len(data) != 1: menuItem.Enable(False)

#--...  

        fileMenu.links.append(File_Snapshot())
        fileMenu.links.append(SeparatorLink())
        fileMenu.links.append(File_Delete())
        fileMenu.links.append(File_Hide())
        fileMenu.links.append(File_Redate())
        fileMenu.links.append(File_Sort())
#--begin changes by abot
        fileMenu.links.append(File_tes3cmd())
#--end changes by abot

#--...