def run_reports(args): expanded_cache, errors = build_expanded_cache() # TODO: Add sorting to output or reporting. report_results = [] report_results.append(PathIssuesReport(expanded_cache)) report_results.append(MissingInstallerReport(expanded_cache)) report_results.append(OrphanedInstallerReport(expanded_cache)) report_results.append(PkgsinfoWithErrorsReport(errors)) report_results.append(OutOfDateReport(expanded_cache)) report_results.append(NoUsageReport(expanded_cache)) # Add the results of the last two reports together to determine # wasted disk space. # expanded_cache["unused_items"] = [item for report in report_results[-2:] # for item in report.items] # report_results.append(UnusedDiskUsageReport(expanded_cache)) report_results.append(UnattendedTestingReport(expanded_cache)) report_results.append(UnattendedProdReport(expanded_cache)) report_results.append(ForceInstallTestingReport(expanded_cache)) report_results.append(ForceInstallProdReport(expanded_cache)) if args.plist: dict_reports = {report.name: report.as_dict() for report in report_results} print FoundationPlist.writePlistToString(dict_reports) else: for report in report_results: report.print_report()
def run_reports(args): expanded_cache, errors = build_expanded_cache() # TODO: Add sorting to output or reporting. report_results = [] report_results.append(PathIssuesReport(expanded_cache)) report_results.append(MissingInstallerReport(expanded_cache)) report_results.append(OrphanedInstallerReport(expanded_cache)) report_results.append(PkgsinfoWithErrorsReport(errors)) report_results.append(OutOfDateReport(expanded_cache)) report_results.append(NoUsageReport(expanded_cache)) # Add the results of the last two reports together to determine # wasted disk space. # expanded_cache["unused_items"] = [item for report in report_results[-2:] # for item in report.items] # report_results.append(UnusedDiskUsageReport(expanded_cache)) report_results.append(UnattendedTestingReport(expanded_cache)) report_results.append(UnattendedProdReport(expanded_cache)) report_results.append(ForceInstallTestingReport(expanded_cache)) report_results.append(ForceInstallProdReport(expanded_cache)) if args.plist: dict_reports = { report.name: report.as_dict() for report in report_results } print FoundationPlist.writePlistToString(dict_reports) else: for report in report_results: report.print_report()
def send_request(self, request): self.socket.send(FoundationPlist.writePlistToString(request)) with os.fdopen(self.socket.fileno()) as f: reply = f.read() if reply.startswith("OK:"): return reply.replace("OK:", "").rstrip() errors = reply.rstrip().split("\n") if not errors: errors = ["ERROR:No reply from server (crash?), check system logs"] raise ProcessorError(", ".join([s.replace("ERROR:", "") for s in errors]))
def send_request(self, request): """Send an install request to autopkginstalld""" self.socket.send(FoundationPlist.writePlistToString(request)) with os.fdopen(self.socket.fileno()) as fileref: while True: data = fileref.readline() if data: if data.startswith("OK:"): return data.replace("OK:", "").rstrip() elif data.startswith("ERROR:"): break else: self.output(data.rstrip()) else: break errors = data.rstrip().split("\n") if not errors: errors = ["ERROR:No reply from autopkginstalld (crash?), " "check system logs"] raise ProcessorError(", ".join([s.replace("ERROR:", "") for s in errors]))
def send_request(self, request): '''Send an install request to autopkginstalld''' self.socket.send(FoundationPlist.writePlistToString(request)) with os.fdopen(self.socket.fileno()) as fileref: while True: data = fileref.readline() if data: if data.startswith("OK:"): return data.replace("OK:", "").rstrip() elif data.startswith("ERROR:"): break else: self.output(data.rstrip()) else: break errors = data.rstrip().split("\n") if not errors: errors = ["ERROR:No reply from autopkginstalld (crash?), " "check system logs"] raise ProcessorError( ", ".join([s.replace("ERROR:", "") for s in errors]))
def munkiserver_edit_package(self): if not 'pkginfo' in self.env or len(self.env['pkginfo']) == 0: return # request the edit form url = self.env['edit_url'] resp = self.curl(url) if resp.find('Munki Server: edit') <= 0: raise ProcessorError('Do not have permission to edit packages in MunkiServer') # extract the CSRF token xml = ElementTree.fromstring(resp) ct = xml.find(".//{http://www.w3.org/1999/xhtml}meta[@name='csrf-token']") options = ['-H', 'X-CSRF-Token: ' + ct.attrib['content']] # compose the list data = {} for key in self.env["pkginfo"]: if key == 'receipts' or key == 'installs' or key == 'raw_tags': key += '_plist' if hasattr(self.env['pkginfo'][key], "__len__") and not hasattr(self.env['pkginfo'][key], "endswith"): # it's a non-scalar type but not a string, so it's a plist value = FoundationPlist.writePlistToString(self.env['pkginfo'][key]) else: value = self.env['pkginfo'][key] data["package[%s]" % key] = value # change the parameter options += ['-X', 'PUT'] url = url[:-5] resp = self.curl(url, options, data) # check for error xml = ElementTree.fromstring(resp) for msg in xml.findall(".//{http://www.w3.org/1999/xhtml}div[@class='message error']"): raise ProcessorError(msg.text) # get the redirect URL if 'version' in self.env["pkginfo"] or 'name' in self.env["pkginfo"]: self.env['edit_url'] = re.match('.*You are being.*(http.*)".*redirected.*',resp).group(1)
#!/usr/bin/python import FoundationPlist my_dict = {'name': 'Scripting OS X', 'url': 'http://scriptingosx.com', 'twitter': 'scriptingosx'} plist = FoundationPlist.writePlistToString(my_dict) print plist