def main(argv): p = optparse.OptionParser() p.add_option("-d", "--directory", metavar="OUTPUTDIRECTORY", default=".", help="Directory path in which to write the output files.") options, arguments = p.parse_args() output_dir = os.path.abspath(os.path.expanduser(options.directory)) if not os.path.exists(output_dir): os.makedirs(output_dir) for processor_name in processor_names(): processor_class = get_processor(processor_name) try: description = processor_class.description except AttributeError: try: description = processor_class.__doc__ except AttributeError: description = "" try: input_vars = processor_class.input_variables except AttributeError: input_vars = {} try: output_vars = processor_class.output_variables except AttributeError: output_vars = {} filename = "Processor-%s.md" % processor_name pathname = os.path.join(output_dir, filename) output = "# %s\n" % escape(processor_name) output += "\n" output += "## Description\n%s\n" % escape(description) output += "\n" output += "## Input Variables\n" output += generate_markdown(input_vars) output += "\n" output += "## Output Variables\n" output += generate_markdown(output_vars) output += "\n" writefile(output, pathname) toc_string = " * Processors\n" for processor_name in processor_names(): page_name = "Processor-%s" % processor_name page_name.replace(" ", "-") toc_string += " * [[%s|%s]]\n" % (processor_name, page_name) pathname = os.path.join(output_dir, "_processor-toc.md") writefile(toc_string, pathname)
def generate_sidebar(sidebar_path): """Generate new _Sidebar.md contents.""" # Generate the Processors section of the Sidebar processor_heading = " * **Processor Reference**" toc_string = "" toc_string += processor_heading + "\n" for processor_name in sorted(processor_names(), key=lambda s: s.lower()): page_name = f"Processor-{processor_name}" page_name.replace(" ", "-") toc_string += f" * [[{processor_name}|{page_name}]]\n" with open(sidebar_path, "r") as fdesc: current_sidebar_lines = fdesc.read().splitlines() # Determine our indent amount section_indent = indent_length(processor_heading) past_processors_section = False for index, line in enumerate(current_sidebar_lines): if line == processor_heading: past_processors_section = True processors_start = index if (indent_length(line) <= section_indent) and past_processors_section: processors_end = index # Build the new sidebar new_sidebar = "" new_sidebar += "\n".join(current_sidebar_lines[0:processors_start]) + "\n" new_sidebar += toc_string new_sidebar += "\n".join(current_sidebar_lines[processors_end:]) + "\n" return new_sidebar
def generate_sidebar(sidebar_path): """Generate new _Sidebar.md contents.""" # Generate the Processors section of the Sidebar processor_heading = " * **Processor Reference**" toc_string = "" toc_string += processor_heading + "\n" for processor_name in sorted(processor_names(), key=lambda s: s.lower()): page_name = "Processor-%s" % processor_name page_name.replace(" ", "-") toc_string += " * [[%s|%s]]\n" % (processor_name, page_name) with open(sidebar_path, "r") as fdesc: current_sidebar_lines = fdesc.read().splitlines() # Determine our indent amount section_indent = indent_length(processor_heading) past_processors_section = False for index, line in enumerate(current_sidebar_lines): if line == processor_heading: past_processors_section = True processors_start = index if (indent_length(line) <= section_indent) and past_processors_section: processors_end = index # Build the new sidebar new_sidebar = "" new_sidebar += "\n".join(current_sidebar_lines[0:processors_start]) + "\n" new_sidebar += toc_string new_sidebar += "\n".join(current_sidebar_lines[processors_end:]) + "\n" return new_sidebar
def validate_proc_args(process, filename): """Warn if invalid processor arguments are used.""" passed = True # List of argument names (lowercase) that will not be flagged as invalid. ignored_args = ("note", "notes", "comment", "comments") # Create dictionary of AutoPkg core processors and their inputs. core_procs = {} for proc in processor_names(): if hasattr(get_processor(proc), "input_variables"): core_procs[proc] = get_processor(proc).input_variables else: core_procs[proc] = {} for proc in process: if proc["Processor"] not in core_procs: # Skip input variable validation for non-core processors. continue for arg in proc.get("Arguments", {}): if arg.lower() in ignored_args: # Skip args in ignored list above. continue if not core_procs[proc["Processor"]]: print("{}: Unknown argument {} for processor {}, " "which does not accept any arguments.".format( filename, arg, proc["Processor"], )) passed = False elif arg not in core_procs[proc["Processor"]]: print("{}: Unknown argument {} for processor {}. " "Allowed arguments are: {}".format( filename, arg, proc["Processor"], ", ".join(core_procs[proc["Processor"]]), )) passed = False return passed
def main(_): """Do it all""" usage = """%prog VERSION ..where VERSION is the release version for which docs are being generated.""" parser = optparse.OptionParser(usage=usage) parser.description = ( "Generate GitHub Wiki documentation from the core processors present " "in autopkglib. The autopkg.wiki repo is cloned locally, changes are " "committed, a diff shown and the user is interactively given the " "option to push to the remote.") parser.add_option( "-d", "--directory", metavar="CLONEDIRECTORY", help=("Directory path in which to clone the repo. If not " "specified, a temporary directory will be used.")) options, arguments = parser.parse_args() if len(arguments) < 1: parser.print_usage() exit() # Grab the version for the commit log. version = arguments[0] print "Cloning AutoPkg wiki.." print if options.directory: output_dir = clone_wiki_dir(clone_dir=options.directory) else: output_dir = clone_wiki_dir() print "Cloned to %s." % output_dir print print # Generate markdown pages for each processor attributes for processor_name in processor_names(): processor_class = get_processor(processor_name) try: description = processor_class.description except AttributeError: try: description = processor_class.__doc__ except AttributeError: description = "" try: input_vars = processor_class.input_variables except AttributeError: input_vars = {} try: output_vars = processor_class.output_variables except AttributeError: output_vars = {} filename = "Processor-%s.md" % processor_name pathname = os.path.join(output_dir, filename) output = "# %s\n" % escape(processor_name) output += "\n" output += "## Description\n%s\n" % escape(description) output += "\n" output += "## Input Variables\n" output += generate_markdown(input_vars) output += "\n" output += "## Output Variables\n" output += generate_markdown(output_vars) output += "\n" writefile(output, pathname) # Generate the Processors section of the Sidebar processor_heading = " * **Processors**" toc_string = "" toc_string += processor_heading + "\n" for processor_name in processor_names(): page_name = "Processor-%s" % processor_name page_name.replace(" ", "-") toc_string += " * [[%s|%s]]\n" % (processor_name, page_name) # Merge in the new stuff! # - Scrape through the current _Sidebar.md, look for where the existing # processors block starts and ends # - Copy the lines up to where the Processors section starts # - Copy the new Processors TOC # - Copy the lines following the Processors section sidebar_path = os.path.join(output_dir, "_Sidebar.md") with open(sidebar_path, "r") as fdesc: current_sidebar_lines = fdesc.read().splitlines() # Determine our indent amount section_indent = indent_length(processor_heading) past_processors_section = False for index, line in enumerate(current_sidebar_lines): if line == processor_heading: past_processors_section = True processors_start = index if (indent_length(line) <= section_indent) and \ past_processors_section: processors_end = index # Build the new sidebar new_sidebar = "" new_sidebar += "\n".join(current_sidebar_lines[0:processors_start]) + "\n" new_sidebar += toc_string new_sidebar += "\n".join(current_sidebar_lines[processors_end:]) + "\n" with open(sidebar_path, "w") as fdesc: fdesc.write(new_sidebar) # Git commit everything os.chdir(output_dir) run_git(["add", "--all"]) run_git(["commit", "-m", "Updating Wiki docs for release %s" % version]) # Show the full diff print run_git(["log", "-p", "--color", "-1"]) # Do we accept? print "-------------------------------------------------------------------" print print( "Shown above is the commit log for the changes to the wiki markdown. \n" "Type 'push' to accept and push the changes to GitHub. The wiki repo \n" "local clone can be also inspected at:\n" "%s." % output_dir) push_commit = raw_input() if push_commit == "push": run_git(["push", "origin", "master"])
def main(_): """Do it all""" usage = dedent( """%prog VERSION ..where VERSION is the release version for which docs are being generated.""" ) parser = optparse.OptionParser(usage=usage) parser.description = ( "Generate GitHub Wiki documentation from the core processors present " "in autopkglib. The autopkg.wiki repo is cloned locally, changes are " "committed, a diff shown and the user is interactively given the " "option to push to the remote." ) parser.add_option( "-d", "--directory", metavar="CLONEDIRECTORY", help=( "Directory path in which to clone the repo. If not " "specified, a temporary directory will be used." ), ) parser.add_option( "-p", "--processor", help=( "Generate changes for only a specific processor. " "This does not update the Sidebar." ), ) options, arguments = parser.parse_args() if len(arguments) < 1: parser.print_usage() exit() # Grab the version for the commit log. version = arguments[0] print("Cloning AutoPkg wiki..") print() if options.directory: output_dir = clone_wiki_dir(clone_dir=options.directory) else: output_dir = clone_wiki_dir() print(f"Cloned to {output_dir}.") print() print() # Generate markdown pages for each processor attributes for processor_name in processor_names(): if options.processor: if options.processor != processor_name: continue processor_class = get_processor(processor_name) try: description = processor_class.description except AttributeError: try: description = processor_class.__doc__ except AttributeError: description = "" try: input_vars = processor_class.input_variables except AttributeError: input_vars = {} try: output_vars = processor_class.output_variables except AttributeError: output_vars = {} filename = f"Processor-{processor_name}.md" pathname = os.path.join(output_dir, filename) output = f"# {escape(processor_name)}\n" output += "\n" output += f"## Description\n{escape(description)}\n" output += "\n" output += "## Input Variables\n" output += generate_markdown(input_vars) output += "\n" output += "## Output Variables\n" output += generate_markdown(output_vars) output += "\n" writefile(output, pathname) # Merge in the new stuff! # - Scrape through the current _Sidebar.md, look for where the existing # processors block starts and ends # - Copy the lines up to where the Processors section starts # - Copy the new Processors TOC # - Copy the lines following the Processors section if not options.processor: sidebar_path = os.path.join(output_dir, "_Sidebar.md") new_sidebar = generate_sidebar(sidebar_path) with open(sidebar_path, "w") as fdesc: fdesc.write(new_sidebar) # Git commit everything os.chdir(output_dir) if not run_git(["status", "--porcelain"]): print("No changes detected.") return run_git(["add", "--all"]) run_git(["commit", "-m", f"Updating Wiki docs for release {version}"]) # Show the full diff print(run_git(["log", "-p", "--color", "-1"])) # Do we accept? print("-------------------------------------------------------------------") print() print( "Shown above is the commit log for the changes to the wiki markdown. \n" "Type 'push' to accept and push the changes to GitHub. The wiki repo \n" "local clone can be also inspected at:\n" f"{output_dir}." ) push_commit = input() if push_commit == "push": run_git(["push", "origin", "master"])
Returns: AbstractProcessor subclass with name Name. """ def __init__(self, **kwargs): """Init processor. Input variables are accepted as kwargs.""" self._input_variables = [] for attr in attributes: setattr(self, attr, None) self._input_variables.append(attr) for key, val in kwargs.items(): setattr(self, key, val) base_class.__init__(self, name) newclass = type(name, (AbstractProcessor, ), {"__init__": __init__}) return newclass # Processors without input_variables are meant to be used as base # classes. processor_classes = [ ProcessorFactory(proc_type, autopkglib.get_processor(proc_type).input_variables) for proc_type in autopkglib.processor_names() if hasattr(autopkglib.get_processor(proc_type), "input_variables") ] # Add classes to this module for each AutoPkg processor. for processor in processor_classes: globals()[processor.__name__] = processor
def main(argv): p = optparse.OptionParser() p.description = ( "Generate GitHub Wiki documentation from the core processors present " "in autopkglib. The autopkg.wiki repo is cloned locally, changes are " "committed and the user is interactively given the option to push it " "to the remote.") p.add_option("-d", "--directory", metavar="CLONEDIRECTORY", help=("Directory path in which to clone the repo. If not " "specified, a temporary directory will be used.")) options, arguments = p.parse_args() print "Cloning AutoPkg wiki.." print if options.directory: output_dir = clone_wiki_dir(clone_dir=options.directory) else: output_dir = clone_wiki_dir() print "Cloned to %s." % output_dir print print # Generate markdown pages for each processor attributes for processor_name in processor_names(): processor_class = get_processor(processor_name) try: description = processor_class.description except AttributeError: try: description = processor_class.__doc__ except AttributeError: description = "" try: input_vars = processor_class.input_variables except AttributeError: input_vars = {} try: output_vars = processor_class.output_variables except AttributeError: output_vars = {} filename = "Processor-%s.md" % processor_name pathname = os.path.join(output_dir, filename) output = "# %s\n" % escape(processor_name) output += "\n" output += "## Description\n%s\n" % escape(description) output += "\n" output += "## Input Variables\n" output += generate_markdown(input_vars) output += "\n" output += "## Output Variables\n" output += generate_markdown(output_vars) output += "\n" writefile(output, pathname) # Generate the Processors section of the Sidebar processor_heading = " * **Processors**" toc_string = "" toc_string += processor_heading + "\n" for processor_name in processor_names(): page_name = "Processor-%s" % processor_name page_name.replace(" ", "-") toc_string += " * [[%s|%s]]\n" % (processor_name, page_name) # Merge in the new stuff! # - Scrape through the current _Sidebar.md, look for where the existing # processors block starts and ends # - Copy the lines up to where the Processors section starts # - Copy the new Processors TOC # - Copy the lines following the Processors section sidebar_path = os.path.join(output_dir, "_Sidebar.md") with open(sidebar_path, "r") as fd: current_sidebar_lines = fd.read().splitlines() # Determine our indent amount section_indent = indent_length(processor_heading) past_processors_section = False for index, line in enumerate(current_sidebar_lines): if line == processor_heading: past_processors_section = True processors_start = index if (indent_length(line) <= section_indent) and \ past_processors_section: processors_end = index # Build the new sidebar new_sidebar = "" new_sidebar += "\n".join(current_sidebar_lines[0:processors_start]) + "\n" new_sidebar += toc_string new_sidebar += "\n".join(current_sidebar_lines[processors_end:]) + "\n" with open(sidebar_path, "w") as fd: fd.write(new_sidebar) # Grab the version for the commit log. version = get_autopkg_version() # Git commit everything os.chdir(output_dir) run_git([ "add", "--all"]) run_git([ "commit", "-m", "Updating Wiki docs for release %s" % version]) # Show the full diff print run_git([ "log", "-p", "--color", "-1"]) # Do we accept? print "-------------------------------------------------------------------" print print ("Shown above is the commit log for the changes to the wiki markdown. \n" "Type 'push' to accept and push the changes to GitHub. The wiki repo \n" "local clone can be also inspected at:\n" "%s." % output_dir) push_commit = raw_input() if push_commit == "push": run_git([ "push", "origin", "master"])
def main(_): """Do it all""" usage = dedent( """%prog VERSION ..where VERSION is the release version for which docs are being generated.""" ) parser = optparse.OptionParser(usage=usage) parser.description = ( "Generate GitHub Wiki documentation from the core processors present " "in autopkglib. The autopkg.wiki repo is cloned locally, changes are " "committed, a diff shown and the user is interactively given the " "option to push to the remote." ) parser.add_option( "-d", "--directory", metavar="CLONEDIRECTORY", help=( "Directory path in which to clone the repo. If not " "specified, a temporary directory will be used." ), ) parser.add_option( "-p", "--processor", help=( "Generate changes for only a specific processor. " "This does not update the Sidebar." ), ) options, arguments = parser.parse_args() if len(arguments) < 1: parser.print_usage() exit() # Grab the version for the commit log. version = arguments[0] print("Cloning AutoPkg wiki..") print() if options.directory: output_dir = clone_wiki_dir(clone_dir=options.directory) else: output_dir = clone_wiki_dir() print("Cloned to %s." % output_dir) print() print() # Generate markdown pages for each processor attributes for processor_name in processor_names(): if options.processor: if options.processor != processor_name: continue processor_class = get_processor(processor_name) try: description = processor_class.description except AttributeError: try: description = processor_class.__doc__ except AttributeError: description = "" try: input_vars = processor_class.input_variables except AttributeError: input_vars = {} try: output_vars = processor_class.output_variables except AttributeError: output_vars = {} filename = "Processor-%s.md" % processor_name pathname = os.path.join(output_dir, filename) output = "# %s\n" % escape(processor_name) output += "\n" output += "## Description\n%s\n" % escape(description) output += "\n" output += "## Input Variables\n" output += generate_markdown(input_vars) output += "\n" output += "## Output Variables\n" output += generate_markdown(output_vars) output += "\n" writefile(output, pathname) # Merge in the new stuff! # - Scrape through the current _Sidebar.md, look for where the existing # processors block starts and ends # - Copy the lines up to where the Processors section starts # - Copy the new Processors TOC # - Copy the lines following the Processors section if not options.processor: sidebar_path = os.path.join(output_dir, "_Sidebar.md") new_sidebar = generate_sidebar(sidebar_path) with open(sidebar_path, "w") as fdesc: fdesc.write(new_sidebar) # Git commit everything os.chdir(output_dir) if not run_git(["status", "--porcelain"]): print("No changes detected.") return run_git(["add", "--all"]) run_git(["commit", "-m", "Updating Wiki docs for release %s" % version]) # Show the full diff print(run_git(["log", "-p", "--color", "-1"])) # Do we accept? print("-------------------------------------------------------------------") print() print( "Shown above is the commit log for the changes to the wiki markdown. \n" "Type 'push' to accept and push the changes to GitHub. The wiki repo \n" "local clone can be also inspected at:\n" "%s." % output_dir ) push_commit = raw_input() if push_commit == "push": run_git(["push", "origin", "master"])
Returns: AbstractProcessor subclass with name Name. """ def __init__(self, **kwargs): """Init processor. Input variables are accepted as kwargs.""" self._input_variables = [] for attr in attributes: setattr(self, attr, None) self._input_variables.append(attr) for key, val in kwargs.items(): setattr(self, key, val) base_class.__init__(self, name) newclass = type(name, (AbstractProcessor, ), {"__init__": __init__}) return newclass # Processors without input_variables are meant to be used as base # classes. processor_classes = [ ProcessorFactory(proc_type, autopkglib.get_processor(proc_type).input_variables) for proc_type in autopkglib.processor_names() if hasattr(autopkglib.get_processor(proc_type), "input_variables")] # Add classes to this module for each AutoPkg processor. for processor in processor_classes: globals()[processor.__name__] = processor