def processModule(targetModule, doc_destination, pyPath=None, excluded_modules=[]): """ Processes a module given by a target directory path and generates documentation @input targetModule - the full path to the module to be documented. @input pyPath - if the python path must be updated to help import this module, make those changes. Defaults to the directory above the requested module. @input excluded_modules - a list of strings representing modules and packages that should not be documented. @return - a list of strings representing the names of the html files created in the documentation process. """ # process default values for vars that cannot be set to "None" if pyPath == None: pyPath = targetModule + "/.." # Map out all the modules to document names = doc.indexPythonModule(targetModule) out.log("Found " + str(len(names)) + " modules to document in module " + str(os.path.basename(targetModule)) ) # change to the destination directory so pydoc can do its thing os.chdir(doc_destination) out.debugPrint("Changed working directory to " + os.getcwd()) # Generate their documentation sys.path.append(os.path.abspath(pyPath)) filenames = doc.documentModules(names, exclude=excluded_modules, destination=doc_destination ) out.log("Wrote documentation for " + str(len(filenames)) + " modules into directory:\n\t" + str(doc_destination)) return filenames
def indexPythonModule(path,force_walk=False): """ Walks through a python module importing the whole tree @input path - The path to the python module in question. @input force_walk - Forces the function to work on directories even if they are not python modules. TODO 7/18 - IMPLEMENT THIS FEATURE. @return - A list of strings, each string being the long module name of modules within the module given by path. Example - processPythonModule('/home/python/') => ["python.mod1", "python.mod2", "python.mod3.a", "python.mod3.b"] """ os.chdir(path) out.debugPrint("Directory is " + os.getcwd()) returnList = [] allFiles = os.listdir(os.getcwd()) dotdot, packageName = os.path.split(path) # get the containing folder and the name of this folder # check to see if this directory is a python package - if not, return [] if not "__init__.py" in allFiles and force_walk == False: return [] else: # if we are going to search this module, add its name to the returnList returnList.append(packageName) for F in allFiles: # ignore invisble files if F[0] == '.': continue if os.path.isdir(os.path.abspath(F)): # assert: F is a directory. Recur on it, then add packageName to each returned dirContents = indexPythonModule(os.path.abspath(F), force_walk) for x in dirContents: returnList.append(packageName + "." + x) os.chdir(path) # change back to the current directory continue else: # This is a regular file - if it's a .py file, append to the list name, ext = os.path.splitext(F) if ext != ".py": # check that our file is a .py file continue if name == "__init__": # do not process the init file continue returnList.append(packageName + "." + name) #print "Module " + returnList[-1] continue out.debugPrint(packageName + ": total " + str(len(returnList)) + " items.") return returnList
def writeDjangoUrlConfig(filenames, urlConfig_destination, urlConfig_name="apiUrls.py", templatePrefix='api/'): """ Creates a Django-style URL Configuration file for all the filenames specified. @input filenames - the file names to write into the urlConfig file @input urlConfig_destination - the destination for the apiUrls file @input urlConfig_name - urlconfig file name (default: 'apiUrls.py') @input templatePrefix - In the render_to_response call, should we look in a subdirectory of the templates dir? (default: 'api/') @return - none """ os.chdir(urlConfig_destination) out.debugPrint("Changed working directory to " + os.getcwd()) f = open(urlConfig_name,'w') # open the file for non-append writing out.log("Opened file for writing:\n\t" + os.path.abspath(f.name)) f.write(out.generateUrlPatterns(filenames, templatePrefix)) # write the urlpatterns to the file out.log("Wrote apiUrls.py file.") # finally, close the file f.close()