def get_packagenamelist(): catalogs = Catalog() package_details = [] for cat in catalogs.list(): package_details = package_details + catalogs.detail(cat) package_list = list( set( [ pkg['name'] for pkg in package_details] ) ) return package_list
def DEFUNCT_get_install_item_names(cls, manifest_name): '''Returns a dictionary containing types of install items valid for the current manifest''' suggested_set = set() update_set = set() versioned_set = set() manifest = read_manifest(manifest_name) if manifest: catalog_list = manifest.get('catalogs', ['all']) for catalog in catalog_list: catalog_items = Catalog.detail(catalog) if catalog_items: suggested_names = list(set( [item['name'] for item in catalog_items if not item.get('update_for')])) suggested_set.update(suggested_names) update_names = list(set( [item['name'] for item in catalog_items if item.get('update_for')])) update_set.update(update_names) item_names_with_versions = list(set( [item['name'] + '-' + trim_version_string(item['version']) for item in catalog_items])) versioned_set.update(item_names_with_versions) return {'suggested': list(suggested_set), 'updates': list(update_set), 'with_version': list(versioned_set)}
def mass_delete(cls, pathname_list, user, delete_pkgs=False): '''Deletes pkginfo files from a list and optionally deletes the associated installer items (pkgs)''' errors = [] catalog_items = [] if delete_pkgs: # cache the catalog_items once; we don't want to incur the # overhead of reading the 'all' catalog multiple times catalog_items = Catalog.detail('all') for pathname in pathname_list: delete_this_pkg = False if delete_pkgs: ref_count, pkg_path = pkg_ref_count(pathname, catalog_items) if ref_count == 1: # OK to delete the pkg if there is only one pkginfo # file that refers to it delete_this_pkg = True try: cls.delete('pkgsinfo', pathname, user) except FileDeleteError, err: errors.append('Error %s when removing %s' % (err, pathname)) else: if delete_this_pkg: try: MunkiFile.delete('pkgs', pkg_path, user) except FileDeleteError, err: errors.append('Error %s when removing %s' % (err, pkg_path))
def getInstallItemNames(cls, manifest_name): '''Returns a dictionary containing types of install items valid for the current manifest''' suggested_set = set() update_set = set() versioned_set = set() manifest = cls.read(manifest_name) if manifest: if settings.ALL_ITEMS: catalog_list = ['all'] else: catalog_list = manifest.get('catalogs', ['all']) for catalog in catalog_list: catalog_items = Catalog.detail(catalog) if catalog_items: suggested_names = list(set( [item['name'] for item in catalog_items if not item.get('update_for')])) suggested_set.update(suggested_names) update_names = list(set( [item['name'] for item in catalog_items if item.get('update_for')])) update_set.update(update_names) item_names_with_versions = list(set( [item['name'] + '-' + trimVersionString(item['version']) for item in catalog_items])) versioned_set.update(item_names_with_versions) return {'suggested': list(suggested_set), 'updates': list(update_set), 'with_version': list(versioned_set)}
def detail(request, manifest_name): if request.method == 'POST': if not request.user.has_perm('reports.change_machine'): return HttpResponse(json.dumps('error')) if request.is_ajax(): json_data = json.loads(request.raw_post_data) if json_data: manifest_detail = Manifest.read(manifest_name) for key in json_data.keys(): manifest_detail[key] = json_data[key] Manifest.write(manifest_name, manifest_detail, request.user) return HttpResponse(json.dumps('success')) if request.method == 'GET': manifest = Manifest.read(manifest_name) valid_install_items = Manifest.getValidInstallItems(manifest_name) valid_catalogs = Catalog.list() valid_manifest_names = Manifest.list() manifest_user = manifest.get(MANIFEST_USERNAME_KEY, '') c = RequestContext(request, {'manifest_name': manifest_name.replace(':', '/'), 'manifest_user': manifest_user, 'manifest_user_is_editable': MANIFEST_USERNAME_IS_EDITABLE, 'manifest': manifest, 'valid_install_items': valid_install_items, 'valid_catalogs': valid_catalogs, 'valid_manifest_names': valid_manifest_names, 'user': request.user, 'page': 'manifests'}) c.update(csrf(request)) return render_to_response('manifests/detail.html', c)
def json_catalog_names(request): valid_catalogs = Catalog.list() valid_catalogs.sort() term = request.GET.get('term', '').lower() if term: suggestions = [ item for item in valid_catalogs if term in item.lower() ] else: suggestions = valid_catalogs return HttpResponse(json.dumps(suggestions), mimetype='application/json')
def getSuggestedInstallItems(cls, manifest_name): '''Returns a list of suggested install item names for the given manifest, taking into account the current list of catalogs, and filtering out updates and versions.''' install_items = [] manifest = cls.read(manifest_name) if manifest: catalog_list = manifest.get('catalogs', []) for catalog in catalog_list: catalog_items = Catalog.detail(catalog) install_items = list(set( [item['name'] for item in catalog_items if not item.get('update_for')])) return install_items
def getSuggestedInstallItems(cls, manifest_name): '''Returns a list of suggested install item names for the given manifest, taking into account the current list of catalogs, and filtering out updates and versions.''' install_items = [] manifest = cls.read(manifest_name) if manifest: catalog_list = manifest.get('catalogs', []) for catalog in catalog_list: catalog_items = Catalog.detail(catalog) install_items = list( set([ item['name'] for item in catalog_items if not item.get('update_for') ])) return install_items
def detail(request, manifest_name): if request.method == 'POST': if not request.user.has_perm('manifests.change_manifests'): return HttpResponse(json.dumps('error')) if request.is_ajax(): json_data = json.loads(request.body) if json_data: manifest_detail = Manifest.read(manifest_name) for key in json_data.keys(): manifest_detail[key] = json_data[key] Manifest.write(manifest_name, manifest_detail, request.user) return HttpResponse(json.dumps('success')) if request.method == 'GET': if not request.user.has_perm('manifests.can_view_manifests'): return HttpResponse(json.dumps('error')) manifest = Manifest.read(manifest_name) #valid_install_items = Manifest.getValidInstallItems(manifest_name) install_items = Manifest.getInstallItemNames(manifest_name) valid_install_items = (install_items['suggested'] + install_items['updates'] + install_items['with_version']) suggested_install_items = install_items['suggested'] valid_catalogs = Catalog.list() valid_manifest_names = Manifest.list() autocomplete_data = json.dumps({ 'items': install_items['suggested'], 'catalogs': valid_catalogs, 'manifests': valid_manifest_names }) manifest_user = manifest.get(MANIFEST_USERNAME_KEY, '') c = RequestContext( request, { 'manifest_name': manifest_name.replace(':', '/'), 'manifest_user': manifest_user, 'manifest_user_is_editable': MANIFEST_USERNAME_IS_EDITABLE, 'manifest': manifest, 'valid_install_items': valid_install_items, 'install_items': install_items, 'valid_catalogs': valid_catalogs, 'valid_manifest_names': valid_manifest_names, 'autocomplete_data': autocomplete_data, 'user': request.user, 'page': 'manifests' }) c.update(csrf(request)) return render_to_response('manifests/detail.html', c)
def index(request, catalog_filter=None): can_view_pkgs = request.user.has_perm('pkgs.can_view_pkgs') can_view_manifests = request.user.has_perm('manifests.can_view_manifests') can_view_catalogs = request.user.has_perm('catalogs.can_view_catalogs') change_pkgs = request.user.has_perm('pkgs.change_pkgs') delete_pkgs = request.user.has_perm('pkgs.delete_pkgs') if not catalog_filter: catalog_filter = "all" git_enabled = None if GIT: git_enabled = GIT git_branching_enabled = None if GIT_BRANCHING: git_branching_enabled = GIT_BRANCHING # option to show the actual branch. It takes a toll on loading speed though # git_branch = Manifest.getGitBranch() if request.method == 'GET': findtext = request.GET.get('findtext') else: findtext = "" all_catalog_items = Packages.detail(catalog_filter, findtext) catalog_list = Catalog.list() catalog_name = 'none' if PROD_CATALOG in catalog_list: catalog_name = PROD_CATALOG elif 'testing' in catalog_list: catalog_name = 'testing' c = RequestContext(request, {'user': request.user, 'all_catalog_items': all_catalog_items, 'catalog_filter': catalog_filter, 'catalog_list': catalog_list, 'catalog_name': catalog_name, 'findtext': findtext, 'can_view_pkgs': can_view_pkgs, 'can_view_manifests': can_view_manifests, 'can_view_catalogs': can_view_catalogs, 'change_pkgs': change_pkgs, 'delete_pkgs': delete_pkgs, 'git_enabled': git_enabled, 'git_branching_enabled': git_branching_enabled, 'page': 'pkgs'}) return render_to_response('pkgs/index.html', c)
def detail(request, manifest_name): if request.method == 'POST': if not request.user.has_perm('manifests.change_manifests'): return HttpResponse(json.dumps('error')) if request.is_ajax(): json_data = json.loads(request.body) if json_data: manifest_detail = Manifest.read(manifest_name) for key in json_data.keys(): manifest_detail[key] = json_data[key] Manifest.write(manifest_name, manifest_detail, request.user) return HttpResponse(json.dumps('success')) if request.method == 'GET': if not request.user.has_perm('manifests.can_view_manifests'): return HttpResponse(json.dumps('error')) manifest = Manifest.read(manifest_name) #valid_install_items = Manifest.getValidInstallItems(manifest_name) install_items = Manifest.getInstallItemNames(manifest_name) valid_install_items = (install_items['suggested'] + install_items['updates'] + install_items['with_version']) suggested_install_items = install_items['suggested'] valid_catalogs = Catalog.list() valid_manifest_names = Manifest.list() autocomplete_data = json.dumps({ 'items': install_items['suggested'], 'catalogs': valid_catalogs, 'manifests': valid_manifest_names }) manifest_user = manifest.get(MANIFEST_USERNAME_KEY, '') c = RequestContext(request, {'manifest_name': manifest_name.replace(':', '/'), 'manifest_user': manifest_user, 'manifest_user_is_editable': MANIFEST_USERNAME_IS_EDITABLE, 'manifest': manifest, 'valid_install_items': valid_install_items, 'install_items': install_items, 'valid_catalogs': valid_catalogs, 'valid_manifest_names': valid_manifest_names, 'autocomplete_data': autocomplete_data, 'user': request.user, 'page': 'manifests'}) c.update(csrf(request)) return render_to_response('manifests/detail.html', c)
def index(request): if request.method == 'GET': findtext = request.GET.get('findtext') all_catalog_items = Packages.detail(findtext) else: all_catalog_items = Packages.detail() catalog_list = Catalog.list() catalog_name = 'none' if PROD_CATALOG in catalog_list: catalog_name = PROD_CATALOG elif 'testing' in catalog_list: catalog_name = 'testing' return render_to_response('pkgs/index.html', {'user': request.user, 'all_catalog_items': all_catalog_items, 'catalog_list': catalog_list, 'catalog_name': catalog_name, 'findtext': findtext, 'page': 'pkgs'})
def detail(request, manifest_name): if request.method == "POST": if not request.user.has_perm("reports.change_machine"): return HttpResponse(json.dumps("error")) if request.is_ajax(): json_data = json.loads(request.body) if json_data: manifest_detail = Manifest.read(manifest_name) for key in json_data.keys(): manifest_detail[key] = json_data[key] Manifest.write(manifest_name, manifest_detail, request.user) return HttpResponse(json.dumps("success")) if request.method == "GET": manifest = Manifest.read(manifest_name) # valid_install_items = Manifest.getValidInstallItems(manifest_name) install_items = Manifest.getInstallItemNames(manifest_name) valid_install_items = install_items["suggested"] + install_items["updates"] + install_items["with_version"] suggested_install_items = install_items["suggested"] valid_catalogs = Catalog.list() valid_manifest_names = Manifest.list() autocomplete_data = json.dumps( {"items": install_items["suggested"], "catalogs": valid_catalogs, "manifests": valid_manifest_names} ) manifest_user = manifest.get(MANIFEST_USERNAME_KEY, "") c = RequestContext( request, { "manifest_name": manifest_name.replace(":", "/"), "manifest_user": manifest_user, "manifest_user_is_editable": MANIFEST_USERNAME_IS_EDITABLE, "manifest": manifest, "valid_install_items": valid_install_items, "install_items": install_items, "valid_catalogs": valid_catalogs, "valid_manifest_names": valid_manifest_names, "autocomplete_data": autocomplete_data, "user": request.user, "page": "manifests", }, ) c.update(csrf(request)) return render_to_response("manifests/detail.html", c)
def getValidInstallItems(cls, manifest_name): '''Returns a list of valid install item names for the given manifest, taking into account the current list of catalogs''' manifest = cls.read(manifest_name) if manifest: catalog_list = manifest.get('catalogs', []) install_items = set() for catalog in catalog_list: catalog_items = Catalog.detail(catalog) if catalog_items: catalog_item_names = list(set( [item['name'] for item in catalog_items])) install_items.update(catalog_item_names) catalog_item_names_with_versions = list(set( [item['name'] + '-' + trimVersionString(item['version']) for item in catalog_items])) install_items.update(catalog_item_names_with_versions) return list(install_items) return []
def getInstallItemNames(cls, manifest_name): '''Returns a dictionary containing types of install items valid for the current manifest''' suggested_set = set() update_set = set() versioned_set = set() manifest = cls.read(manifest_name) if manifest: if ALL_ITEMS: catalog_list = ['all'] else: catalog_list = manifest.get('catalogs', ['all']) for catalog in catalog_list: catalog_items = Catalog.detail(catalog) if catalog_items: suggested_names = list( set([ item['name'] for item in catalog_items if not item.get('update_for') ])) suggested_set.update(suggested_names) update_names = list( set([ item['name'] for item in catalog_items if item.get('update_for') ])) update_set.update(update_names) item_names_with_versions = list( set([ item['name'] + '-' + trimVersionString(item['version']) for item in catalog_items ])) versioned_set.update(item_names_with_versions) return { 'suggested': list(suggested_set), 'updates': list(update_set), 'with_version': list(versioned_set) }
def getValidInstallItems(cls, manifest_name): '''Returns a list of valid install item names for the given manifest, taking into account the current list of catalogs''' manifest = cls.read(manifest_name) if manifest: catalog_list = manifest.get('catalogs', []) install_items = set() for catalog in catalog_list: catalog_items = Catalog.detail(catalog) if catalog_items: catalog_item_names = list( set([item['name'] for item in catalog_items])) install_items.update(catalog_item_names) catalog_item_names_with_versions = list( set([ item['name'] + '-' + trimVersionString(item['version']) for item in catalog_items ])) install_items.update(catalog_item_names_with_versions) return list(install_items) return []
def get_pkg_ref_count(request, pkg_path): """Returns the number of pkginfo files referencing a given pkg_path""" LOGGER.debug("Got request for pkg ref count for %s", pkg_path) return HttpResponse(json.dumps(Catalog.get_pkg_ref_count(pkg_path)), content_type="application/json")
def get_pkg_ref_count(request, pkg_path): '''Returns the number of pkginfo files referencing a given pkg_path''' LOGGER.debug("Got request for pkg ref count for %s", pkg_path) return HttpResponse(json.dumps(Catalog.get_pkg_ref_count(pkg_path)), content_type='application/json')
def json_catalog_data(request): '''Returns complied and sorted catalog data in JSON format''' LOGGER.debug("Got request for catalog data") return HttpResponse(json.dumps(Catalog.catalog_info()), content_type='application/json')
def catalog_view(request): '''Returns list of catalog names in JSON format''' catalog_list = Catalog.list() LOGGER.debug("Got request for catalog names") return HttpResponse(json.dumps(catalog_list), content_type='application/json')
def detail_pkg(request, serial, manifest_name): machine = None manifest = None install_items = None if serial: try: machine = Machine.objects.get(serial_number=serial) except Machine.DoesNotExist: raise Http404 else: raise Http404 report_plist = {} if machine: try: report = MunkiReport.objects.get(machine=machine) report_plist = report.get_report() except MunkiReport.DoesNotExist: pass # get autocomplete data install_items = Manifest.getInstallItemNames(manifest_name) valid_install_items = (install_items['suggested'] + install_items['updates'] + install_items['with_version']) suggested_install_items = install_items['suggested'] valid_catalogs = Catalog.list() valid_manifest_names = Manifest.list() autocomplete_data = json.dumps({ 'items': install_items['suggested'], 'catalogs': valid_catalogs, 'manifests': valid_manifest_names }) # loop trought includet manifests as long as it have one includetManifests = dict() def get_addition_manifests(manifest): detailManifest = Manifest.read(manifest) includetManifests.update({manifest: detailManifest}) if "included_manifests" in detailManifest: for includetManifest in detailManifest.included_manifests: get_addition_manifests(includetManifest) manifest = Manifest.read(manifest_name) sorted_Manifests = SortedDict() sorted_Manifests[manifest_name] = manifest if "included_manifests" in manifest: for includetManifest in manifest.included_manifests: get_addition_manifests(includetManifest) sort_list = manifest.included_manifests for key in sort_list: sorted_Manifests[key] = includetManifests[key] key_list = includetManifests.keys() key_list.sort() for key in key_list: if key not in sorted_Manifests: sorted_Manifests[key] = includetManifests[key] # item_details -> list with software and details # true_items for check if a software is in catalog or not item_details = {} true_items = list() if "catalogs" in manifest: for catalog in manifest.catalogs: catalog_detail = Catalog.detail(catalog) if catalog_detail: for detail in reversed(catalog_detail): if not detail.name in item_details: item_details[detail.name] = detail true_items.append(detail.name) if "icon_name" in item_details[detail.name]: icon = Catalog.get_icon( item_details[detail.name].icon_name) else: icon = Catalog.get_icon(detail.name) item_details[detail.name].icon_name = icon ManagedInstallsDetail = SortedDict() if report_plist.has_key("ManagedInstalls"): for item in report_plist.ManagedInstalls: ManagedInstallsDetail[item.name] = item # installs installs = SortedDict() listed = list() installsTypes = [ "managed_installs", "managed_uninstalls", "optional_installs" ] for installsType in installsTypes: installs[installsType] = SortedDict() for number, manifests in enumerate(sorted_Manifests): installs[installsType][manifests] = SortedDict() if manifest: for index, item in enumerate( sorted_Manifests[manifests][installsType]): listed.append(item) if ManagedInstallsDetail.has_key(item): installs[installsType][manifests][ item] = ManagedInstallsDetail[item] if item in true_items: if installs[installsType].get(manifests, {}).has_key(item): installs[installsType][manifests][item].update( item_details[item]) else: installs[installsType][manifests][ item] = item_details[item] installs[installsType][manifests][item].update( {"incatalog": "True"}) else: if installs[installsType].get(manifests, {}).has_key(item): installs[installsType][manifests][item].update( {"incatalog": "False"}) else: installs[installsType][manifests][item] = { 'name': item, "incatalog": "False" } required = SortedDict() for item in sorted(ManagedInstallsDetail.items(), key=lambda x: x[1]['display_name']): if not item[0] in listed: if item_details.has_key(item[0]): ManagedInstallsDetail[item[0]].icon_name = item_details[ item[0]].icon_name else: ManagedInstallsDetail[ item[0]].icon_name = "/static/img/PackageIcon.png" required[item[0]] = ManagedInstallsDetail[item[0]] # handle items that were installed during the most recent run install_results = {} for result in report_plist.get('InstallResults', []): nameAndVers = result['name'] + '-' + result['version'] if result['status'] == 0: install_results[nameAndVers] = "installed" else: install_results[nameAndVers] = 'error' if install_results: for item in report_plist.get('ItemsToInstall', []): name = item.get('display_name', item['name']) nameAndVers = ('%s-%s' % (name, item['version_to_install'])) item['install_result'] = install_results.get( nameAndVers, 'pending') for item in report_plist.get('ManagedInstalls', []): if 'version_to_install' in item: name = item.get('display_name', item['name']) nameAndVers = ('%s-%s' % (name, item['version_to_install'])) if install_results.get(nameAndVers) == 'installed': item['installed'] = True # handle items that were removed during the most recent run # this is crappy. We should fix it in Munki. removal_results = {} # for result in report_plist.get('RemovalResults', []): # m = re.search('^Removal of (.+): (.+)$', result) # if m: # try: # if m.group(2) == 'SUCCESSFUL': # removal_results[m.group(1)] = 'removed' # else: # removal_results[m.group(1)] = m.group(2) # except IndexError: # pass if removal_results: for item in report_plist.get('ItemsToRemove', []): name = item.get('display_name', item['name']) item['install_result'] = removal_results.get(name, 'pending') if item['install_result'] == 'removed': if not 'RemovedItems' in report_plist: report_plist['RemovedItems'] = [item['name']] elif not name in report_plist['RemovedItems']: report_plist['RemovedItems'].append(item['name']) c = RequestContext( request, { 'manifest_name': manifest_name, 'manifest': manifest, 'report': report_plist, 'installs': installs, 'autocomplete_data': autocomplete_data, 'required': required, 'valid_manifest_names': valid_manifest_names, 'valid_catalogs': valid_catalogs, }) c.update(csrf(request)) return render_to_response('reports/detail_pkg.html', c)
def catalog_view(request): """Returns list of catalog names in JSON format""" catalog_list = Catalog.list() LOGGER.debug("Got request for catalog names") return HttpResponse(json.dumps(catalog_list), content_type="application/json")
def detail_pkg(request, serial, manifest_name): machine = None manifest = None install_items = None if serial: try: machine = Machine.objects.get(serial_number=serial) except Machine.DoesNotExist: raise Http404 else: raise Http404 report_plist = {} if machine: try: report = MunkiReport.objects.get(machine=machine) report_plist = report.get_report() except MunkiReport.DoesNotExist: pass # get autocomplete data install_items = Manifest.getInstallItemNames(manifest_name) valid_install_items = install_items["suggested"] + install_items["updates"] + install_items["with_version"] suggested_install_items = install_items["suggested"] valid_catalogs = Catalog.list() valid_manifest_names = Manifest.list() autocomplete_data = json.dumps( {"items": install_items["suggested"], "catalogs": valid_catalogs, "manifests": valid_manifest_names} ) # loop trought includet manifests as long as it have one includetManifests = dict() def get_addition_manifests(manifest): detailManifest = Manifest.read(manifest) includetManifests.update({manifest: detailManifest}) if "included_manifests" in detailManifest: for includetManifest in detailManifest.included_manifests: get_addition_manifests(includetManifest) manifest = Manifest.read(manifest_name) sorted_Manifests = SortedDict() sorted_Manifests[manifest_name] = manifest if "included_manifests" in manifest: for includetManifest in manifest.included_manifests: get_addition_manifests(includetManifest) sort_list = manifest.included_manifests for key in sort_list: sorted_Manifests[key] = includetManifests[key] key_list = includetManifests.keys() key_list.sort() for key in key_list: if key not in sorted_Manifests: sorted_Manifests[key] = includetManifests[key] # item_details -> list with software and details # true_items for check if a software is in catalog or not item_details = {} true_items = list() if "catalogs" in manifest: for catalog in manifest.catalogs: catalog_detail = Catalog.detail(catalog) if catalog_detail: for detail in reversed(catalog_detail): if not detail.name in item_details: item_details[detail.name] = detail true_items.append(detail.name) if "icon_name" in item_details[detail.name]: icon = Catalog.get_icon(item_details[detail.name].icon_name) else: icon = Catalog.get_icon(detail.name) item_details[detail.name].icon_name = icon ManagedInstallsDetail = SortedDict() if report_plist.has_key("ManagedInstalls"): for item in report_plist.ManagedInstalls: ManagedInstallsDetail[item.name] = item # installs installs = SortedDict() listed = list() installsTypes = ["managed_installs", "managed_uninstalls", "optional_installs"] for installsType in installsTypes: installs[installsType] = SortedDict() for number, manifests in enumerate(sorted_Manifests): installs[installsType][manifests] = SortedDict() if manifest: for index, item in enumerate(sorted_Manifests[manifests][installsType]): listed.append(item) if ManagedInstallsDetail.has_key(item): installs[installsType][manifests][item] = ManagedInstallsDetail[item] if item in true_items: if installs[installsType].get(manifests, {}).has_key(item): installs[installsType][manifests][item].update(item_details[item]) else: installs[installsType][manifests][item] = item_details[item] installs[installsType][manifests][item].update({"incatalog": "True"}) else: if installs[installsType].get(manifests, {}).has_key(item): installs[installsType][manifests][item].update({"incatalog": "False"}) else: installs[installsType][manifests][item] = {"name": item, "incatalog": "False"} required = SortedDict() for item in sorted(ManagedInstallsDetail.items(), key=lambda x: x[1]["display_name"]): if not item[0] in listed: if item_details.has_key(item[0]): ManagedInstallsDetail[item[0]].icon_name = item_details[item[0]].icon_name else: ManagedInstallsDetail[item[0]].icon_name = "/static/img/PackageIcon.png" required[item[0]] = ManagedInstallsDetail[item[0]] # handle items that were installed during the most recent run install_results = {} for result in report_plist.get("InstallResults", []): nameAndVers = result["name"] + "-" + result["version"] if result["status"] == 0: install_results[nameAndVers] = "installed" else: install_results[nameAndVers] = "error" if install_results: for item in report_plist.get("ItemsToInstall", []): name = item.get("display_name", item["name"]) nameAndVers = "%s-%s" % (name, item["version_to_install"]) item["install_result"] = install_results.get(nameAndVers, "pending") for item in report_plist.get("ManagedInstalls", []): if "version_to_install" in item: name = item.get("display_name", item["name"]) nameAndVers = "%s-%s" % (name, item["version_to_install"]) if install_results.get(nameAndVers) == "installed": item["installed"] = True # handle items that were removed during the most recent run # this is crappy. We should fix it in Munki. removal_results = {} # for result in report_plist.get('RemovalResults', []): # m = re.search('^Removal of (.+): (.+)$', result) # if m: # try: # if m.group(2) == 'SUCCESSFUL': # removal_results[m.group(1)] = 'removed' # else: # removal_results[m.group(1)] = m.group(2) # except IndexError: # pass if removal_results: for item in report_plist.get("ItemsToRemove", []): name = item.get("display_name", item["name"]) item["install_result"] = removal_results.get(name, "pending") if item["install_result"] == "removed": if not "RemovedItems" in report_plist: report_plist["RemovedItems"] = [item["name"]] elif not name in report_plist["RemovedItems"]: report_plist["RemovedItems"].append(item["name"]) c = RequestContext( request, { "manifest_name": manifest_name, "manifest": manifest, "report": report_plist, "installs": installs, "autocomplete_data": autocomplete_data, "required": required, "valid_manifest_names": valid_manifest_names, "valid_catalogs": valid_catalogs, }, ) c.update(csrf(request)) return render_to_response("reports/detail_pkg.html", c)
def json_catalog_data(request): """Returns complied and sorted catalog data in JSON format""" LOGGER.debug("Got request for catalog data") return HttpResponse(json.dumps(Catalog.catalog_info()), content_type="application/json")
def old_json_catalog_names(request): valid_catalogs = Catalog.list() valid_catalogs.sort() return HttpResponse(json.dumps(valid_catalogs), mimetype='application/json')
def detail(request, manifest_name): if request.method == 'POST': if not request.user.has_perm('manifests.change_manifests'): return HttpResponse(json.dumps('error')) if request.is_ajax(): json_data = json.loads(request.body) if json_data: manifest_detail = Manifest.read(manifest_name) for key in json_data.keys(): manifest_detail[key] = json_data[key] Manifest.write(manifest_name, manifest_detail, request.user) logger.info("ManifestWrite instigated.") return HttpResponse(json.dumps('success')) if request.method == 'GET': if not request.user.has_perm('manifests.can_view_manifests'): return HttpResponse(json.dumps('error')) manifest = Manifest.read(manifest_name) #valid_install_items = Manifest.getValidInstallItems(manifest_name) install_items = Manifest.getInstallItemNames(manifest_name) valid_install_items = (install_items['suggested'] + install_items['updates'] + install_items['with_version']) suggested_install_items = install_items['suggested'] valid_catalogs = Catalog.list() valid_manifest_names = Manifest.list() autocomplete_data = json.dumps({ 'items': install_items['suggested'], 'catalogs': valid_catalogs, 'manifests': valid_manifest_names }) manifest_user = manifest.get(MANIFEST_USERNAME_KEY, '') manifest_restriction = manifest.get(MANIFEST_RESTRICTION_KEY, '') user_groups = Group.objects.values_list('name', flat=True) if manifest_restriction: manifest_restriction_is_editable = None if request.user.is_superuser: manifest_restriction_is_editable = 'yes' elif request.user.is_staff and 'staff' in manifest_restriction: manifest_restriction_is_editable = 'yes' else: for item in manifest_restriction: if Manifest.can_edit_restricted_manifest(request.user, item): manifest_restriction_is_editable = 'yes' else: manifest_restriction_is_editable = 'unrestricted' git_branching_enabled = None if GIT_BRANCHING: git_branching_enabled = GIT_BRANCHING c = RequestContext(request, {'manifest_name': manifest_name.replace(':', '/'), 'manifest_user': manifest_user, 'manifest_user_is_editable': MANIFEST_USERNAME_IS_EDITABLE, 'manifest': manifest, 'valid_install_items': valid_install_items, 'install_items': install_items, 'valid_catalogs': valid_catalogs, 'valid_manifest_names': valid_manifest_names, 'autocomplete_data': autocomplete_data, 'git_branching_enabled': git_branching_enabled, 'restriction_key': MANIFEST_RESTRICTION_KEY, 'manifest_restriction': manifest_restriction, 'manifest_restriction_is_editable': manifest_restriction_is_editable, 'user_groups': user_groups, 'user': request.user, 'page': 'manifests'}) c.update(csrf(request)) return render_to_response('manifests/detail.html', c)
def get_cataloglist(): return Catalog.list()