Example #1
0
def exportTopicTree(moduleName = None, rootTopicName=None, rootTopic=None, 
    bak='bak', moduleDoc=None):
    '''Export the topic tree to a string and return the string.
    The export only traverses the children of rootTopic. Notes:

    - If moduleName is given, the string is also written to moduleName.py in
      os.getcwd() (the file is overwritten). If bak is not None, the module file
      is first copied to moduleName.py.bak. 
    - If rootTopicName or rootTopic are not specified, the pub.ALL_TOPICS
      topic will used.
    - The moduleDoc is the doc string for the module.
    - If importTopicTree() was called with lazy=True, then only those topics
      that were used by application will be exported.'''

    if rootTopicName:
        rootTopic = _topicMgr.getTopic(rootTopicName)
    if rootTopic is None:
        rootTopic = getDefaultRootAllTopics()
        
    # create exporter
    if moduleName is None:
        from StringIO import StringIO
        capture = StringIO()
        exportTreeAsSpec(rootTopic, fileObj=capture, treeDoc=moduleDoc)
        return capture.getvalue()
        
    else:
        filename = '%s.py' % moduleName
        if bak:
            _backupIfExists(filename, bak)
        moduleFile = file(filename, 'w')
        try:
            exportTreeAsSpec(rootTopic, fileObj=moduleFile, treeDoc=moduleDoc)
        finally:
            moduleFile.close()
Example #2
0
def exportTopicTree(moduleName = None, rootTopicName=None, rootTopic=None, 
    bak='bak', moduleDoc=None):
    '''Export the topic tree to a string and return the string. Parameters:

        - If moduleName is given, the string is also written to moduleName.py in
          os.getcwd() (the file is overwritten). If bak is None, the module file
          is not backed up. 
        - If rootTopicName or rootTopic are specified, the export only traverses 
          tree from corresponding topic. Otherwise, pub.ALL_TOPICS is starting point. 
        - The moduleDoc is the doc string for the module.
    '''

    if rootTopicName:
        rootTopic = _topicMgr.getTopic(rootTopicName)
    if rootTopic is None:
        rootTopic = getDefaultRootAllTopics()
        
    # create exporter
    if moduleName is None:
        from StringIO import StringIO
        capture = StringIO()
        exportTreeAsSpec(rootTopic, fileObj=capture, treeDoc=moduleDoc)
        return capture.getvalue()
        
    else:
        filename = '%s.py' % moduleName
        if bak:
            _backupIfExists(filename, bak)
        moduleFile = file(filename, 'w')
        try:
            exportTreeAsSpec(rootTopic, fileObj=moduleFile, treeDoc=moduleDoc)
        finally:
            moduleFile.close()
Example #3
0
def exportTopicTree(moduleName=None,
                    rootTopicName=None,
                    rootTopic=None,
                    bak='bak',
                    moduleDoc=None):
    '''Export the topic tree to a string and return the string.
    The export only traverses the children of rootTopic. Notes:

    - If moduleName is given, the string is also written to moduleName.py in
      os.getcwd() (the file is overwritten). If bak is not None, the module file
      is first copied to moduleName.py.bak. 
    - If rootTopicName or rootTopic are not specified, the pub.ALL_TOPICS
      topic will used.
    - The moduleDoc is the doc string for the module.
    - If importTopicTree() was called with lazy=True, then only those topics
      that were used by application will be exported.'''

    if rootTopicName:
        rootTopic = _topicMgr.getTopic(rootTopicName)
    if rootTopic is None:
        rootTopic = getDefaultRootAllTopics()

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

    else:
        filename = '%s.py' % moduleName
        if bak:
            _backupIfExists(filename, bak)
        moduleFile = file(filename, 'w')
        try:
            exportTreeAsSpec(rootTopic, fileObj=moduleFile, treeDoc=moduleDoc)
        finally:
            moduleFile.close()
Example #4
0
def exportTopicTree(moduleName=None,
                    rootTopicName=None,
                    rootTopic=None,
                    bak='bak',
                    moduleDoc=None):
    '''Export the topic tree to a string and return the string. Parameters:

        - If moduleName is given, the string is also written to moduleName.py in
          os.getcwd() (the file is overwritten). If bak is None, the module file
          is not backed up. 
        - If rootTopicName or rootTopic are specified, the export only traverses 
          tree from corresponding topic. Otherwise, pub.ALL_TOPICS is starting point. 
        - The moduleDoc is the doc string for the module.
    '''

    if rootTopicName:
        rootTopic = _topicMgr.getTopic(rootTopicName)
    if rootTopic is None:
        rootTopic = getDefaultRootAllTopics()

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

    else:
        filename = '%s.py' % moduleName
        if bak:
            _backupIfExists(filename, bak)
        moduleFile = file(filename, 'w')
        try:
            exportTreeAsSpec(rootTopic, fileObj=moduleFile, treeDoc=moduleDoc)
        finally:
            moduleFile.close()