Skip to content

Commit 8d4937c

Browse files
committed
Flake8 linted
1 parent b436303 commit 8d4937c

7 files changed

Lines changed: 68 additions & 94 deletions

File tree

Main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from VTPackage import VTApp
22

33
vtApp = VTApp.VTApp()
4-
vtApp.start()
4+
vtApp.start()

VTPackage/Consts.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# -*- coding: utf-8 -*-
22
""" The global consts file
33
4-
Some constant values are being used across multiple parts of the application. A good example is the size of an entry in our UI .
5-
If we wouldn't have this Consts.py file, every time we will want to change the size of an entry, we will need to do it in more than 10 different places.
6-
a good practice is to define such constans once inside a file, and consume it from your different application parts
4+
Some constant values are being used across multiple parts of the application.
5+
A good example is the size of an entry in our UI.
6+
If we wouldn't have this Consts.py file,
7+
every time we will want to change the size of an entry,
8+
we will need to do it in more than 10 different places.
9+
a good practice is to define such constants once inside a file,
10+
and consume it from your different application parts
711
"""
812

913

10-
entry_width = 50
14+
ENTRY_WIDTH = 50

VTPackage/FileReportTab.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
class FileReportTab:
2424

25-
def __init__(self,root,frame, vtClient):
25+
def __init__(self, root, frame, vtClient):
2626
self.root = root
2727
self.frame = frame
28-
self.vtClient= vtClient
28+
self.vtClient = vtClient
2929

3030
self.mainVTURLframe = ttk.LabelFrame(frame, text=' File report')
3131
self.mainVTURLframe.grid(column=0, row=1, padx=8, pady=4)
@@ -36,47 +36,44 @@ def __init__(self,root,frame, vtClient):
3636

3737
ttk.Label(self.mainVTURLframe, text="File path:").grid(column=0, row=2, sticky='W') # <== right-align
3838
self.filePath = StringVar()
39-
filePathEntry = ttk.Entry(self.mainVTURLframe, width=Consts.entry_width, textvariable=self.filePath, state='readonly')
39+
filePathEntry = ttk.Entry(self.mainVTURLframe, width=Consts.ENTRY_WIDTH, textvariable=self.filePath, state='readonly')
4040
filePathEntry.grid(column=1, row=2, sticky='W')
4141

4242
ttk.Label(self.mainVTURLframe, text="Status:").grid(column=0, row=3, sticky='W') # <== right-align
4343
self.status = StringVar()
44-
statusEntry = ttk.Entry(self.mainVTURLframe, width=Consts.entry_width, textvariable=self.status, state='readonly')
44+
statusEntry = ttk.Entry(self.mainVTURLframe, width=Consts.ENTRY_WIDTH, textvariable=self.status, state='readonly')
4545
statusEntry.grid(column=1, row=3, sticky='W')
4646

4747
ttk.Label(self.mainVTURLframe, text="Positive Indications:").grid(column=0, row=4, sticky='W') # <== right-align
4848
self.positiveIndications = StringVar()
49-
positiveIndicationsEntry = ttk.Entry(self.mainVTURLframe, width=Consts.entry_width, textvariable=self.positiveIndications,state='readonly')
49+
positiveIndicationsEntry = ttk.Entry(self.mainVTURLframe, width=Consts.ENTRY_WIDTH, textvariable=self.positiveIndications, state='readonly')
5050
positiveIndicationsEntry.grid(column=1, row=4, sticky='W')
5151

52-
ttk.Label(self.mainVTURLframe, text="SHA1:").grid(column=0, row=5,sticky='W') # <== right-align
52+
ttk.Label(self.mainVTURLframe, text="SHA1:").grid(column=0, row=5, sticky='W') # <== right-align
5353
self.sha1 = StringVar()
54-
sha1Entry = ttk.Entry(self.mainVTURLframe, width=Consts.entry_width, textvariable=self.sha1,state='readonly')
54+
sha1Entry = ttk.Entry(self.mainVTURLframe, width=Consts.ENTRY_WIDTH, textvariable=self.sha1, state='readonly')
5555
sha1Entry.grid(column=1, row=5, sticky='W')
5656

5757
ttk.Label(self.mainVTURLframe, text="SHA256:").grid(column=0, row=6, sticky='W') # <== right-align
5858
self.sha256 = StringVar()
59-
sha256Entry = ttk.Entry(self.mainVTURLframe, width=Consts.entry_width, textvariable=self.sha256,state='readonly')
59+
sha256Entry = ttk.Entry(self.mainVTURLframe, width=Consts.ENTRY_WIDTH, textvariable=self.sha256, state='readonly')
6060
sha256Entry.grid(column=1, row=6, sticky='W')
6161

62-
chooseFileButton = ttk.Button(self.mainVTURLframe, text="Choose File",width = 40,command=self._scanFile).grid(column=1, row=0)
62+
chooseFileButton = ttk.Button(self.mainVTURLframe, text="Choose File", width=40, command=self._scanFile).grid(column=1, row=0)
6363

64-
self.scanCheckingTimeInterval = 25000 # This is the amount of time we are going to wait before asking VT again if it already processed our scan request
64+
self.scanCheckingTimeInterval = 25000 # This is the amount of time we are going to wait before asking VT again if it already processed our scan request
6565

6666
for child in self.mainVTURLframe.winfo_children():
6767
child.grid_configure(padx=4, pady=2)
6868

69-
def showResults(self,results):
69+
def showResults(self, results):
7070
try:
7171
self.sha1.set(results["sha1"])
7272
self.sha256.set(results["sha256"])
7373
self.positiveIndications.set(results["positives"])
7474
except Exception as e:
7575
messagebox.showerror('Error', e)
7676

77-
78-
79-
8077
def checkStatus(self):
8178
try:
8279
self.scanResult = self.vtClient.get_file_report(self.scanID)
@@ -92,7 +89,6 @@ def checkStatus(self):
9289
self.showResults(self.scanResult)
9390
self.status.set("Finished!")
9491

95-
9692
self.progressBar['value'] = 100
9793
except Exception as e:
9894
if "To much API requests" in str(e):
@@ -101,10 +97,9 @@ def checkStatus(self):
10197
def _scanFile(self):
10298
try:
10399
self.progressBar['value'] = 0
104-
hasScanFinished = False
105-
filePath = filedialog.askopenfilename(initialdir = "/",title = "Select file for VT",filetypes = (("EXE files","*.exe"),("all files","*.*")))
100+
filePath = filedialog.askopenfilename(initialdir="/", title="Select file for VT", filetypes=(("EXE files", "*.exe"), ("all files", "*.*")))
106101

107-
if (filePath): # Only if the user chose a file, we will want to continue the process
102+
if (filePath): # Only if the user chose a file, we will want to continue the process
108103
self.filePath.set(filePath)
109104
self.status.set("Sending file...")
110105
self.progressBar['value'] = 10
@@ -116,9 +111,8 @@ def _scanFile(self):
116111
self.scanResult = self.vtClient.get_file_report(self.scanID)
117112
print(self.scanResult)
118113
self.checkStatus()
119-
# We could have been using time.sleep() or time.wait(), but then our UI would get stuck.
120-
# by using after, we are initiating a callback in which does not blocks our event loop
121-
114+
# We could have been using time.sleep() or time.wait(), but then our UI would get stuck.
115+
# by using after, we are initiating a callback in which does not blocks our event loop
122116

123117
except Exception as e:
124118
messagebox.showerror('Error', e)

VTPackage/IPReportTab.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# -*- coding: utf-8 -*-
22
"""This tab is in charge of sending sending IP addresses for investigation
33
4-
Some times, we will want the analyze certain IP address to understand if it is associated with malicious files or URLs
5-
VirusTotal gives us some useful information like where in the world this IP address hosted, and the amount of malicious
6-
files that was downloaded from it.
4+
Some times,
5+
we will want the analyze certain IP address to understand if it is associated with malicious files or URLs.
6+
VirusTotal gives us some useful information like where in the world this IP address hosted,
7+
and the amount of malicious files that was downloaded from it.
78
"""
89

910
from tkinter import ttk
@@ -14,57 +15,54 @@
1415

1516
class IPreportTab:
1617

17-
def __init__(self,root,frame, vtClient):
18+
def __init__(self, root, frame, vtClient):
1819
self.root = root
1920
self.frame = frame
2021
self.mainVTURLframe = ttk.LabelFrame(frame, text=' IP report tab!')
2122

22-
2323
# using the tkinter grid layout manager
2424
self.mainVTURLframe.grid(column=0, row=0, padx=8, pady=4)
2525
ttk.Label(self.mainVTURLframe, text="IP:").grid(column=0, row=0, sticky='W') # Sticky sayes where to stick the label to : N,S,E,W
26-
ipEntry = ttk.Entry(self.mainVTURLframe,width = Consts.entry_width)
26+
ipEntry = ttk.Entry(self.mainVTURLframe, width=Consts.ENTRY_WIDTH)
2727
ipEntry.grid(column=1, row=0, sticky='E')
2828

29-
3029
ttk.Label(self.mainVTURLframe, text="Country:").grid(column=0, row=1, sticky='W') # <== right-align
3130
Country = StringVar()
32-
CountryEntry = ttk.Entry(self.mainVTURLframe, width=Consts.entry_width, textvariable=Country, state='readonly')
31+
CountryEntry = ttk.Entry(self.mainVTURLframe, width=Consts.ENTRY_WIDTH, textvariable=Country, state='readonly')
3332
CountryEntry.grid(column=1, row=1, sticky='W')
3433

3534
ttk.Label(self.mainVTURLframe, text="Owner:").grid(column=0, row=2, sticky='W') # <== right-align
3635
Owner = StringVar()
37-
OwnerEntry = ttk.Entry(self.mainVTURLframe, width=Consts.entry_width, textvariable=Owner, state='readonly')
36+
OwnerEntry = ttk.Entry(self.mainVTURLframe, width=Consts.ENTRY_WIDTH, textvariable=Owner, state='readonly')
3837
OwnerEntry.grid(column=1, row=2, sticky='W')
3938

4039
ttk.Label(self.mainVTURLframe, text="Number of detected URLS:").grid(column=0, row=3, sticky='W') # <== right-align
4140
numberOfDetectedUrls = StringVar()
42-
numberOfDetectedUrlsEntry = ttk.Entry(self.mainVTURLframe, width=Consts.entry_width, textvariable=numberOfDetectedUrls, state='readonly')
41+
numberOfDetectedUrlsEntry = ttk.Entry(self.mainVTURLframe, width=Consts.ENTRY_WIDTH, textvariable=numberOfDetectedUrls, state='readonly')
4342
numberOfDetectedUrlsEntry.grid(column=1, row=3, sticky='W')
4443

4544
ttk.Label(self.mainVTURLframe, text="Number of detected malicious files:").grid(column=0, row=4, sticky='W') # <== right-align
4645
numberOfDownloadedMaliciousFiles = StringVar()
47-
numberOfDownloadedMaliciousFilesEntry = ttk.Entry(self.mainVTURLframe, width=Consts.entry_width, textvariable=numberOfDownloadedMaliciousFiles, state='readonly')
46+
numberOfDownloadedMaliciousFilesEntry = ttk.Entry(self.mainVTURLframe, width=Consts.ENTRY_WIDTH, textvariable=numberOfDownloadedMaliciousFiles, state='readonly')
4847
numberOfDownloadedMaliciousFilesEntry.grid(column=1, row=4, sticky='W')
4948

50-
self.notificationFrame = ttk.LabelFrame(self.frame, text=' Notifications', width=Consts.entry_width)
49+
self.notificationFrame = ttk.LabelFrame(self.frame, text=' Notifications', width=Consts.ENTRY_WIDTH)
5150
# using the tkinter grid layout manager
5251
self.notificationFrame.grid(column=0, row=1, padx=8, pady=10, sticky='W')
5352

5453
ttk.Label(self.notificationFrame, text="Errors:").grid(column=0, row=0, sticky='W') # <== increment row for each
5554
Error = StringVar()
56-
ErrorEntry = ttk.Entry(self.notificationFrame, width=Consts.entry_width, textvariable=Error, state='readonly')
55+
ErrorEntry = ttk.Entry(self.notificationFrame, width=Consts.ENTRY_WIDTH, textvariable=Error, state='readonly')
5756

5857
ErrorEntry.grid(column=1, row=0, sticky='W')
5958

6059
def _cleanErrorMessage(): # We could have been doing this without a function, but it is more neat that way
6160
Error.set("")
6261

63-
6462
def _getReport():
6563
# the _ notation before a function means that this function is internal to the class only. As python cannot really prevent you from using it outside the class (as C# for example) the notation is being used to warn other developers not to call this function outside the class
6664
try:
67-
_cleanErrorMessage() # Starting with cleaning the error message bar
65+
_cleanErrorMessage() # Starting with cleaning the error message bar
6866
if not ipEntry.get():
6967
errMessage = 'Please enter an IP address'
7068
print(errMessage)
@@ -76,12 +74,9 @@ def _getReport():
7674
print(response)
7775
Country.set(response["country"])
7876
Owner.set(response["as_owner"])
79-
numberOfDetectedUrls.set(len(response["detected_urls"])) # len helps us count the amount of items inside the list
77+
numberOfDetectedUrls.set(len(response["detected_urls"])) # len helps us count the amount of items inside the list
8078
numberOfDownloadedMaliciousFiles.set(len(response["detected_downloaded_samples"]))
8179

82-
83-
84-
8580
except Exception as e:
8681
print(e)
8782
Error.set(e)
@@ -93,5 +88,3 @@ def _getReport():
9388
child.grid_configure(padx=4, pady=2)
9489
for child in self.notificationFrame.winfo_children():
9590
child.grid_configure(padx=4, pady=2)
96-
97-

VTPackage/URLreportTab.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,25 @@
1111

1212

1313
class URLreportTab:
14-
def __init__(self,root,frame, vtClient):
14+
def __init__(self, root, frame, vtClient):
1515
self.root = root
1616
self.frame = frame
1717
self.mainVTURLframe = ttk.LabelFrame(frame, text=' URL report tab!')
1818

19-
2019
# using the tkinter grid layout manager
2120
self.mainVTURLframe.grid(column=0, row=0, padx=8, pady=4)
22-
ttk.Label(self.mainVTURLframe, text="URL:").grid(column=0, row=0, sticky='W') #What does sticky does? Sticky sayes where to stick the label to : N,S,E,W
23-
urlEntry = ttk.Entry(self.mainVTURLframe,width = Consts.entry_width)
21+
ttk.Label(self.mainVTURLframe, text="URL:").grid(column=0, row=0, sticky='W') # What does sticky does? Sticky sayes where to stick the label to : N,S,E,W
22+
urlEntry = ttk.Entry(self.mainVTURLframe, width=Consts.ENTRY_WIDTH)
2423
urlEntry.grid(column=1, row=0, sticky='E')
2524

2625
ttk.Label(self.mainVTURLframe, text="Positive Indications:").grid(column=0, row=1, sticky='W') # <== right-align
2726
Positive = StringVar()
28-
PositiveEntry = ttk.Entry(self.mainVTURLframe, width=Consts.entry_width, textvariable=Positive, state='readonly')
27+
PositiveEntry = ttk.Entry(self.mainVTURLframe, width=Consts.ENTRY_WIDTH, textvariable=Positive, state='readonly')
2928
PositiveEntry.grid(column=1, row=1, sticky='W')
3029

3130
ttk.Label(self.mainVTURLframe, text="Detections:").grid(column=0, row=2, sticky='W') # <== right-align
3231
detections = StringVar()
33-
detectionsEntry = ttk.Entry(self.mainVTURLframe, width=Consts.entry_width, textvariable=detections, state='readonly')
32+
detectionsEntry = ttk.Entry(self.mainVTURLframe, width=Consts.ENTRY_WIDTH, textvariable=detections, state='readonly')
3433
detectionsEntry.grid(column=1, row=2, sticky='W')
3534

3635
self.notificationFrame = ttk.LabelFrame(self.frame, text=' Notifications', width=40)
@@ -39,18 +38,17 @@ def __init__(self,root,frame, vtClient):
3938

4039
ttk.Label(self.notificationFrame, text="Errors:").grid(column=0, row=0, sticky='W') # <== increment row for each
4140
Error = StringVar()
42-
ErrorEntry = ttk.Entry(self.notificationFrame, width=Consts.entry_width, textvariable=Error, state='readonly')
41+
ErrorEntry = ttk.Entry(self.notificationFrame, width=Consts.ENTRY_WIDTH, textvariable=Error, state='readonly')
4342

4443
ErrorEntry.grid(column=1, row=0, sticky='W')
4544

4645
def _cleanErrorMessage(): # We could have been doing this without a function, but it is more neat that way
4746
Error.set("")
4847

49-
5048
def _getReport():
5149
# the _ notation before a function means that this function is internal to the class only. As python cannot really prevent you from using it outside the class (as C# for example) the notation is being used to warn other developers not to call this function outside the class
5250
try:
53-
_cleanErrorMessage() # Starting with cleaning the error message bar
51+
_cleanErrorMessage() # Starting with cleaning the error message bar
5452
if not urlEntry.get():
5553
print('Please enter a URL')
5654
Error.set("Please enter a URL!")
@@ -68,19 +66,14 @@ def _getReport():
6866
findings.add(value["result"])
6967
detections.set(",".join([str(finding) for finding in findings]))
7068

71-
7269
except Exception as e:
7370
print(e)
7471
Error.set(e)
7572

7673
checkURLinVTButton = ttk.Button(self.mainVTURLframe, text='Check in VT!', command=_getReport).grid(column=2, row=0)
7774

78-
#Instead of setting padding for each UI element, we can just iterate through the children of the main UI object.
75+
# Instead of setting padding for each UI element, we can just iterate through the children of the main UI object.
7976
for child in self.mainVTURLframe.winfo_children():
8077
child.grid_configure(padx=4, pady=2)
8178
for child in self.notificationFrame.winfo_children():
8279
child.grid_configure(padx=4, pady=2)
83-
84-
85-
86-

VTPackage/VTApp.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
"""This is the main window of our application
33
4-
In order to make our code neat and scalable, we want to create one main page and a class for any other tab.
4+
In order to make our code neat and scalable, we want to create one main page and a class for any other tab.
55
In that way, we are achieving control over our UI elements, while making sure it is easy to add new ones.
66
"""
77
# We are importing only the relevant libraries from tkinter
@@ -23,7 +23,7 @@
2323

2424
class VTApp:
2525
def __init__(self):
26-
#Loading the config file
26+
# Loading the config file
2727
self.config = configparser.ConfigParser()
2828
self.config.read('config.ini')
2929
self.virusTotalAPIkey = config['VirusTotal']['apiKey']
@@ -41,7 +41,6 @@ def __init__(self):
4141
if not self.vtClient.is_API_key_valid():
4242
messagebox.showerror('Error', "API key is not valid! Check your config file")
4343

44-
4544
def _quit():
4645
self.root.quit() # The app will exist when this function is called
4746
self.root.destroy()
@@ -51,12 +50,12 @@ def _quit():
5150
self.tabControl = ttk.Notebook(self.root) # Create Tab Control
5251

5352
self.urlFrame = ttk.Frame(self.tabControl)
54-
self.urlTab = URLreportTab.URLreportTab(self.root,self.urlFrame, self.vtClient)
55-
self.tabControl.add(self.urlFrame,text = 'URL')
53+
self.urlTab = URLreportTab.URLreportTab(self.root, self.urlFrame, self.vtClient)
54+
self.tabControl.add(self.urlFrame, text='URL')
5655

5756
self.ipFrame = ttk.Frame(self.tabControl)
58-
self.ipTab = IPReportTab.IPreportTab(self.tabControl,self.ipFrame, self.vtClient)
59-
self.tabControl.add(self.ipFrame, text = 'IP')
57+
self.ipTab = IPReportTab.IPreportTab(self.tabControl, self.ipFrame, self.vtClient)
58+
self.tabControl.add(self.ipFrame, text='IP')
6059

6160
self.fileFrame = ttk.Frame(self.tabControl)
6261
self.fileTab = FileReportTab.FileReportTab(self.tabControl, self.fileFrame, self.vtClient)
@@ -66,4 +65,3 @@ def _quit():
6665

6766
def start(self):
6867
self.root.mainloop()
69-

0 commit comments

Comments
 (0)