Skip to content

Commit 8f20144

Browse files
committed
add function in fileActions.py
Signed-off-by: Timothée Ruffenach <timruff@gmx.com>
1 parent 0599288 commit 8f20144

File tree

1 file changed

+51
-19
lines changed

1 file changed

+51
-19
lines changed

standalone/fileActions.py

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# @author RUFFENACH Timothée
2-
# Version 1.0
2+
# Version 1.1
33
# Scrip to edit file
44
# Help me for lab burpsuite resolve with zap
55

@@ -16,11 +16,11 @@ def __init__(self):
1616
self.getContentPane().setLayout(None)
1717

1818
# Create selection menu
19-
options = ["Inserting a character string alternately", "Duplicate data file"]
19+
options = ["Inserting a character string alternately", "Duplicate data file", "Create Json tab with data file"]
2020

2121
# Create scrolling menu
2222
self.dropdown = JComboBox(options)
23-
self.dropdown.setBounds(50, 50, 200, 30)
23+
self.dropdown.setBounds(50, 50, 400, 20)
2424
self.dropdown.addActionListener(self.selection_changee)
2525
self.getContentPane().add(self.dropdown)
2626

@@ -39,6 +39,9 @@ def selection_changee(self, event):
3939
elif selected_option == "Duplicate data file":
4040
self.dropdown.setPopupVisible(False)
4141
self.fonction_option2()
42+
elif selected_option == "Create Json tab with data file":
43+
self.dropdown.setPopupVisible(False)
44+
self.fonction_option3()
4245

4346
# close scrolling menu
4447
self.dropdown.setPopupVisible(False)
@@ -92,18 +95,8 @@ def fonction_option2(self):
9295
copy = self.getNumber(1,100, "How many copy data file do you want [1 to 100]")
9396
filePath = self.chooseFile()
9497
print("path", filePath)
95-
# get number line of file
96-
97-
file = open(filePath, "r")
98-
nb_line = 0
99-
for line in file:
100-
nb_line += 1
101-
file.close()
10298

103-
# the file can't have 0 line
104-
if nb_line == 0:
105-
JOptionPane.showMessageDialog(None, "Empty file", "Alerte", JOptionPane.WARNING_MESSAGE)
106-
return 0
99+
self.getNumberLine(filePath)
107100

108101
# read data of file
109102
file = open(filePath, "r")
@@ -116,14 +109,54 @@ def fonction_option2(self):
116109

117110
self.saveFile(dataCopy)
118111

112+
def fonction_option3(self):
113+
114+
filePath = self.chooseFile()
115+
print("path", filePath)
116+
117+
# read data of file
118+
file = open(filePath, "r")
119+
data = file.readlines()
120+
file.close()
121+
122+
# get numberline
123+
self.getNumberLine(filePath)
124+
125+
# create tab JSon
126+
dataJson =[]
127+
dataJson.append("[\n")
128+
129+
for i in range(len(data)):
130+
dataJson.append("\""+data[i].rstrip('\n')+"\",\n")
131+
132+
dataJson.append("]\n")
133+
134+
135+
136+
self.saveFile(dataJson)
137+
138+
139+
# get number line file
140+
def getNumberLine(self,filePath):
141+
nb_line = 0
142+
143+
while nb_line < 1:
144+
file = open(filePath, "r")
145+
146+
for line in file:
147+
nb_line += 1
148+
file.close()
149+
150+
# the file can't have 0 line
151+
if nb_line == 0:
152+
JOptionPane.showMessageDialog(None, "Empty file", "Alerte", JOptionPane.WARNING_MESSAGE)
153+
154+
return nb_line
155+
119156
def saveFile(self,data):
120157
# create instance JFileChooser
121158
file_chooser = JFileChooser()
122159

123-
# debug
124-
#for i in range(len(data)):
125-
# print(data[i])
126-
127160
# show dialog box
128161
result = file_chooser.showSaveDialog(None)
129162

@@ -202,4 +235,3 @@ def confirm_closing():
202235
# menu
203236
menu = SelectionMenu()
204237
menu.setVisible(True)
205-

0 commit comments

Comments
 (0)