65 lines
1.4 KiB
Python
65 lines
1.4 KiB
Python
#
|
|
#
|
|
#
|
|
import re
|
|
import time
|
|
|
|
#
|
|
class ToolBox:
|
|
"""
|
|
Various tools
|
|
"""
|
|
#
|
|
# -c tablename:colName,colName2 userstable:names,ages
|
|
# -b tablename:colName,colName2 userstable:names,ages
|
|
#
|
|
# TODO: change the split to a smart regex, instead of spliting on space
|
|
#
|
|
@staticmethod
|
|
def parseColParams(param):
|
|
tblCols = {}
|
|
tables = param.split()
|
|
for table in tables:
|
|
cols = table.split(':')
|
|
tblCols[cols[0]] = cols[1].split(',')
|
|
return tblCols
|
|
|
|
#
|
|
@staticmethod
|
|
def parseFilename(fqfilepath):
|
|
filename = 'fingerprint'
|
|
try:
|
|
results = re.search(r'.*[\\/](\S*)\..*', fqfilepath)
|
|
if len(results.group(1)) != 0:
|
|
filename = results.group(1)
|
|
except:
|
|
filename = fqfilepath
|
|
return filename
|
|
|
|
#
|
|
@staticmethod
|
|
def parseFilenameIncExt(fqfilepath):
|
|
results = re.search(r'.*[\\/](\S*\..*)', fqfilepath)
|
|
if len(results.group(1)) != 0:
|
|
filename = results.group(1)
|
|
return filename
|
|
|
|
#
|
|
@staticmethod
|
|
def getTimestampFilename(fqfilename):
|
|
""" return output file name """
|
|
timestr = ToolBox.getTimestampStr()
|
|
filename = ToolBox.parseFilename(fqfilename)
|
|
fileout = filename + "__" + timestr + '.json'
|
|
return fileout
|
|
|
|
#
|
|
@staticmethod
|
|
def getTimestampStr():
|
|
timestr = '000'
|
|
try:
|
|
timestr = time.strftime('%Y-%m-%d_%H%M%S', time.localtime(time.time()))
|
|
except:
|
|
pass
|
|
return timestr
|