-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpFct.py
executable file
·63 lines (59 loc) · 1.98 KB
/
helpFct.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python3.6
# -*- coding: utf-8 -*-
from sys import argv
from fileCls 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 ('b/python/\t.py')
fileHelp = File ('b/\t.txt')
def printHelp (pythonFile):
filePython.title = pythonFile
filePython.shortcut()
filePython.toPath()
fileHelp.title = 'aide '+ pythonFile
fileHelp.shortcut()
fileHelp.toPath()
# obtenir le code python
filePython.read()
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
posE = filePython.text.find ('"', posS)
helpMessage = filePython.text [:posE]
posS = helpMessage.rfind ('"') +1
helpMessage = helpMessage [posS:]
helpMessage = helpMessage.strip ()
listHelp.append ('____________ Message ____________\n')
listHelp.append (helpMessage)
# récupérer les imports
listHelp.append ('\n____________ imports ____________\n')
for line in listHelpRaw:
for word, lenght in wordImport:
if word == line [:lenght]:
listHelp.append (line)
break
# récupérer les fonctions
listHelp.append ('\n____________ Fonctions ____________\n')
for line in listHelpRaw:
for word, lenght in wordFunction:
if word == line [:lenght]:
listHelp.append (line)
break
fileHelp.text = '\n'.join (listHelp)
fileHelp.text = fileHelp.text.replace ('\nclass', '\n\nclass')
fileHelp.text = fileHelp.text.replace ('\n\n\n', '\n\n')
fileHelp.write()
print ('lire "'+ fileHelp.title +'" sur le bureau')
help = """
préciser le chemin du dossier python dans ce fichier.
par défaut, il vaut... /bureau/python
utilisation:
printHelp (pythonFile)
j'ai /bureau/python/pythonFile.py sur mon ordi.
"""
if __name__ == '__main__':
if len (argv) >1: printHelp (argv [1])
else: print (help)