use mmap in fdxsql tool to mathc how files are handled by flask upload
This commit is contained in:
@@ -8,6 +8,7 @@ report type, ie dsw, INFILE is an excel file, DATABASE is an sqlite file
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import mmap
|
||||||
import xlrd
|
import xlrd
|
||||||
import argparse
|
import argparse
|
||||||
import sqlite3
|
import sqlite3
|
||||||
@@ -109,7 +110,7 @@ def getDate(srcSheet):
|
|||||||
|
|
||||||
def processDsw(file, database):
|
def processDsw(file, database):
|
||||||
# open the excel sheet for reading
|
# open the excel sheet for reading
|
||||||
srcBook = xlrd.open_workbook(file)
|
srcBook = xlrd.open_workbook(file_contents=file.read())
|
||||||
srcSheet = srcBook.sheet_by_index(0)
|
srcSheet = srcBook.sheet_by_index(0)
|
||||||
|
|
||||||
reportDate = getDate(srcSheet)
|
reportDate = getDate(srcSheet)
|
||||||
@@ -129,13 +130,17 @@ def main():
|
|||||||
parser.add_argument("database")
|
parser.add_argument("database")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# open the file and create mmap object
|
||||||
|
file = open(args.inFile, 'r')
|
||||||
|
mmapfile = mmap.mmap(file.fileno(), length=0, access=mmap.ACCESS_READ)
|
||||||
|
|
||||||
#open the database
|
#open the database
|
||||||
conn = openDatabase(args.database)
|
conn = openDatabase(args.database)
|
||||||
if conn == None:
|
if conn == None:
|
||||||
sys.exit('database could not be opened, does it exist')
|
sys.exit('database could not be opened, does it exist')
|
||||||
|
|
||||||
if args.type == 'dsw':
|
if args.type == 'dsw':
|
||||||
date, error = processDsw(args.inFile, conn)
|
date, error = processDsw(mmapfile, conn)
|
||||||
if not error:
|
if not error:
|
||||||
print(date)
|
print(date)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from flaskfdx.tools import fdxsql
|
|||||||
|
|
||||||
def validate_xls_file(file):
|
def validate_xls_file(file):
|
||||||
if inspect_format(None, file.read()) == 'xls':
|
if inspect_format(None, file.read()) == 'xls':
|
||||||
|
file.stream.seek(0)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user