コード例 #1
0
ファイル: test_node.py プロジェクト: methane/markment
def test_open(io):
    ("Node#open should return an open file")
    io.open.return_value = 'an open file'

    nd = Node('/foo/bar')

    nd.open('wee.py').should.equal('an open file')
    io.open.assert_once_called_with('/foo/bar/wee.py')
コード例 #2
0
def save_sitemap(event, args, project, theme, generated):
    if not args.SITEMAP_PREFIX:
        return

    urlset = etree.Element("urlset")
    destination = Node(args.OUTPUT)

    NAME = 'sitemap.xml'

    for item in filter(lambda x: x.endswith('html'), generated):
        relative = destination.relative(item)
        url = etree.SubElement(urlset, "url")
        loc = etree.SubElement(url, "loc")
        loc.text = "{0}/{1}".format(
            args.SITEMAP_PREFIX.rstrip('/'),
            relative,
        )

    with destination.open(NAME, 'w') as f:
        f.write(etree.tostring(urlset, pretty_print=True).decode('utf-8'))