Start a new topic

pruning switches from flt crashes python

I have two scripts that are very similar to each other.  One removes switches from a database, and one removes everything except switches from a database.


I'm using a shell copy to make a duplicate of the db.flt.


My prune_non_switch script works fine on the copy, but the prune script fails on the source db file and I'm not sure why.


The script has been run without incident on several hundred other files.  I don't see why this one is special and could use some help figuring that out.


Thx


 

from mgapilib import *
import sys

mgInit (None, None)

print("\nOpening database: ",sys.argv[1],"\n")
db = mgOpenDb (sys.argv[1])
if db == None:
   print(mgGetLastError (), "\n")
   mgExit ()

def isNodeParent (parentNode, testChildren):
   for possibleChild in testChildren:
      testNode = possibleChild
      while testNode and testNode != db:
         if testNode == parentNode:
            return MG_TRUE   
         testNode = mgGetParent(testNode)
   return MG_FALSE
   
switchDepth = 0

def checkSwitch (db, parent, rec, data):
   global switchDepth
   if mgGetCode (rec) == fltSwitch:
      switchDepth = switchDepth + 1
   return MG_TRUE
   

def deleteSwitchNodes (db, parent, rec, deleteList):

   if mgGetCode (rec) == fltSwitch:
      mgDelete(rec)
      
   return MG_TRUE
   


#mgWalk (db, checkSwitch, deleteSwitchNodes, None, MWALK_NOREADONLY)

mgWalk (db, None, deleteSwitchNodes, None, MWALK_NOREADONLY)

mgWriteDb (db)

ok = mgCloseDb (db)
if ok == MG_FALSE:
   print("Error closing database\n")


mgExit()

 

zip

Was the db that failed open in creator when the script ran?


I ask because mgOpenDb will fail if Creator has it open already.

Thanks Chris.  Not positive, I don't think so, but I'll double check.

Nope.  I just copied a temp file from the original file, then closed creator, then ran the script and it still died.

Login to post a comment