zettelparser.py 文件源码

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

项目:Zettels 作者: sthesing 项目源码 文件源码
def _parse_metadata(rootdir, for_yaml, index):
        origcwd = os.getcwd()
        os.chdir(rootdir)
        logger.debug("Parsing metadata:")
        for f in for_yaml:
            # Make the path to the file relative to the root directory
            #f = os.path.relpath(f, rootdir)

            logger.debug("Current file:")
            logger.debug(f)
            #only if there is more than the backbone.
            if for_yaml[f]['start'] != '':
                logger.debug("start: " + for_yaml[f]['start'])
                logger.debug("stop: " + for_yaml[f]['stop'])
                y = ''
                for i in range(
                    int(for_yaml[f]['start']), 
                    int(for_yaml[f]['stop'])
                    ):
                    y = y + linecache.getline(f, i)

                logger.debug("y: " + str(y))

                metadata = yaml.safe_load(y)
                #write the metadata to the index.
                for item in metadata:
                    index['files'][f][item] = metadata[item]

        linecache.clearcache()
        os.chdir(origcwd)
        logger.debug("Parsing metadata: Done.")
        return index
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号