Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9f076b

Browse files
committed
code refactoring
1 parent 7877a93 commit f9f076b

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

lib/core/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,8 +1259,8 @@ def getConsoleWidth(default=80):
12591259

12601260
return width if width else default
12611261

1262-
def clearConsoleLine():
1263-
dataToStdout("\r%s\r" % (" " * (getConsoleWidth() - 1)))
1262+
def clearConsoleLine(forceOutput=False):
1263+
dataToStdout("\r%s\r" % (" " * (getConsoleWidth() - 1)), forceOutput)
12641264

12651265
def parseXmlFile(xmlFile, handler):
12661266
stream = StringIO(readCachedFileContent(xmlFile))

lib/core/testing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import time
1818

1919
from lib.controller.controller import start
20+
from lib.core.common import clearConsoleLine
2021
from lib.core.common import dataToStdout
2122
from lib.core.common import getCompiledRegex
22-
from lib.core.common import getConsoleWidth
2323
from lib.core.common import readXmlFile
2424
from lib.core.data import conf
2525
from lib.core.data import logger
@@ -65,7 +65,7 @@ def smokeTest():
6565
status = '%d/%d (%d%s) ' % (count, length, round(100.0*count/length), '%')
6666
dataToStdout("\r[%s] [INFO] complete: %s" % (time.strftime("%X"), status))
6767

68-
dataToStdout("\r%s\r" % (" "*(getConsoleWidth()-1)))
68+
clearConsoleLine()
6969
if retVal:
7070
logger.info("smoke test final result: PASSED")
7171
else:

lib/techniques/brute/use.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import time
1111

1212
from lib.core.agent import agent
13+
from lib.core.common import clearConsoleLine
1314
from lib.core.common import dataToStdout
14-
from lib.core.common import getConsoleWidth
1515
from lib.core.common import getFileItems
1616
from lib.core.common import popValue
1717
from lib.core.common import pushValue
@@ -42,8 +42,8 @@ def tableExists(tableFile):
4242
result = Request.queryPage(agent.payload(newValue=query))
4343

4444
if result:
45-
infoMsg = "\r[%s] [INFO] retrieved: %s" % (time.strftime("%X"), table)
46-
infoMsg = "%s%s\n" % (infoMsg, " "*(getConsoleWidth()-1-len(infoMsg)))
45+
clearConsoleLine(True)
46+
infoMsg = "\r[%s] [INFO] retrieved: %s\n" % (time.strftime("%X"), table)
4747
dataToStdout(infoMsg, True)
4848
retVal.append(table)
4949

@@ -53,7 +53,7 @@ def tableExists(tableFile):
5353

5454
conf.verbose = popValue()
5555

56-
dataToStdout("\n", True)
56+
clearConsoleLine(True)
5757

5858
if not retVal:
5959
warnMsg = "no table found"
@@ -93,8 +93,8 @@ def columnExists(columnFile):
9393
result = Request.queryPage(agent.payload(newValue=query))
9494

9595
if result:
96-
infoMsg = "\r[%s] [INFO] retrieved: %s" % (time.strftime("%X"), column)
97-
infoMsg = "%s%s\n" % (infoMsg, " "*(getConsoleWidth()-1-len(infoMsg)))
96+
clearConsoleLine(True)
97+
infoMsg = "\r[%s] [INFO] retrieved: %s\n" % (time.strftime("%X"), column)
9898
dataToStdout(infoMsg, True)
9999
retVal.append(column)
100100

@@ -104,7 +104,7 @@ def columnExists(columnFile):
104104

105105
conf.verbose = popValue()
106106

107-
dataToStdout("\n", True)
107+
clearConsoleLine(True)
108108

109109
if not retVal:
110110
warnMsg = "no column found"

0 commit comments

Comments
 (0)