term_utils.py 文件源码

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

项目:walkdir-telegram-bot 作者: deepserket 项目源码 文件源码
def ls(self):
        """ Generate a list of InlineKeyboardButton of files and dir in current_dir """
        p = Popen('ls', cwd=self.current_dir, shell=True, stdout=PIPE, stderr=PIPE).communicate()

        files = str(p[0], 'utf-8').strip().split('\n') # Also contains directories
        files = [f for f in files if check_file(f)] # removing bad files...

        kb = []

        if self.current_dir != '/':
            kb.append([InlineKeyboardButton("..", callback_data='..d')])

        for f in files: # First the directories...
            path = os.path.join(self.current_dir, f)
            if os.path.isdir(path):
                kb.append([InlineKeyboardButton("dir: {}".format(f),
                            callback_data="{}d".format(f))])

        for f in files: # ...Then the files
            path = os.path.join(self.current_dir, f)
            if os.path.isfile(path):
                kb.append([InlineKeyboardButton("file: {}".format(f),
                            callback_data="{}f".format(f))])
        return kb
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号