FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sqlmap/lib/utils/progress.py at master · feixiang8418/sqlmap · GitHub
feixiang8418
/
sqlmap
Public
forked from
sqlmapproject/sqlmap
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
sqlmap
/
lib
/
utils
/
progress.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
108 lines (88 loc) · 3.57 KB
Breadcrumbs
sqlmap
/
lib
/
utils
/
progress.py
Copy path
File metadata and controls
108 lines (88 loc) · 3.57 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python
"""
Copyright (c) 2006-2014 sqlmap developers (http://sqlmap.org/)
See the file 'doc/COPYING' for copying permission
"""
from
lib
.
core
.
common
import
getUnicode
from
lib
.
core
.
common
import
dataToStdout
from
lib
.
core
.
data
import
conf
from
lib
.
core
.
data
import
kb
class
ProgressBar
(
object
):
"""
This class defines methods to update and draw a progress bar
"""
def
__init__
(
self
,
minValue
=
0
,
maxValue
=
10
,
totalWidth
=
None
):
self
.
_progBar
=
"[]"
self
.
_oldProgBar
=
""
self
.
_min
=
int
(
minValue
)
self
.
_max
=
int
(
maxValue
)
self
.
_span
=
max
(
self
.
_max
-
self
.
_min
,
0.001
)
self
.
_width
=
totalWidth
if
totalWidth
else
conf
.
progressWidth
self
.
_amount
=
0
self
.
_times
=
[]
self
.
update
()
def
_convertSeconds
(
self
,
value
):
seconds
=
value
minutes
=
seconds
/
60
seconds
=
seconds
-
(
minutes
*
60
)
return
"%.2d:%.2d"
%
(
minutes
,
seconds
)
def
update
(
self
,
newAmount
=
0
):
"""
This method updates the progress bar
"""
if
newAmount
<
self
.
_min
:
newAmount
=
self
.
_min
elif
newAmount
>
self
.
_max
:
newAmount
=
self
.
_max
self
.
_amount
=
newAmount
# Figure out the new percent done, round to an integer
diffFromMin
=
float
(
self
.
_amount
-
self
.
_min
)
percentDone
=
(
diffFromMin
/
float
(
self
.
_span
))
*
100.0
percentDone
=
round
(
percentDone
)
percentDone
=
min
(
100
,
int
(
percentDone
))
# Figure out how many hash bars the percentage should be
allFull
=
self
.
_width
-
len
(
"100%% [] %s/%s ETA 00:00"
%
(
self
.
_max
,
self
.
_max
))
numHashes
=
(
percentDone
/
100.0
)
*
allFull
numHashes
=
int
(
round
(
numHashes
))
# Build a progress bar with an arrow of equal signs
if
numHashes
==
0
:
self
.
_progBar
=
"[>%s]"
%
(
" "
*
(
allFull
-
1
))
elif
numHashes
==
allFull
:
self
.
_progBar
=
"[%s]"
%
(
"="
*
allFull
)
else
:
self
.
_progBar
=
"[%s>%s]"
%
(
"="
*
(
numHashes
-
1
),
" "
*
(
allFull
-
numHashes
))
# Add the percentage at the beginning of the progress bar
percentString
=
getUnicode
(
percentDone
)
+
"%"
self
.
_progBar
=
"%s %s"
%
(
percentString
,
self
.
_progBar
)
def
progress
(
self
,
deltaTime
,
newAmount
):
"""
This method saves item delta time and shows updated progress bar with calculated eta
"""
if
len
(
self
.
_times
)
<=
((
self
.
_max
*
3
)
/
100
)
or
newAmount
>
self
.
_max
:
eta
=
None
else
:
midTime
=
sum
(
self
.
_times
)
/
len
(
self
.
_times
)
midTimeWithLatest
=
(
midTime
+
deltaTime
)
/
2
eta
=
midTimeWithLatest
*
(
self
.
_max
-
newAmount
)
self
.
_times
.
append
(
deltaTime
)
self
.
update
(
newAmount
)
self
.
draw
(
eta
)
def
draw
(
self
,
eta
=
None
):
"""
This method draws the progress bar if it has changed
"""
if
self
.
_progBar
!=
self
.
_oldProgBar
:
self
.
_oldProgBar
=
self
.
_progBar
dataToStdout
(
"
\r
%s %d/%d%s"
%
(
self
.
_progBar
,
self
.
_amount
,
self
.
_max
, (
" ETA %s"
%
self
.
_convertSeconds
(
int
(
eta
)))
if
eta
is
not
None
else
""
))
if
self
.
_amount
>=
self
.
_max
:
if
not
conf
.
liveTest
:
dataToStdout
(
"
\r
%s
\r
"
%
(
" "
*
self
.
_width
))
kb
.
prependFlag
=
False
else
:
dataToStdout
(
"
\n
"
)
def
__str__
(
self
):
"""
This method returns the progress bar string
"""
return
getUnicode
(
self
.
_progBar
)
Back
|
FazBrowse Home
|
New Git URL