Пример #1
0
def documentModules(moduleNames, exclude=[], destination=".", Path=None):
    """ Generates pydoc documentation for each module name given and outputs the HTML files into the destination directory.
        @input moduleNames - a list of names for the modules to document.
        @input exclude - a list of module and package names that should NOT be documented
        @input destination - a string indicating the directory path where the documentation HTML should be written.  Defaults to "."
        @input Path - any specific PATH to use?
        @return - a list of the filenames of all html files which were written.
    """

    # update the path variable with any special info
    sys.path.append(Path)
    
    writtenFiles = [] # list for all files that have been written
    
    # change to the appropriate directory
    os.chdir(destination)
    
    # loop through all the module names we were given
    for modName in moduleNames:
        
        # filter out any excluded modules
        for x in exclude:
            if modName.find(x) != -1:
                out.log("Skipping module " + modName)
                modName = ""

        # filter out bogus module names
        if modName == "":
            continue
    

        # import the module and write out the documentation for it.
        try:
            M = importModule(modName, Path=Path)

	    out.log("",nl=False)

            pydoc.writedoc(M)

            writtenFiles.append(modName+".html")
        except ImportError as e: # print error msg and proceed to next object
            out.log("Could not import module " + modName + " - " + str(e), err=True)
            continue

    return writtenFiles
Пример #2
0
def setUpDjango(djangoProjectPath, djangoSettingsModule="settings"):
	""" Sets up the django environment for a given project to help with the importing of django-related modules.
	    @input djangoProjectPath - the full directory path to the django project we'll be using.
	    @input djangoSettingsModule - the name of the python module to use as the settings for this project.  (default = "settings")
	""" 
	
	# generate the full module name for the settings module
	settingsModuleName = os.path.basename(djangoProjectPath) + "." + djangoSettingsModule
	try:
		# do all the important settings stuff 
		sys.path.append(os.path.abspath(djangoProjectPath+'/..'))
		os.environ['DJANGO_SETTINGS_MODULE'] = settingsModuleName
		from django.core.management import setup_environ
		settingsModule = importer.importModule(settingsModuleName)
		out.log("Configured PATH, loaded Django settings.")
		
		setup_environ(settingsModule)
		out.log("Set up Django Environment for project " + os.path.basename(djangoProjectPath)+".")
	except Exception as e:
		out.log("Could not set up Django environment - " + str(e), err=True)
		out.log("Is the Django settings module really called " + settingsModuleName + " ?")
		out.log("Proceeding anyway.  Many of the module imports may fail.", err=True)