1

I have a python script to update 4 authoritative geopackage files with additions and changes made to copies of the geopackages in the field (field geopackages). Once the new records and edited records within the field DB are copied to the authoritative geopackages my script closes the geopackages from QGIS, followed by cutting and pasting the processed field geopackages to an archive folder. This process works fine for 3/4 of the geopackages, but fails on the 4th. The geopackage I have this issue with is the the only 1 of 4 with a single layer/table.

The function I use to move the field geopackages to an archive folder is this:

def moveUpdatedInputs(incomingDataPath, processedDataPath):

    inP = incomingDataPath
    outP = processedDataPath
    ##get all geopackage files
    gpkgIn = findGPKG(inP)
    ##get time stamp
    t = time.localtime()
    tryAgainList =[]
    tStamp = time.strftime("_%Y_%m_%d_%H_%M_%S", t)
    ##create new save as names
    saveOutNames = []
    for item in gpkgIn:
        insertSpot = item.find(".")
        interimName = item[:insertSpot] + tStamp + item[insertSpot:]
        newName = interimName.replace(inP,outP)
        shutil.copyfile(item,newName)
        try:
            os.remove(item)
        except:
            print ("locked")
            tryAgainList.append(item)
    for item in tryAgainList:
        insertSpot = item.find(".")
        interimName = item[:insertSpot] + tStamp + item[insertSpot:]
        newName = interimName.replace(inP,outP)
        shutil.copyfile(item,newName)
        try:
            os.remove(item)
        except:
            print ("locked")
            #tryAgainList.append(item)
        

I access this script after creating the data syncing object, then deleting the data syncing object to unlock the files from QGIS. This works when entered line my line in the command line:

v1 = compareFMO_TableSettings(incomingDataPath,outgoingDataPath)
del(v1)
moveUpdatedInputs(incomingDataPath, processedDataPath)

But if I try to automate the commands with a function, it fails because the geopackage with one layer remains locked:

 def runner():
     v1 = compareFMO_TableSettings(incomingDataPath,outgoingDataPath)
     del(v1)
     moveUpdatedInputs(incomingDataPath, processedDataPath)

After adding a blank second table to the geopackage of concern everything works, so I have found a work around, but I cannot figure out why QGIS maintains a lock on a geopackage with a single layer when the geopackage is used within a python script but does not behave this way with a geopackage containing 2+ layers.

What I am looking for is a solution that can cut and paste geopackages containing only 1 layer after processing, whereas currently my solution only works for geopackages containing 2+ layers.

I am using QGIS 3.10.5, if that is a useful detail.

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.