Example #1
0
	def save(self, savepath):
		"""Saves documentation to the given file path."""

		if self.pages is None:
			self.log.info("Couldn't get any information about the module.")

		for page in self.pages:
			newpath = savepath + '/' + page
			ghtml.forcedir(os.path.split(newpath)[0])
			with open(savepath + '/' + page, 'w') as doc:
				doc.write(self.pages[page])

		pass
Example #2
0
def main():
	log = logging.getLogger("GracefulDocs")

	# get the output folder for the documentation
	if len(sys.argv) > 2:
		outdir = sys.argv[2]
	else:
		outdir = input("Enter a folder for the HTML documentation to be written to (just '.' for current directory); enter '*quit' or '*q' to cancel:  ")
	
	# get the name of the module/file to be documented
	if len(sys.argv) > 1:
		modulename = sys.argv[1]
	else:
		modulename = input("Please enter module name to document:  ")

	# check if user asked for help
	if re.match("(-+)h | (-+)help | (\?+)", modulename.lower()):
		print("Module name must be in your system path or current working directory")

	if outdir.lower() == ['*quit']:
		exit()

	# get the full path from the relative path the user entered
	outdir = os.path.abspath(outdir)
	log.debug(outdir)

	# create the output folder for documentation if it doesn't already exist
	if not os.path.isdir(outdir):
		uin = input("This directory does not yet exist. Would you like to create it? (Y/N) ")

		if uin.lower() in "yes":
			ghtml.forcedir(os.path.abspath(outdir))
		else:
			log.info("Cancelling doc creation...")
			exit()


	# generate the docs and save
	html = Generator(modulename)
	html.save(outdir)

	log.info("Documenation written to " + outdir + " .")
	u_open = input("Open in browser now? (Y/N) ")

	if u_open.lower() in ['y', 'yes']:
		webbrowser.open(url = os.path.abspath(outdir + '/index.html'), new = 2)

	pass