Пример #1
0
    for childNode in element.childNodes:
      parseTocElement(childNode, space + 2)


def getTocXml(src, space=0):
  url = os.path.join(urlPrefix, src)
  path = os.path.join(getRomnDir(), src)

  if not os.path.exists(os.path.dirname(path)):
    os.makedirs(os.path.dirname(path))

  download(url, path, space)

  dom = xml.dom.minidom.parse(path)
  parseTocElement(dom.documentElement, space)


if __name__ == '__main__':
  getTocXml(rootTocXmlSrc)

  # add this fake node to force stack update in next script
  infoFileContent += (u'2' + separator + u'fake')

  if not os.path.exists(os.path.dirname(getInfoFilePath())):
    os.makedirs(os.path.dirname(getInfoFilePath()))
  with open(getInfoFilePath(), 'w') as f:
    f.write(infoFileContent.encode('utf-8'))

  getPaliXml('cscd/tipitaka-latn.xsl', 0)
  getPaliXml('cscd/tipitaka-latn.css', 0)
Пример #2
0
        for childNode in element.childNodes:
            parseTocElement(childNode, space + 2)


def getTocXml(src, space=0):
    url = os.path.join(urlPrefix, src)
    path = os.path.join(getRomnDir(), src)

    if not os.path.exists(os.path.dirname(path)):
        os.makedirs(os.path.dirname(path))

    download(url, path, space)

    dom = xml.dom.minidom.parse(path)
    parseTocElement(dom.documentElement, space)


if __name__ == '__main__':
    getTocXml(rootTocXmlSrc)

    # add this fake node to force stack update in next script
    infoFileContent += (u'2' + separator + u'fake')

    if not os.path.exists(os.path.dirname(getInfoFilePath())):
        os.makedirs(os.path.dirname(getInfoFilePath()))
    with open(getInfoFilePath(), 'w') as f:
        f.write(infoFileContent.encode('utf-8'))

    getPaliXml('cscd/tipitaka-latn.xsl', 0)
    getPaliXml('cscd/tipitaka-latn.css', 0)
Пример #3
0
    # stack[-1]['dpeth'] = node['depth']
    deepestNode = stack.pop()
    deepestNode.pop('depth')
    stack[-1]['child'].append(deepestNode)
    if not isLeafNode(node):
      node['child'] = []
    stack.append(node)
    return stack


def infoFile2TreeviewData(path):
  rootNode = {'child': [], 'depth': 0}
  stack = [rootNode]
  with open(path, 'r') as f:
    for line in f.readlines():
      # remove '\n' and decode as utf-8
      line = line[:-1].decode('utf-8')
      # each line represents one node
      node = getNodeDict(line)
      stack = updateStack(stack, node)
  return rootNode


if __name__ == '__main__':
  treeviewData = infoFile2TreeviewData(getInfoFilePath())

  with open(getTreeviewJsonPath(), 'w') as f:
    f.write(json.dumps(treeviewData))

  prettyPrint(treeviewData)
Пример #4
0
        # stack[-1]['dpeth'] = node['depth']
        deepestNode = stack.pop()
        deepestNode.pop('depth')
        stack[-1]['child'].append(deepestNode)
        if not isLeafNode(node):
            node['child'] = []
        stack.append(node)
        return stack


def infoFile2TreeviewData(path):
    rootNode = {'child': [], 'depth': 0}
    stack = [rootNode]
    with open(path, 'r') as f:
        for line in f.readlines():
            # remove '\n' and decode as utf-8
            line = line[:-1].decode('utf-8')
            # each line represents one node
            node = getNodeDict(line)
            stack = updateStack(stack, node)
    return rootNode


if __name__ == '__main__':
    treeviewData = infoFile2TreeviewData(getInfoFilePath())

    with open(getTreeviewJsonPath(), 'w') as f:
        f.write(json.dumps(treeviewData))

    prettyPrint(treeviewData)