@staticmethod
    def Init():
        Log.info("Initializing BCache")
        if (BCache.bcache == None):
            boardf = open(Config.Config.GetBoardsFile(), 'r+b')
            if (boardf == None):
                Log.error("Cannot open boards file")
                raise ServerError("fail to open boards file")
            try:
                BCache.bcache = mmap.mmap(boardf.fileno(), Config.MAXBOARD * BoardHeader.size, flags = mmap.MAP_SHARED, prot = mmap.PROT_READ)
                if (BCache.bcache == None):
                    Log.error("Cannot mmap boards file")
                    raise ServerError("fail to mmap boards file")
            finally:
                boardf.close()
        Log.info("Got boards list")

        if (BCache.brdshm == None):
            try:
                Log.info("Attaching to BCache shared memory")
                BCache.brdshm = SharedMemory(Config.Config.GetInt("BCACHE_SHMKEY", 3693), size = BCache.BRDSHM_SIZE)
#                print "Got SHM"
#                for i in range(0, Config.MAXBOARD):
#                    bh = BoardHeader(i)
#                    if (bh.filename != ''):
#                        bs = BoardStatus(i)
#                        print "Board: ", bh.filename, " lastpost: ", bs.lastpost, " total: ", bs.total, " curruser: ", bs.currentusers
#                print BoardStatus.size
            except:
                # do initialization
                Log.info("Creating BCache shared memory")
                BCache.brdshm = SharedMemory(Config.Config.GetInt("BCACHE_SHMKEY", 3693), size = BCache.BRDSHM_SIZE, flags = IPC_CREAT, mode = 0660)
                fd = BCache.Lock()
                try:
                    maxbrd = -1
                    for i in range(0, Config.MAXBOARD):
                        bh = BoardHeader(i)
                        if (bh.filename != ''):
                            bs = BoardStatus(i)
                            board = Board(bh, bs, i)
                            board.UpdateLastPost()
                            maxbrd = i

                    if (maxbrd != -1):
                        BCache.SetBoardCount(maxbrd + 1)
                finally:
                    BCache.Unlock(fd)

        Log.info("BCache initialized")

        return
dataset/ETHPy150Open HenryHu/pybbs/BCache.py/BCache.Init/original