Khadafi995

plugin.py

Jan 18th, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.13 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab
  4.  
  5. # target script
  6.  
  7. import re
  8. import sys
  9. import html5lib
  10.  
  11. from PyQt5 import QtCore, QtGui, QtWidgets
  12. from PyQt5.QtWidgets import QWidget, QApplication
  13. from bs4 import BeautifulSoup, Tag
  14. from PCap2 import *
  15. from Formulaire import Ui_Formulaire
  16.  
  17. #Class Balise Gui
  18. class balise_class (QWidget,Ui_Formulaire):
  19.     def __init__(self):
  20.         QWidget.__init__(self)
  21.         self.setupUi(self)
  22.         self.confirm_button.clicked.connect(self.initValue)
  23.  
  24.     def initValue(self):
  25.         balise_value = self.balise_value.value()
  26.         class_value = self.class_value.value()
  27.         if (balise_value == "") or (class_value == ""):
  28.             print("Champ balise ou class vide non autorisé !")
  29.             return -1
  30.         else :
  31.             metadonnee = [balise_value, class_value]
  32.             return metadonnee
  33.  
  34. def run(bk):
  35.     print("Initialisation de l'application")
  36.     app = QApplication(sys.argv)
  37.     #QApplication.setStyle(QtWidgets.QStyleFactory.create('plastique'))
  38.     Balise_form = balise_class()
  39.     print("Affichage de Balise_form")
  40.     Balise_form.show()
  41.     #balise_name = metadonee[0]
  42.     #class_name = metadonee[1]
  43.     balise_name = "span"
  44.     class_name = "PCap"
  45.  
  46.     #parcourir tous les fichiers xhtml
  47.     data =""
  48.     try :
  49.         print("Traitement des fichiers xhtml")
  50.         for (id, href) in bk.text_iter():
  51.             data = bk.readfile(id)
  52.             soup = BeautifulSoup(data, "html5lib")
  53.             soup = findWordWithoutSpace(soup, balise_name, class_name)
  54.     except:
  55.         print("Le fichier ne peut pas être traiter !")
  56.  
  57.     #remplacement du fichier xhtml modifié
  58.     try :
  59.         bk.deletefile(id)
  60.         basename = id+".xhtml"
  61.         meta = "application/xhtml+xml"
  62.         uid1 = id
  63.         bk.addfile(uid1, basename, data2, meta)
  64.     except:
  65.         print("Le fichier ne peut pas être ajouté !")
  66.     sys.exit(app.exec_())
  67.     return 0
  68.  
  69. def main():
  70.     print("I reached main when I should not have\n")
  71.     return -1
  72.  
  73. if __name__ == "__main__":
  74.     sys.exit(main())
Advertisement
Add Comment
Please, Sign In to add comment