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 mmap
|
||||
import xlrd
|
||||
import argparse
|
||||
import sqlite3
|
||||
@@ -109,7 +110,7 @@ def getDate(srcSheet):
|
||||
|
||||
def processDsw(file, database):
|
||||
# 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)
|
||||
|
||||
reportDate = getDate(srcSheet)
|
||||
@@ -129,13 +130,17 @@ def main():
|
||||
parser.add_argument("database")
|
||||
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
|
||||
conn = openDatabase(args.database)
|
||||
if conn == None:
|
||||
sys.exit('database could not be opened, does it exist')
|
||||
|
||||
if args.type == 'dsw':
|
||||
date, error = processDsw(args.inFile, conn)
|
||||
date, error = processDsw(mmapfile, conn)
|
||||
if not error:
|
||||
print(date)
|
||||
else:
|
||||
|
||||
@@ -5,6 +5,7 @@ from flaskfdx.tools import fdxsql
|
||||
|
||||
def validate_xls_file(file):
|
||||
if inspect_format(None, file.read()) == 'xls':
|
||||
file.stream.seek(0)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user