Settings.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:CorpBot.py 作者: corpnewt 项目源码 文件源码
def backup(self):
        # Wait initial time - then start loop
        await asyncio.sleep(self.backupWait)
        while not self.bot.is_closed:
            # Initial backup - then wait
            if not os.path.exists(self.backupDir):
                # Create it
                os.makedirs(self.backupDir)
            # Flush backup
            timeStamp = datetime.today().strftime("%Y-%m-%d %H.%M")
            self.flushSettings("./{}/Backup-{}.json".format(self.backupDir, timeStamp))

            # Get curr dir and change curr dir
            retval = os.getcwd()
            os.chdir(self.backupDir)

            # Get reverse sorted backups
            backups = sorted(os.listdir(os.getcwd()), key=os.path.getmtime)
            numberToRemove = None
            if len(backups) > self.backupMax:
                # We have more than 100 backups right now, let's prune
                numberToRemove = len(backups)-self.backupMax
                for i in range(0, numberToRemove):
                    os.remove(backups[i])

            # Restore curr dir
            os.chdir(retval)
            if numberToRemove:
                print("Settings Backed Up ({} removed): {}".format(numberToRemove, timeStamp))
            else:
                print("Settings Backed Up: {}".format(timeStamp))
            await asyncio.sleep(self.backupTime)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号