def __init__(self, file=None): if file: if pathRoot not in file: file = pathPython + file if file[-3:] != '.py': file = file + '.py' if os.sep != '/': file = file.replace('/', os.sep) File.__init__(self, file) self.extension = 'py'
def __init__(self, numext='0', message='?', module='?', numint='0', type='ano'): Mantis.__init__(self, numext, message, module, numint, type) File.__init__(self, 'b/' + self.type + ' ' + numext + '.txt')
def __init__(self, objTested, fileTested): File.__init__(self) self.clazz = objTested.__class__.__name__ self.object = objTested self.funcs = [] for func in dir(objTested.__class__): if func[:2] != '__': self.funcs.append(func) self.title = 'test ' + self.clazz self.text = 'test de la classe %s, fichier: %snliste des fonctions: %s' % ( self.clazz, fileTested, ', '.join(self.funcs)) print(self.text)
def fromHtml(self, fhtml): # self.file est un fichier téléchargé de https://mantis2.axyus.com/view.php?id=3165 self.file = fhtml File.fromFile(self) # le message d = self.index('<title') d = self.index('>', d) + 1 f = self.index('</title>') self.message = self.text[d:f] d = self.message.find(': ') self.numext = self.message[:d] self.numext = self.numext.lstrip('0') self.message = self.text[d + 2:] # le module d = self.index('<th>Sous-module</th>') d = self.index('- ', d) + 2 f = self.index('-', d) self.module = self.text[d:f].lower() # la livraison d = self.index('<th>Version ciblée</th>') d = self.index('<td>', d) + 4 f = self.index('</td>', d) livraison = self.text[d:f] log.coucou() # les images images = self.text.split('<img src=') trash = images.pop(0) trash = images.pop(-1) rangeImg = range(len(images)) for i in rangeImg: f = images[i].find('>') - 1 d = images[i][:f].rfind('/') + 1 images[i] = images[i][d:f] textImg = "" if images: textImg = ' '.join(images) textImg = 'images: ' + textImg # créer le fichier self.createFile() if livraison: refFile.replace('nom-liv', livraison) if textImg: refFile.replace('====== infos ======', '====== infos ======\n\n' + textImg) if livraison or textImg: refFile.toFile()
def get(self, TagNomfile=None, sens=True): for dirpath, SousListDossiers, subList in os.walk(self.path): if not subList: continue if TagNomfile and sens: range_tag = range(len(subList) - 1, -1, -1) for i in range_tag: if TagNomfile not in subList[i] or '.txt' not in subList[i]: trash = subList.pop(i) elif TagNomfile: range_tag = range(len(subList) - 1, -1, -1) for i in range_tag: if TagNomfile in subList[i] and '.txt' in subList[i]: trash = subList.pop(i) if subList: for file in subList: fileTmp = File(os.path.join(dirpath, file)) fileTmp.dataFromFile() self.append(fileTmp) self.sort() rangeFile = self.range() for f in rangeFile: self[f].fromFile()
def fromFile(self): File.fromFile(self) self.clean() while self.contain('\n\n'): self.replace('\n\n', '\n') refFile.fromFile() refFile.clean() while refFile.contain('\n\n'): refFile.replace('\n\n', '\n') refFile.replace('%message%', '%s') refFile.replace('%numext%', '%s') refFile.replace('%numint%', '%s') refFile.replace('%module%', '%s') refFile.replace('%type%', '%s') d = refFile.index('\ntype') d = refFile.index('\n_____', d) data = self.fromModel(refFile.text[:d]) self.message = data[1] self.numext = data[2] self.numint = data[3] self.module = data[4] self.type = data[5]
def cleanLog (self, dateMin=None, dateMax=None): if dateMin: fileDate = File (self.file) fileDate.fromFile() fileDate.getDate (dateMin, dateMax) self.text = fileDate.text self.fromText() else: self.fromFile() self.cleanLines() self.toText() self.cleanModule() self.reverseLines() self.title = self.title + ' bis' self.fileFromData() File.toFile (self)
def fromFile(self): File.fromFile(self) self.clean()
def toFile(self): self.text = self.toText(self.sepLin, self.sepCol) File.toFile(self)
def __init__(self, sepLin='\n', sepCol='\t', file=None): File.__init__(self, file) Table.__init__(self) self.sepLin = sepLin self.sepCol = sepCol
def toFile(self): self.toText() File.toFile(self)
#!/usr/bin/python3.6 # -*- coding: utf-8 -*- from fileSimple import File wordImport = (('import ', 7), ('from ', 5)) wordFunction = (('class ', 6), ('def ', 4), ('\t""" ', 5), ('\treturn', 7), ('\tdef ', 5), ('\t\t""" ', 6), ('\t\treturn', 8)) filePython = File() filePython.path = 'b/python' filePython.extension = 'py' fileHelp = File() fileHelp.path = 'b/' fileHelp.extension = 'txt' def printHelp(pythonFile): # obtenir le code python if '/' in pythonFile: end = pythonFile.rfind('/') + 1 filePython.path += pythonFile[:end] pythonFile = pythonFile[end:] filePython.title = pythonFile filePython.fileFromData() filePython.fromFile() while '\n\n' in filePython.text: filePython.text = filePython.text.replace('\n\n', '\n') listHelp = [] listHelpRaw = filePython.text.split('\n') # récupérer l'aide if '\nhelp' in filePython.text: posS = filePython.text.find('\nhelp') + 10
def createDdt(self, dtime, module='cdm'): sqlFile = File() if module == 'sif': if self.module == 'rcsf': sqlFile.file = refSqlSifRcsf else: sqlFile.file = refSqlSif elif module == 'cdm': if self.module == 'rcsf': sqlFile.file = refSqlCdmRcsf else: sqlFile.file = refSqlCdm sqlFile.dataFromFile() sqlFile.fromFile() sqlFile.replace('%numero%', self.numext) dateStr = '%02d/%02d/%02d' % (dtime.day, dtime.month, dtime.year) sqlFile.replace('%date%', dateStr) sqlFile.path = self.path sqlFile.title = sqlFile.title.replace('00000', self.numext) sqlFile.fileFromData() sqlFile.toFile()
# -*- coding: utf-8 -*- from datetime import datetime from fileSimple import File from listFiles import ListFile from fileHtml import FileHtml import debutils.logger as log types = ('ano', 'ddt', 'evo', 'ana', 'rcsf') modules = { 'cdm': ('cdm', 'gd', 'ac'), 'sif': ('aec', 'sif', 'can'), 'edi': ('edi', 'ord') } refPath = 'C:\\Users\\deborah.powers\\python\\mantis\\mantis\\' refName = refPath + 'mantis-base.txt' refFile = File(refName) refSqlCdm = refPath + '01_CDM_DDT-00000_xxx.sql' refSqlSif = refPath + '01_SIF_DDT-00000_xxx.sql' refSqlCdmRcsf = refPath + '01_CDM_DDT-00000_reprise_csf.sql' refSqlSifRcsf = refPath + '01_SIF_DDT-00000_suppression_csf.sql' class Mantis(): def __init__(self, numext='0', message='?', module='?', numint='0', type='ano'): self.message = message self.numext = numext
from sys import argv from fileSimple import File, Article help ="""traiter des fichiers utilisation le script est appelable dans un fichier python3 fileClass.py fichier tag (fichierB) les valeurs de tag clean (reset upper): nettoyer le texte. modifier ou pas la casse. mef (reset upper): mettre en forme un texte utilisant ma mise en forme spécifique. cpr: comparer deux fichiers ligne à ligne. """ nbArg = len (argv) if nbArg <3: print (help) elif argv[2] == 'testFile': filePerso = File() filePerso.test() elif argv[2] == 'testArtic': filePerso = Article() filePerso.test() elif argv[2] =='tmp': fileTxt = Article() fileTxt.tmp() elif nbArg ==4 and argv[2][:3] == 'cpr': fpA = File (argv[1]) fpB = File (argv[3]) if argv[2] == 'cprs': fpA.compare (fpB, 'lsort') else: fpA.compare (fpB) elif argv[2] == 'help': from fileSimple.help import printHelp printHelp (argv[1])
#!/usr/bin/python3.6 # -*- coding: utf-8 -*- # http://www.pallier.org/extra/liste.de.mots.francais.frgut.txt from sys import argv from debutils.text import wordsEnd from fileSimple import File from fileSimple.fileList import FileList import debutils.logger as logger newPoints = "-'() /_\"\n\t<> [](){}|%#$@=+*°&0123456789" ref = File('b/liste-mots.txt') class FileSrc(FileList): def log(self): d = self.index('mcehywkh') print(self.text[d - 20:d + 20]) def clean(self): self.text = self.text.lower() FileList.clean(self) for p in newPoints: self.replace(p, ' ') for p in wordsEnd: self.replace(p, ' ') self.text = ' ' + self.text + ' ' self.fromText() def groom(self): self.sort() self.delDouble()
def __init__(self, sepLin='\n', file=None): File.__init__(self, file) List.__init__(self) self.sepLin = sepLin
def toFile(self): self.shape() File.toFile(self)
def fromFile(self): File.fromFile(self) self.fromText()