(moduleName: str = None, rootTopic: Union[Topic, str] = None,
                        bak: str = 'bak', moduleDoc: str = None)
Using TopicTreeSpecPrinter, exports the topic tree rooted at rootTopic to a
    Python module (.py) file. This module will define module-level classes
    representing root topics, nested classes for subtopics etc. Returns a string
    representing the contents of the file. Parameters:

        - If moduleName is given, the topic tree is written to moduleName.py in
          os.getcwd(). By default, it is first backed up, it it already exists,
          using bak as the filename extension. If bak is None, existing module file
          gets overwritten.
        - If rootTopic is specified, the export only traverses tree from
          corresponding topic. Otherwise, complete tree, using
          pub.getDefaultTopicTreeRoot() as starting  point.
        - The moduleDoc is the doc string for the module ie topic tree.
Using TopicTreeSpecPrinter, exports the topic tree rooted at rootTopic to a
    Python module (.py) file. This module will define module-level classes
    representing root topics, nested classes for subtopics etc. Returns a string
    representing the contents of the file. Parameters:
Using TopicTreeSpecPrinter exports the topic tree rooted at rootTopic to a Python module ( . py ) file . This module will define module - level classes representing root topics nested classes for subtopics etc . Returns a string representing the contents of the file . Parameters :
def exportTopicTreeSpec(moduleName: str = None, rootTopic: Union[Topic, str] = None,
                        bak: str = 'bak', moduleDoc: str = None):
    """
    Using TopicTreeSpecPrinter, exports the topic tree rooted at rootTopic to a
    Python module (.py) file. This module will define module-level classes
    representing root topics, nested classes for subtopics etc. Returns a string
    representing the contents of the file. Parameters:

        - If moduleName is given, the topic tree is written to moduleName.py in
          os.getcwd(). By default, it is first backed up, it it already exists,
          using bak as the filename extension. If bak is None, existing module file
          gets overwritten.
        - If rootTopic is specified, the export only traverses tree from
          corresponding topic. Otherwise, complete tree, using
          pub.getDefaultTopicTreeRoot() as starting  point.
        - The moduleDoc is the doc string for the module ie topic tree.
    """

    if rootTopic is None:
        from .. import pub
        rootTopic = pub.getDefaultTopicMgr().getRootAllTopics()
    elif isinstance(rootTopic, str):
        from .. import pub
        rootTopic = pub.getDefaultTopicMgr().getTopic(rootTopic)

    # create exporter
    if moduleName is None:
        capture = io.StringIO()
        TopicTreeSpecPrinter(rootTopic, fileObj=capture, treeDoc=moduleDoc)
        return capture.getvalue()

    else:
        filename = '%s.py' % moduleName
        if bak:
            _backupIfExists(filename, bak)
        moduleFile = open(filename, 'w')
        try:
            TopicTreeSpecPrinter(rootTopic, fileObj=moduleFile, treeDoc=moduleDoc)
        finally:
            moduleFile.close()
def exportTopicTreeSpec ( moduleName : str = None , rootTopic : Union [ Topic , str ] = None , bak : str = 'bak' , moduleDoc : str = None ) : if rootTopic is None : from . . import pub rootTopic = pub . getDefaultTopicMgr ( ) . getRootAllTopics ( ) elif isinstance ( rootTopic , str ) : from . . import pub rootTopic = pub . getDefaultTopicMgr ( ) . getTopic ( rootTopic ) # create exporter if moduleName is None : capture = io . StringIO ( ) TopicTreeSpecPrinter ( rootTopic , fileObj = capture , treeDoc = moduleDoc ) return capture . getvalue ( ) else : filename = '%s.py' % moduleName if bak : _backupIfExists ( filename , bak ) moduleFile = open ( filename , 'w' ) try : TopicTreeSpecPrinter ( rootTopic , fileObj = moduleFile , treeDoc = moduleDoc ) finally : moduleFile . close ( )