(self, cmd)
open ?OPTIONS? ?FILE?: Closes existing database and opens a different one

        Options are: --new which deletes the file if it already exists

        If FILE is omitted then a memory database is opened
open ?OPTIONS? ?FILE?: Closes existing database and opens a different one
open ?OPTIONS? ?FILE? : Closes existing database and opens a different one
def command_open(self, cmd):
        """open ?OPTIONS? ?FILE?: Closes existing database and opens a different one

        Options are: --new which deletes the file if it already exists

        If FILE is omitted then a memory database is opened
        """
        new = False
        dbname = None
        c = cmd
        while c:
            p = c.pop(0)
            if p.startswith("--"):
                if p == "--new":
                    new = True
                    continue
                raise self.Error("Unknown open param: " + p)
            if dbname:
                raise self.Error("Too many arguments: " + p)
            dbname = p

        if new and dbname:
            # close it first in case re-opening existing.  windows doesn't
            # allow deleting open files, tag alongs cause problems etc
            # hence retry and sleeps
            self.db = (None, None)
            for suffix in "", "-journal", "-wal", "-shm":
                fn = dbname + suffix
                for retry in range(1, 5):
                    try:
                        os.remove(fn)
                        break
                    except OSError:
                        if not os.path.isfile(fn):
                            break
                        # under windows tag alongs can delay being able to
                        # delete after we have closed the file
                        import gc
                        gc.collect(2)
                        time.sleep(.05 * retry)
                else:
                    os.rename(fn, fn + "-DELETEME")

        self.db = (None, dbname)
def command_open ( self , cmd ) : new = False dbname = None c = cmd while c : p = c . pop ( 0 ) if p . startswith ( "--" ) : if p == "--new" : new = True continue raise self . Error ( "Unknown open param: " + p ) if dbname : raise self . Error ( "Too many arguments: " + p ) dbname = p if new and dbname : # close it first in case re-opening existing.  windows doesn't # allow deleting open files, tag alongs cause problems etc # hence retry and sleeps self . db = ( None , None ) for suffix in "" , "-journal" , "-wal" , "-shm" : fn = dbname + suffix for retry in range ( 1 , 5 ) : try : os . remove ( fn ) break except OSError : if not os . path . isfile ( fn ) : break # under windows tag alongs can delay being able to # delete after we have closed the file import gc gc . collect ( 2 ) time . sleep ( .05 * retry ) else : os . rename ( fn , fn + "-DELETEME" ) self . db = ( None , dbname )