Question about labelplus, or perhaps a general problem

Suggestions and discussion of future versions
Post Reply
daerlnaxe
Member
Member
Posts: 12
Joined: Wed Nov 01, 2017 9:59 am

Question about labelplus, or perhaps a general problem

Post by daerlnaxe »

Sorry, it's me... again.

I try to understand how it works. There is several broken links on the help page.

I ve almost finished what i would to do.
When i enable the plugin i made, it modify labelplus conf if label.conf and labelplus conf have ~ a label similar. (i check if the name is capitalized or not).
The orphan torrent under labelplus are moved in the labelplus label... But.

1st : the counter of the targetted labelplus label is not updated.
2nd: i have perhaps found why, but to modify the conf was not enough because i couln't add after a sublabel, it abort all the time. I have tried to disable then enable labelplus plugin when i had this problem to try to refresh the counter. I stopped to do that.
3: now that i use

Code: Select all

labelplus_plugin = deluge.component.get("CorePlugin.LabelPlus")
labelplus_plugin.update()
the counter is not updated, i can add a sublabel, but i can't move the fresh torrents added by the plugin in any sublabel or label. I think it mus be a problem about a variable, perhaps force to recheck the torrents mapped.... Everything is ok after have restart deluged (the core )

So i ask to myself, is there a common def to all the plugin, like enable, disable ? Or i must check in the plugin if there is something... ?

Here is my code, for the moment it's just a draft

Code: Select all

    def update_lbplus(self):
    # lecture d'un fichier conf tiers.
        chronos = time.strftime("%d/%m/%Y %H:%M:%S")
        try:
            self.label_config = deluge.configmanager.ConfigManager("label.conf")
            self.labelPlus_config = deluge.configmanager.ConfigManager("labelplus.conf")

        # Récupération des liaisons noms : bind dans labelplus
            labelPCats={}
            for cat in self.labelPlus_config['labels']:
                # Récupération uniquement des catégories maitresses
                if ':' in cat: continue
                #print(categorie)
                nom = self.labelPlus_config['labels'][cat]['name']
                labelPCats[nom] = cat
        # fin

        # Récupération des catégories de label
            i=0
            labelCat = {}
            for cat in self.label_config['labels']:
                labelCat[cat]=i
                i+=1
        # fin
        # Nombre de torrents dans labelplus
            avant = len(self.labelPlus_config['mappings'])
            countlbp = 0
            ignored = 0
            modif = 0
        # Go
            torrent_labels = self.label_config['torrent_labels']

            for tor in torrent_labels:     # lecture de tous les torrents ajoutés
                if tor in self.labelPlus_config['mappings']:    # si le torrent de label est dans les torrents mappings de labelplus
                    countlbp +=1
                else:                                           # Le torrent n'est pas mappé dans labelplus
                # Recherche de correspondance des catégories
                    idlab = torrent_labels[tor]
                    idLAB = idlab.capitalize()
                    if idLAB in labelPCats:
                        self.labelPlus_config['mappings'][tor] = labelPCats[idLAB]
                        modif+=1
                    elif idlab in labelPCats:
                        self.labelPlus_config['mappings'][tor] = labelPCats[idlab]
                        modif+=1
                    # TODO: perhaps si to create label
                    else:
                        ignored +=1


            self.write('Déja triés: {}'.format(countlbp))
            self.write('modifiés: {}'.format( modif))
            self.write('Non traités: {}'.format(ignored))
        except Exception as e:
            import sys
            log.error( "myplugin3: {0}{1}".format( e, sys.exc_info()[-1].tb_lineno ))
        else:

            if not modif ==0:
                self.labelPlus_config.save()
                labelplus_plugin = deluge.component.get("CorePlugin.LabelPlus")
                labelplus_plugin.update()                

daerlnaxe
Member
Member
Posts: 12
Joined: Wed Nov 01, 2017 9:59 am

Re: Question about labelplus, or perhaps a general problem

Post by daerlnaxe »

I think it's ok now, i changed the direct writing by using a def in labelplus '_set_torrent_label'
daerlnaxe
Member
Member
Posts: 12
Joined: Wed Nov 01, 2017 9:59 am

Re: Question about labelplus, or perhaps a general problem

Post by daerlnaxe »

New code, if somebody can check to see if it's ok like this. It's only a draft, i have not even a name... for the time it's "myplugin3".... :lol: :lol: :lol:

It works well... if you create a new label on labelplus with the same name that in label it transfert immediatly all the torrents. Idem if you add a new torrent by autoadd ... For the moment i don't use really the gtk, i will try.... i thought add a way beetween label and label plus in config... list all the labels in label, all in labelplus. Put two listbox in front then select and add the links beetween, by this method it will more powerful.

The actual code (draft, don't forget it)... i'm not used to python2.7, i worked with python3.6 to make a watcher of vpn (keep the connexion, beetween a list, by using the openvpn protocol and not networkmanager, if it's diconnected it kills deluge... and others if i develop plugins for it), it watch the lan too using socket lib, not by the basch commands.

Then

Code: Select all

    def update_lbplus(self):
    # lecture d'un fichier conf tiers.
        chronos = time.strftime("%d/%m/%Y %H:%M:%S")
        try:
            self.label_config = deluge.configmanager.ConfigManager("label.conf")
            self.labelPlus_config = deluge.configmanager.ConfigManager("labelplus.conf")

    # beta
            self.write("test du label", 'a')
            self.write(dir(self.label_config), 'a')
    # beta

        # Récupération des liaisons noms : bind dans labelplus
            labelPCats={}
            for cat in self.labelPlus_config['labels']:
                # Récupération uniquement des catégories maitresses
                if ':' in cat: continue
                #print(categorie)
                nom = self.labelPlus_config['labels'][cat]['name']
                labelPCats[nom] = cat
        # fin

        # Récupération des catégories de label
            i=0
            labelCat = {}
            for cat in self.label_config['labels']:
                labelCat[cat]=i
                i+=1
        # fin
        # Nombre de torrents dans labelplus
            avant = len(self.labelPlus_config['mappings'])
            countlbp = 0
            ignored = 0
            modif = 0
        # Go
            #torrent_labels =

        #initialisation d'un tableau de liste
            zeDict={}
            for value in labelPCats.values():
                zeDict[value]=[]
        # Rego
            for tor in self.label_config['torrent_labels']:     # lecture de tous les torrents ajoutés
                if tor in self.labelPlus_config['mappings']:    # si le torrent de label est dans les torrents mappings de labelplus
                    countlbp +=1
                else:                                           # Le torrent n'est pas mappé dans labelplus
                # Recherche de correspondance des catégories
                    #torrent_id = tor
                    idlab = self.label_config['torrent_labels'][tor]
                    idLAB = idlab.capitalize()

                    if idLAB in labelPCats:
                        zeDict[ labelPCats[idLAB] ].append(tor)
                        modif+=1

                    elif idlab in labelPCats:
                    #    self.labelPlus_config['mappings'][tor] = labelPCats[idlab]
                        zeDict[ labelPCats[idlab] ].append(tor)
                        modif+=1
                    # TODO: perhaps si to create label
                    else:
                        ignored +=1


            self.write('Déja triés: {}'.format(countlbp))
            self.write('modifiés: {}'.format( modif))
            self.write('Non traités: {}'.format(ignored))
        except Exception as e:
            import sys
            log.error( "myplugin3: {0}{1}".format( e, sys.exc_info()[-1].tb_lineno ))
        else:
            self.write("pas de modif 2")
            #self.write(labelplus_plugin)

            #self.write(dir(labelplus_plugin))


            if not modif ==0:
                self.write("Modifications à faire")
                labelplus_plugin = deluge.component.get("CorePlugin.LabelPlus")
                #labelplus_plugin._set_torrent_label( tor, labelPCats[idLAB])
                for labelplus, torrents in zeDict.items():
                    if len(torrents)==0: continue
                    self.write(labelplus)
                    self.write(torrents)
                    labelplus_plugin.set_torrent_labels( torrents, labelplus)
                    self.write("boucle ok")

                #self.labelPlus_config.save()
                #labelplus_plugin = deluge.component.get("CorePlugin.LabelPlus")
                labelplus_plugin.update()


It use the set_torrents_labels, then make an update.
Post Reply