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(self): """ Create a BES software distribution task. """ # Assign Application Variables url = self.get_direct_url( self.env.get("bes_overrideurl", self.env.get("url"))) user = getpass.getuser() gmtime_now = strftime("%a, %d %b %Y %X +0000", gmtime()) bes_sha1 = self.get_sha1() bes_size = self.get_size() bes_sha256 = self.get_sha256() bes_displayname = self.env.get("NAME") bes_version = self.env.get("bes_version") bes_title = self.env.get("bes_title", "Deploy %s %s" % (bes_displayname, bes_version)) bes_category = self.env.get("bes_category", 'Software Deployment') bes_relevance = self.env.get("bes_relevance") bes_filename = self.env.get("bes_filename", url.split('/')[-1]) bes_filename = bes_filename.strip().replace(' ', '_') bes_prefetch = self.env.get("bes_prefetch", self.get_prefetch( self.env.get("bes_softwareinstaller", self.env.get("pathname")), bes_filename, url)) bes_description = self.env.get("bes_description", 'This task will deploy %s %s.<BR><BR>' 'This task is applicable on Mac OS X' % (bes_displayname, bes_version)) bes_actions = self.env.get("bes_actions", {1:{'ActionName': 'DefaultAction', 'ActionNumber': 'Action1', 'ActionScript': """"""}}) bes_preactionscript = self.env.get("bes_preactionscript", "") bes_postactionscript = self.env.get("bes_postactionscript", "") # Legacy ClientUI bes_selfservice = self.env.get("bes_selfservice", "False") bes_ssa = self.env.get("bes_ssa", "False") bes_icon = self.env.get("bes_icon", False) bes_additionalmimefields = self.env.get("bes_additionalmimefields", False) # Prepend prefetch line to action script for all actions # Prepend and append pre and post actionscript additions for action in bes_actions: bes_actions[action]['ActionScript'] = ("%s\n%s%s\n%s" % ( bes_preactionscript, bes_prefetch, bes_actions[action]['ActionScript'], bes_postactionscript )).strip() # Additional Metadata for Task details = OrderedDict(( ('Category', bes_category), ('DownloadSize', str(os.path.getsize(self.env.get( "bes_softwareinstaller", self.env.get("pathname"))))), ('Source', "%s v%s (%s)" % (os.path.basename(__file__), __version__, str(get_autopkg_version()))), ('SourceID', user), ('SourceReleaseDate', str(datetime.datetime.now())[:10]), ('SourceSeverity', ""), ('CVENames', ""), ('SANSID', ""), )) # Start Building BES XML self.output("Building 'Deploy %s %s.bes'" % (bes_displayname, bes_version)) root_schema = { "{http://www.w3.org/2001/XMLSchema-instance}" + "noNamespaceSchemaLocation": 'BES.xsd' } root = self.new_node('BES', None, root_schema) self.doc._setroot(root) # Create Top Level 'Task' Tag node = self.new_node('Task', None) root.append(node) # Append Title and Description node.append(self.new_node('Title', bes_title)) node.append(self.new_node('Description', bes_description)) # Append Relevance for line in bes_relevance: if os.path.isfile(QNA): self.validate_relevance(line) node.append(self.new_node('Relevance', line)) # Append Details Dictionary for key, value in details.items(): node.append(self.new_node(key, value)) # Add Self-Service UI Data, If Specified if bes_ssa in ['True', 'true']: if bes_icon: bes_b64icon = self.get_icon(bes_icon) node.append(self.new_mime('action-ui-metadata', ("{\"version\": \"%s\"," "\"size\": \"%s\"," "\"icon\": \"%s\"}") % (bes_version, bes_size, bes_b64icon))) else: node.append(self.new_mime('action-ui-metadata', '{"version": "%s", "size": "%s"}' % (bes_version, bes_size))) # Add Self-Service Data, If Specified if bes_selfservice in ['True', 'true']: self.output("Appending Self-Services MIME Fields...") node.append(self.new_mime('x-fixlet-swdCommandOverride', "%s" % bes_filename)) node.append(self.new_mime('x-fixlet-swd-wizard-data', ("{\"comment\":null," "\"pkgvariablekey\":\"SWD_Package_%s_0\"," "\"pkgTag\":\"\"," "\"vendor\":\"\"," "\"description\":\"\"," "\"lastmodified\":\"%s\"," "\"files\":[{\"ReferenceName\":\"/%s/download.bfswd\"," "\"id\":\"%s_0\"," "\"folderoffset\":\"\"," "\"osd_metadata\":null," "\"msi_metadata\":null," "\"sha1\":\"%s\"," "\"HasAnonymousReference\":true," "\"size\":%s," "\"filename\":\"%s\"," "\"exe_metadata\":{\"CompanyName\":\"\"," "\"FileVersion\":\"\"," "\"ProductVersion\":\"\"," "\"ProductName\":\"\"," "\"exe_metadata_version\":\"\"}," "\"spb_metadata\":null," "\"ReferenceID\":0," "\"sha256\":\"%s\"," "\"appv_metadata\":null," "\"dateadded\":\"%s\"," "\"compressed_data_for_package\":false}]," "\"product\":\"%s\"," "\"creator\":\"%s\"," "\"owner\":\"%s\"," "\"version\":\"%s\"}") % (user, gmtime_now, bes_sha1, bes_sha1, bes_sha1, bes_size, bes_filename, bes_sha256, gmtime_now, bes_displayname, user, user, bes_version))) node.append(self.new_mime('x-fixlet-swdPackageID', "SWD_Package_%s_0" % (user))) node.append(self.new_mime('x-fixlet-advancedLogOptions', ("{\"individualLog\":false," "\"uploadTheLog\":false," "\"individualLogCustomerName\":null}"))) node.append(self.new_mime('x-fixlet-advancedPathOptions', ("{\"customPath\":false," "\"customPathName\":null," "\"deleteCustomPath\":false}"))) node.append(self.new_mime('x-fixlet-source', os.path.basename(__file__))) node.append(self.new_mime('x-fixlet-prePostInstall', ("{\"preType\":null," "\"preInstall\":null," "\"selected\":false," "\"postType\":null," "\"postInstall\":null}"))) node.append(self.new_mime('x-fixlet-runAsSystem', "true")) node.append(self.new_mime('x-fixlet-pkgTag', "")) node.append(self.new_mime('x-fixlet-pkgType', "")) node.append(self.new_mime('x-fixlet-swdSelectedFiles', "[\"%s\"]" % bes_sha1.upper())) node.append(self.new_mime('x-fixlet-runFileSha1', bes_sha1.upper())) node.append(self.new_mime('x-fixlet-canPreserveCustom', "true")) node.append(self.new_mime('x-fixlet-adf-wizard-source', "Software Distribution_SoftwareDistribution")) node.append(self.new_mime('x-fixlet-adf-wizard-data', "")) else: # And If Not, Just Append MIME Source Data node.append(self.new_mime('x-fixlet-source', os.path.basename(__file__))) # Add Additional MIME Fields if bes_additionalmimefields: for name, value in bes_additionalmimefields.iteritems(): node.append(self.new_mime(name, value)) # Add Modification Time node.append( self.new_mime('x-fixlet-modification-time', strftime("%a, %d %b %Y %X +0000", gmtime()))) node.append(self.new_node('Domain', 'BESC')) # Append Default Action for action in sorted(bes_actions.iterkeys()): if bes_actions[action].get('ActionName', None) == 'DefaultAction': node.append(self.new_action(bes_actions[action])) bes_actions.pop(action, None) # Append Actions for action in sorted(bes_actions.iterkeys()): node.append(self.new_action(bes_actions[action])) # Write Final BES File to Disk bes_file = "%s/Deploy %s %s.bes" % (self.env.get("RECIPE_CACHE_DIR"), bes_displayname, bes_version) self.doc.write(bes_file, encoding="UTF-8", xml_declaration=True) self.env['bes_file'] = bes_file self.output("Output BES File: '%s'" % self.env.get("bes_file"))
def main(self): """ Create a BES software distribution task. """ self.output("bes_softwareinstaller is " + str(self.env.get("bes_softwareinstaller"))) self.output("pathname is " + str(self.env.get("pathname"))) skipPrefetch = False # Check for URL, set to skip if (self.env.get("bes_overrideurl") == None) and (self.env.get("url") == None): skipPrefetch = True self.output("Skip Prefetch - TRUE") else: # Assign Application Variables url = self.get_direct_url( self.env.get("bes_overrideurl", self.env.get("url"))) self.output(url) self.output("^This is the 'url' var") self.output("Skip prefetch is " + str(skipPrefetch)) self.output("GET name of script for source") # Get name of script for Source fileBaseName = str(os.path.basename(__file__)) self.output("ln 332") user = getpass.getuser() self.output("ln 334") # If we don't have a file, don't get a size if skipPrefetch == True: self.output("running skipPrefetch True stuff") bes_size = self.env.get("filesize", 0) else: self.output("getting size") bes_size = self.get_size() self.output("ln 342") gmtime_now = strftime("%a, %d %b %Y %X +0000", gmtime()) bes_displayname = self.env.get("NAME") self.output("ln 346") bes_version = self.env.get("bes_version") self.output("ln348") bes_title = self.env.get("bes_title", "Deploy %s %s" % (bes_displayname, bes_version)) self.output("ln 352") bes_category = self.env.get("bes_category", 'Software Deployment') self.output("ln354") bes_relevance = self.env.get("bes_relevance") self.output("ln 356") if skipPrefetch != True: bes_filename = self.env.get("bes_filename", url.split('/')[-1]) bes_filename = bes_filename.strip().replace(' ', '_') bes_prefetch = self.env.get("bes_prefetch", self.get_prefetch(None, bes_filename, url)) bes_description = self.env.get("bes_description", 'This task will deploy %s %s.<BR><BR>' 'This task is applicable on Mac OS X' % (bes_displayname, bes_version)) bes_actions = self.env.get("bes_actions", {1:{'ActionName': 'DefaultAction', 'ActionNumber': 'Action1', 'ActionScript': """"""}}) bes_preactionscript = self.env.get("bes_preactionscript", "") bes_postactionscript = self.env.get("bes_postactionscript", "") bes_ssa = self.env.get("bes_ssa", "False") bes_ssaaction = self.env.get("bes_ssaaction", None) bes_icon = self.env.get("bes_icon", False) bes_additionalmimefields = self.env.get("bes_additionalmimefields", False) self.output("ln 372") # Prepend prefetch line to action script for all actions # Prepend and append pre and post actionscript additions self.output("finished var sets") if skipPrefetch == True: for action in bes_actions: bes_actions[action]['ActionScript'] = ("%s\n%s\n%s" % ( bes_preactionscript, bes_actions[action]['ActionScript'], bes_postactionscript )).strip() else: for action in bes_actions: bes_actions[action]['ActionScript'] = ("%s\n%s%s\n%s" % ( bes_preactionscript, bes_prefetch, bes_actions[action]['ActionScript'], bes_postactionscript )).strip() # Additional Metadata for Task details = OrderedDict(( ('Category', bes_category), ('DownloadSize', str(bes_size)), ('Source', "%s v%s (%s)" % (fileBaseName, __version__, str(get_autopkg_version()))), ('SourceID', user), ('SourceReleaseDate', str(datetime.datetime.now())[:10]), ('SourceSeverity', ""), ('CVENames', ""), ('SANSID', ""), )) self.output("ln 404") # Start Building BES XML self.output("Building 'Deploy %s %s.bes'" % (bes_displayname, bes_version)) root_schema = { "{http://www.w3.org/2001/XMLSchema-instance}" + "noNamespaceSchemaLocation": 'BES.xsd' } root = self.new_node('BES', None, root_schema) self.doc._setroot(root) # Create Top Level 'Task' Tag node = self.new_node('Task', None) root.append(node) # Append Title and Description node.append(self.new_node('Title', bes_title)) node.append(self.new_node('Description', bes_description)) # Append Relevance for line in bes_relevance: if os.path.isfile(QNA): self.validate_relevance(line) node.append(self.new_node('Relevance', line)) # Append Details Dictionary for key, value in details.items(): node.append(self.new_node(key, value)) self.output("ln 435") # Add Self-Service UI Data, If Specified if bes_ssa in ['True', 'true']: if bes_icon: bes_b64icon = self.get_icon(bes_icon) node.append(self.new_mime('action-ui-metadata', ("{\"version\": \"%s\"," "\"size\": \"%s\"," "\"icon\": \"%s\"}") % (bes_version, bes_size, bes_b64icon))) else: node.append(self.new_mime('action-ui-metadata', '{"version": "%s", "size": "%s"}' % (bes_version, bes_size))) self.output("ln450") # Append MIME Source Data node.append(self.new_mime('x-fixlet-source', fileBaseName)) # Add Additional MIME Fields if bes_additionalmimefields: for name, value in bes_additionalmimefields.iteritems(): node.append(self.new_mime(name, value)) # Add Modification Time node.append( self.new_mime('x-fixlet-modification-time', gmtime_now)) node.append(self.new_node('Domain', 'BESC')) # Append Default Action bes_ssaaction_copy = None for action in sorted(bes_actions.iterkeys()): if bes_actions[action].get('ActionName', None) == bes_ssaaction: bes_ssaaction_copy = bes_actions[action] if bes_actions[action].get('ActionName', None) == 'DefaultAction': node.append(self.new_action(bes_actions[action])) bes_actions.pop(action, None) # Append Actions for action in sorted(bes_actions.iterkeys()): node.append(self.new_action(bes_actions[action])) self.output("ln 480") # Append SSA Action if bes_ssaaction and bes_ssaaction_copy: bes_ssaaction_copy['Description'] = ['', 'Make available', ' in Self Service'] bes_ssaaction_copy['ActionNumber'] = 'Action10' bes_ssaaction_copy['ActionName'] = 'Action' node.append(self.new_action(bes_ssaaction_copy, ssa=True)) # Write Final BES File to Disk bes_file = "%s/Deploy %s %s.bes" % (self.env.get("RECIPE_CACHE_DIR"), bes_displayname, bes_version) self.doc.write(bes_file, encoding="UTF-8", xml_declaration=True) self.env['bes_file'] = bes_file self.output("Output BES File: '%s'" % self.env.get("bes_file"))
def main(self): """ Create a BES software distribution task. """ skipPrefetch = False # Check for URL, set to skip if (self.env.get("bes_overrideurl") == None) and (self.env.get("url") == None): skipPrefetch = True else: # Assign Application Variables url = self.get_direct_url( self.env.get("bes_overrideurl", self.env.get("url"))) # Get name of script for Source fileBaseName = str(os.path.basename(__file__)) user = getpass.getuser() # If we don't have a file, don't get a size if skipPrefetch == True: bes_size = self.env.get("filesize", 0) else: bes_size = self.get_size() gmtime_now = strftime("%a, %d %b %Y %X +0000", gmtime()) bes_displayname = self.env.get("NAME") bes_version = self.env.get("bes_version") bes_title = self.env.get("bes_title", "Deploy %s %s" % (bes_displayname, bes_version)) bes_category = self.env.get("bes_category", 'Software Deployment') bes_relevance = self.env.get("bes_relevance") if skipPrefetch != True: bes_filename = self.env.get("bes_filename", url.split('/')[-1]) bes_filename = bes_filename.strip().replace(' ', '_') bes_prefetch = self.env.get("bes_prefetch", self.get_prefetch(None, bes_filename, url)) bes_description = self.env.get("bes_description", 'This task will deploy %s %s.<BR><BR>' 'This task is applicable on Mac OS X' % (bes_displayname, bes_version)) bes_actions = self.env.get("bes_actions", {1:{'ActionName': 'DefaultAction', 'ActionNumber': 'Action1', 'ActionScript': """"""}}) bes_preactionscript = self.env.get("bes_preactionscript", "") bes_postactionscript = self.env.get("bes_postactionscript", "") bes_ssa = self.env.get("bes_ssa", "False") bes_ssaaction = self.env.get("bes_ssaaction", None) bes_icon = self.env.get("bes_icon", False) bes_additionalmimefields = self.env.get("bes_additionalmimefields", False) # Prepend prefetch line to action script for all actions # Prepend and append pre and post actionscript additions if skipPrefetch == True: for action in bes_actions: bes_actions[action]['ActionScript'] = ("%s\n%s\n%s" % ( bes_preactionscript, bes_actions[action]['ActionScript'], bes_postactionscript )).strip() else: for action in bes_actions: bes_actions[action]['ActionScript'] = ("%s\n%s%s\n%s" % ( bes_preactionscript, bes_prefetch, bes_actions[action]['ActionScript'], bes_postactionscript )).strip() # Additional Metadata for Task details = OrderedDict(( ('Category', bes_category), ('DownloadSize', str(bes_size)), ('Source', "%s v%s (%s)" % (fileBaseName, __version__, str(get_autopkg_version()))), ('SourceID', user), ('SourceReleaseDate', str(datetime.datetime.now())[:10]), ('SourceSeverity', ""), ('CVENames', ""), ('SANSID', ""), )) # Start Building BES XML self.output("Building 'Deploy %s %s.bes'" % (bes_displayname, bes_version)) root_schema = { "{http://www.w3.org/2001/XMLSchema-instance}" + "noNamespaceSchemaLocation": 'BES.xsd' } root = self.new_node('BES', None, root_schema) self.doc._setroot(root) # Create Top Level 'Task' Tag node = self.new_node('Task', None) root.append(node) # Append Title and Description node.append(self.new_node('Title', bes_title)) node.append(self.new_node('Description', bes_description)) # Append Relevance for line in bes_relevance: if os.path.isfile(QNA): self.validate_relevance(line) node.append(self.new_node('Relevance', line)) # Append Details Dictionary for key, value in details.items(): node.append(self.new_node(key, value)) # Add Self-Service UI Data, If Specified if bes_ssa in ['True', 'true']: if bes_icon: bes_b64icon = self.get_icon(bes_icon) node.append(self.new_mime('action-ui-metadata', ("{\"version\": \"%s\"," "\"size\": \"%s\"," "\"icon\": \"%s\"}") % (bes_version, bes_size, bes_b64icon))) else: node.append(self.new_mime('action-ui-metadata', '{"version": "%s", "size": "%s"}' % (bes_version, bes_size))) # Append MIME Source Data node.append(self.new_mime('x-fixlet-source', fileBaseName)) # Add Additional MIME Fields if bes_additionalmimefields: for name, value in bes_additionalmimefields.iteritems(): node.append(self.new_mime(name, value)) # Add Modification Time node.append( self.new_mime('x-fixlet-modification-time', gmtime_now)) node.append(self.new_node('Domain', 'BESC')) # Append Default Action bes_ssaaction_copy = None for action in sorted(bes_actions.iterkeys()): if bes_actions[action].get('ActionName', None) == bes_ssaaction: bes_ssaaction_copy = bes_actions[action] if bes_actions[action].get('ActionName', None) == 'DefaultAction': node.append(self.new_action(bes_actions[action])) bes_actions.pop(action, None) # Append Actions for action in sorted(bes_actions.iterkeys()): node.append(self.new_action(bes_actions[action])) # Append SSA Action if bes_ssaaction and bes_ssaaction_copy: bes_ssaaction_copy['Description'] = ['', 'Make available', ' in Self Service'] bes_ssaaction_copy['ActionNumber'] = 'Action10' bes_ssaaction_copy['ActionName'] = 'Action' node.append(self.new_action(bes_ssaaction_copy, ssa=True)) # Write Final BES File to Disk bes_file = "%s/Deploy %s %s.bes" % (self.env.get("RECIPE_CACHE_DIR"), bes_displayname, bes_version) self.doc.write(bes_file, encoding="UTF-8", xml_declaration=True) self.env['bes_file'] = bes_file self.output("Output BES File: '%s'" % self.env.get("bes_file"))