Skip to content

Commit 9473d07

Browse files
2 parents 3f6ec14 + 0d83a10 commit 9473d07

File tree

4 files changed

+511
-45
lines changed

4 files changed

+511
-45
lines changed

CodeBaseTools.py

+30-15
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@
203203
coding spcifiers shown above will be applied to every field of the appropriate type. If that is not what you
204204
want, process fields individually using replace() or curvalstrex().
205205
"""
206+
207+
from __future__ import print_function, absolute_import
206208
import decimal
207209
import os
208210
import csv
@@ -311,6 +313,7 @@ def __init__(self, bLargeMode=False):
311313
self.xNonPrintables[ord(c)] = None
312314
self.cbt = cbp
313315
self.nDataSession = self.cbt.initdatasession(bLargeMode)
316+
314317
self.oCSV = csv
315318
self.xLastFieldList = [] # Used by scattertorecord() to avoid having to repeat afields()
316319
self.cLastRecordAlias = "" # ditto
@@ -514,6 +517,7 @@ def use(self, tableName, alias="", readOnly=False, exclusive=False, noBuffering=
514517
self.cErrorMessage = "NO table name supplied"
515518
self.nErrorNumber = -49348
516519
return False
520+
517521
# if "LTLACCESSENABLE" in tableName:
518522
# import traceback
519523
# stack_str = ''.join(traceback.format_stack())
@@ -530,6 +534,7 @@ def use(self, tableName, alias="", readOnly=False, exclusive=False, noBuffering=
530534
if not lbReturn:
531535
self.cErrorMessage = self.cbt.geterrormessage() + " OPEN FAILED"
532536
self.nErrorNumber = self.cbt.geterrornumber()
537+
533538
return lbReturn
534539

535540
def maketempindex(self, lcExpr, tagFilter="", descending=0):
@@ -584,7 +589,7 @@ def selecttempindex(self, lnCode):
584589
lbReturn = self.cbt.selecttempindex(lnCode)
585590
if (not lbReturn):
586591
self.cErrorMessage = self.cbt.geterrormessage()
587-
self.nErrorNumber = self.cbt.geterrornumber()
592+
self.nErrorNumber = self.cbt.geterrornumber()
588593
return lbReturn
589594

590595
def closetempindex(self, lnCode):
@@ -2880,7 +2885,9 @@ def closetable(self, alias=""):
28802885
"""
28812886
self.cErrorMessage = ""
28822887
self.nErrorNumber = 0
2888+
cTable = self.dbf(alias)
28832889
lbReturn = self.cbt.closetable(alias)
2890+
28842891
if not lbReturn:
28852892
self.cErrorMessage = self.cbt.geterrormessage()
28862893
self.nErrorNumber = self.cbt.geterrornumber()
@@ -2936,6 +2943,7 @@ def closedatabases(self):
29362943
"""
29372944
self.cErrorMessage = ""
29382945
self.nErrorNumber = 0
2946+
29392947
lbReturn = self.cbt.closedatabases()
29402948
if not lbReturn:
29412949
self.cErrorMessage = self.cbt.geterrormessage()
@@ -3772,7 +3780,7 @@ def scan(self, indexTag="", forExpr="", noData=False, fieldList=None, getList=Fa
37723780
if self.cbt.geterrornumber() != 0:
37733781
self.cErrorMessage = self.cbt.geterrormessage()
37743782
self.nErrorNumber = self.cbt.geterrornumber()
3775-
raise ValueError("Scan failed with err: " + str(self.cErrorMessage))
3783+
raise ValueError("Scan failed with err: " + str(self.cErrorMessage)+ " " + self.dbf())
37763784
break
37773785
yield lxDict
37783786
if oCBT.alias() != lcCurrentTable:
@@ -3795,7 +3803,7 @@ def scan(self, indexTag="", forExpr="", noData=False, fieldList=None, getList=Fa
37953803
if self.cbt.geterrornumber() != 0:
37963804
self.cErrorMessage = self.cbt.geterrormessage()
37973805
self.nErrorNumber = self.cbt.geterrornumber()
3798-
raise ValueError("Scan failed with err: " + str(self.cErrorMessage))
3806+
raise ValueError("Scan failed with err: " + str(self.cErrorMessage) + " " + self.dbf())
37993807
break
38003808
yield lxDict
38013809
if oCBT.alias() != lcCurrentTable:
@@ -4096,7 +4104,7 @@ def makeXMLValueString(self, xValue, cType):
40964104

40974105
return cRet
40984106

4099-
def getNewKey( self, dataDir, filename=None, readOnly=False, stayOpen=False, noFlush=False):
4107+
def getNewKey(self, dataDir, filename=None, readOnly=False, stayOpen=False, noFlush=False):
41004108
"""
41014109
Copy of GetNewKey from VFP. Returns the next sequential key number for the passed filename or a negative
41024110
value on error. M-P System Services, Inc., specific code.
@@ -4122,7 +4130,7 @@ def getNewKey( self, dataDir, filename=None, readOnly=False, stayOpen=False, noF
41224130
by using a NextKey.dbf table to store the "next key" value of each table in your system. The NextKey.dbf
41234131
table is expected to have two fields:
41244132
Field Field Name Type Width Dec Index Collate Nulls Next Step
4125-
1 TABLE_NAME Character 15 Asc Machine No
4133+
1 TABLE_NAME Character 20 Asc Machine No
41264134
2 NEXTKEYVAL Integer 4 No
41274135
41284136
and to have an index called TABLE_NAME on UPPER(TABLE_NAME). The dataDir parameter tells the function
@@ -4293,17 +4301,22 @@ def openTableList(self, aTables, cPath=""):
42934301
self.cErrorMessage = "openTableList Failed because: %s, %d" % (self.cErrorMessage, self.nErrorNumber)
42944302
return lxReturn
42954303

4296-
_cbToolsobj = _cbTools() # always in use
4304+
4305+
# _cbToolsobj = _cbTools() # always in use
4306+
_cbToolsobj = None # Only instantiated if needed.
42974307
_cbToolsLargeobj = None # only instantiated if needed
42984308

42994309

43004310
def cbTools(bIsLarge=False):
43014311
global _cbToolsLargeobj
4312+
global _cbToolsobj
43024313
if bIsLarge:
43034314
if _cbToolsLargeobj is None:
43044315
_cbToolsLargeobj = _cbTools(True)
43054316
return _cbToolsLargeobj
43064317
else:
4318+
if _cbToolsobj is None:
4319+
_cbToolsobj = _cbTools()
43074320
return _cbToolsobj
43084321

43094322

@@ -4745,8 +4758,7 @@ def copydatatable(cTableName="", cSourceDir="", cTargetDir="", bByZap=False, oCB
47454758

47464759
def cbtWork():
47474760
tmpdir = 'c:\\MPSSPythonScripts\\TestDataOutput'
4748-
from MPSSCommon.MPSSBaseTools import confirmPath, DELETEFILE
4749-
if not confirmPath(tmpdir):
4761+
if not mTools.confirmPath(tmpdir):
47504762
tmpdir = ''
47514763
# Create Table Example #1
47524764
xFlds = list()
@@ -4773,7 +4785,7 @@ def cbtWork():
47734785
lnStart = time()
47744786

47754787
testname = os.path.join(tmpdir, "employee1.dbf")
4776-
DELETEFILE(testname)
4788+
mTools.DELETEFILE(testname)
47774789
print(testname)
47784790
bResult = vfp.createtable(testname, lcFld)
47794791
lnEnd = time()
@@ -4929,7 +4941,7 @@ def cbt_test():
49294941
vfp = cbTools()
49304942
vfp.use("e:\\loadbuilder2\\appdbfs\\73rdstrt\\shipmstr.dbf", alias="SHIPMSTR")
49314943
nStart = time()
4932-
nResult = vfp.copyto(cAlias="SHIPMSTR", cOutput=cDest, cType="DBF", cTestExpr='', bHeader=True, bStripBlanks=True)
4944+
nResult = vfp.copyto(cAlias="SHIPMSTR", cOutput=cDest, cType="DBF", cTestExpr='', bHeader=True, bStripBlanks=False)
49334945
nEnd = time()
49344946
vfp.closetable("SHIPMSTR")
49354947
print("ELAPSED TIME: ", (nEnd - nStart))
@@ -4939,8 +4951,8 @@ def cbt_test():
49394951
print("NRESULT: ", nResult)
49404952
# return True
49414953
tmpdir = 'c:\\MPSSPythonScripts\\TestDataOutput'
4942-
from MPSSCommon.MPSSBaseTools import confirmPath
4943-
if not confirmPath(tmpdir):
4954+
4955+
if not mTools.confirmPath(tmpdir):
49444956
tmpdir = ''
49454957
# Create Table Example #1
49464958
lcFld = "firstname,C,25,0,FALSE\n"
@@ -5181,6 +5193,8 @@ def cbt_test():
51815193
# return lbResult
51825194

51835195

5196+
__all__ = ["_cbTools", "cbTools", "cbToolsX", "TableObj", "copydatatable", "VFPFIELD"]
5197+
51845198
if __name__ == "__main__":
51855199
print("***** Testing CodeBaseTools.py components")
51865200
cbt_test()
@@ -5189,7 +5203,8 @@ def cbt_test():
51895203
print(lbResult)
51905204
print("***** Testing Complete")
51915205
if 'stop' in sys.argv:
5192-
raw_input('press <enter>')
5206+
if not _ver3x:
5207+
raw_input('press <enter>')
5208+
else:
5209+
input('press <enter>')
51935210

5194-
5195-

0 commit comments

Comments
 (0)