def markPendingItemsAsInstalling(self): '''While an install/removal session is happening, mark optional items that are being installed/removed with the appropriate status''' msclog.debug_log('marking pendingItems as installing') install_info = munki.getInstallInfo() items_to_be_installed_names = [item['name'] for item in install_info.get('managed_installs', [])] items_to_be_removed_names = [item['name'] for item in install_info.get('removals', [])] for name in items_to_be_installed_names: # remove names for user selections since we are installing MunkiItems.user_install_selections.discard(name) for name in items_to_be_removed_names: # remove names for user selections since we are removing MunkiItems.user_removal_selections.discard(name) for item in MunkiItems.getOptionalInstallItems(): new_status = None if item['name'] in items_to_be_installed_names: msclog.debug_log('Setting status for %s to "installing"' % item['name']) new_status = u'installing' elif item['name'] in items_to_be_removed_names: msclog.debug_log('Setting status for %s to "removing"' % item['name']) new_status = u'removing' if new_status: item['status'] = new_status self.updateDOMforOptionalItem(item)
def build_categories_page(): '''Build page showing available categories and some items in each one''' all_items = MunkiItems.getOptionalInstallItems() header = NSLocalizedString(u"Categories", u"Categories label") page_name = u'categories.html' category_list = [] for item in all_items: if 'category' in item and item['category'] not in category_list: category_list.append(item['category']) item_html = build_category_items_html() all_categories_label = NSLocalizedString(u"All Categories", u"AllCategoriesLabel") categories_html = u'<option selected>%s</option>\n' % all_categories_label for item in sorted(category_list): categories_html += u'<option>%s</option>\n' % item page = {} page['list_items'] = item_html page['category_items'] = categories_html page['header_text'] = header footer = get_template('footer_template.html', raw=True) generate_page(page_name, 'list_template.html', page, showcase=u'', sidebar=u'', footer=footer)
def build_list_page(category=None, developer=None, filter=None): '''Build page listing available optional items''' items = MunkiItems.getOptionalInstallItems() header = NSLocalizedString(u"All items", u"AllItemsHeaderText") page_name = u'category-all.html' if category == 'all': category = None if category: header = category page_name = u'category-%s.html' % category if developer: header = developer page_name = u'developer-%s.html' % developer if filter: header = u'Search results for %s' % filter page_name = u'filter-%s.html' % filter category_list = [] for item in items: if 'category' in item and item['category'] not in category_list: category_list.append(item['category']) item_html = build_list_page_items_html( category=category, developer=developer, filter=filter) # make HTML for Categories pop-up menu all_categories_label = NSLocalizedString(u"All Categories", u"AllCategoriesLabel") if category: categories_html = u'<option>%s</option>\n' % all_categories_label else: categories_html = u'<option selected>%s</option>\n' % all_categories_label for item in sorted(category_list): if item == category: categories_html += u'<option selected>%s</option>\n' % item else: categories_html += u'<option>%s</option>\n' % item categories_html_list = '' # make HTML for list of categories for item in sorted(category_list): categories_html_list += (u'<li class="link"><a href="category-%s.html">%s</a></li>\n' % (quote(item), item)) page = {} page['list_items'] = item_html page['category_items'] = categories_html page['category_list'] = categories_html_list page['header_text'] = header if category or filter or developer: showcase = '' else: showcase = get_template('showcase_template.html', raw=True) sidebar = get_template('sidebar_template.html', raw=True) footer = get_template('footer_template.html', raw=True) generate_page(page_name, 'list_template.html', page, showcase=showcase, sidebar=sidebar, footer=footer)
def build_category_items_html(): '''Returns HTML for the items on the Categories page''' all_items = MunkiItems.getOptionalInstallItems() if all_items: category_list = [] for item in all_items: if 'category' in item and item['category'] not in category_list: category_list.append(item['category']) item_template = get_template('category_item_template.html') item_html = u'' for category in sorted(category_list): category_data = {} category_data['category_name_escaped'] = escape_html(category) category_data['category_link'] = u'category-%s.html' % quote(category) category_items = [item for item in all_items if item.get('category') == category] shuffle(category_items) category_data['item1_icon'] = category_items[0]['icon'] category_data['item1_display_name_escaped'] = escape_html( category_items[0]['display_name']) category_data['item1_detail_link'] = category_items[0]['detail_link'] if len(category_items) > 1: category_data['item2_display_name_escaped'] = escape_html( category_items[1]['display_name']) category_data['item2_detail_link'] = category_items[1]['detail_link'] else: category_data['item2_display_name_escaped'] = u'' category_data['item2_detail_link'] = u'#' if len(category_items) > 2: category_data['item3_display_name_escaped'] = escape_html( category_items[2]['display_name']) category_data['item3_detail_link'] = category_items[2]['detail_link'] else: category_data['item3_display_name_escaped'] = u'' category_data['item3_detail_link'] = u'#' item_html += item_template.safe_substitute(category_data) # pad with extra empty items so we have a multiple of 3 if len(category_list) % 3: for x in range(3 - (len(category_list) % 3)): item_html += u'<div class="lockup"></div>\n' else: # no items status_results_template = get_template('status_results_template.html') alert = {} alert['primary_status_text'] = NSLocalizedString( u"There are no available software items.", u"No Items primary text") alert['secondary_status_text'] = NSLocalizedString( u"Try again later.", u"No Items secondary text") alert['hide_progress_bar'] = u'hidden' alert['progress_bar_value'] = u'' item_html = status_results_template.safe_substitute(alert) return item_html
def build_updates_page(): '''available/pending updates''' page_name = u'updates.html' # need to consolidate/centralize this flag. Accessing it this way is ugly. if NSApp.delegate().mainWindowController._update_in_progress: return build_update_status_page() item_list = MunkiItems.getEffectiveUpdateList() other_updates = [ item for item in MunkiItems.getOptionalInstallItems() if item['status'] == 'update-available' ] page = {} page['update_rows'] = u'' page['hide_progress_spinner'] = u'hidden' page['hide_other_updates'] = u'hidden' page['install_all_button_classes'] = u'' item_template = get_template('update_row_template.html') if item_list: for item in item_list: escapeAndQuoteCommonFields(item) page['update_rows'] += item_template.safe_substitute(item) elif not other_updates: status_results_template = get_template('status_results_template.html') alert = {} alert['primary_status_text'] = NSLocalizedString( u"Your software is up to date.", u"No Pending Updates primary text") alert['secondary_status_text'] = NSLocalizedString( u"There is no new software for your computer at this time.", u"No Pending Updates secondary text") alert['hide_progress_bar'] = u'hidden' alert['progress_bar_value'] = u'' page['update_rows'] = status_results_template.safe_substitute(alert) count = len(item_list) page['update_count'] = msclib.updateCountMessage(count) page['install_btn_label'] = msclib.getInstallAllButtonTextForCount(count) page['warning_text'] = get_warning_text() page['other_updates_header_message'] = NSLocalizedString( u"Other available updates", u"Other Available Updates label") page['other_update_rows'] = u'' if other_updates: page['hide_other_updates'] = u'' for item in other_updates: escapeAndQuoteCommonFields(item) page['other_update_rows'] += item_template.safe_substitute(item) footer = get_template('footer_template.html', raw=True) generate_page(page_name, 'updates_template.html', page, footer=footer)
def build_category_items_html(): '''Returns HTML for the items on the Categories page''' all_items = MunkiItems.getOptionalInstallItems() if all_items: category_list = [] for item in all_items: if 'category' in item and item['category'] not in category_list: category_list.append(item['category']) item_template = get_template('category_item_template.html') item_html = u'' for category in sorted(category_list): category_data = {} category_data['category_name_escaped'] = escape_html(category) category_data['category_link'] = u'category-%s.html' % quote(category) category_items = [item for item in all_items if item.get('category') == category] shuffle(category_items) category_data['item1_icon'] = category_items[0]['icon'] category_data['item1_display_name_escaped'] = escape_html( category_items[0]['display_name']) category_data['item1_detail_link'] = category_items[0]['detail_link'] if len(category_items) > 1: category_data['item2_display_name_escaped'] = escape_html( category_items[1]['display_name']) category_data['item2_detail_link'] = category_items[1]['detail_link'] else: category_data['item2_display_name_escaped'] = u'' category_data['item2_detail_link'] = u'#' if len(category_items) > 2: category_data['item3_display_name_escaped'] = escape_html( category_items[2]['display_name']) category_data['item3_detail_link'] = category_items[2]['detail_link'] else: category_data['item3_display_name_escaped'] = u'' category_data['item3_detail_link'] = u'#' item_html += item_template.safe_substitute(category_data) # pad with extra empty items so we have a multiple of 3 if len(category_list) % 3: for x in range(3 - (len(category_list) % 3)): item_html += u'<div class="lockup"></div>\n' else: # no items status_results_template = get_template('status_results_template.html') alert = {} alert['primary_status_text'] = NSLocalizedString( u"There are no available software items.", u"No Items primary text") alert['secondary_status_text'] = NSLocalizedString( u"Try again later.", u"No Items secondary text") alert['hide_progress_bar'] = u'hidden' alert['progress_bar_value'] = u'' item_html = status_results_template.safe_substitute(alert) return item_html
def build_detail_page(item_name): '''Build page showing detail for a single optional item''' msclog.debug_log('build_detail_page for %s' % item_name) items = MunkiItems.getOptionalInstallItems() page_name = u'detail-%s.html' % item_name for item in items: if item['name'] == item_name: page = MunkiItems.OptionalItem(item) addDetailSidebarLabels(page) # make "More in CategoryFoo" list page['hide_more_in_category'] = u'hidden' more_in_category_html = u'' more_in_category = [] if item.get('category'): category = item['category'] page['category_link'] = u'category-%s.html' % quote(category) more_in_category = [a for a in items if a.get('category') == category and a != item and a.get('status') != 'installed'] if more_in_category: page['hide_more_in_category'] = u'' page['moreInCategoryLabel'] = page['moreInCategoryLabel'] % page['category'] shuffle(more_in_category) more_template = get_template('detail_more_items_template.html') for more_item in more_in_category[:4]: more_item['second_line'] = more_item.get('developer', '') more_in_category_html += more_template.safe_substitute(more_item) page['more_in_category'] = more_in_category_html # make "More by DeveloperFoo" list page['hide_more_by_developer'] = u'hidden' more_by_developer_html = u'' more_by_developer = [] if item.get('developer'): developer = item['developer'] page['developer_link'] = u'developer-%s.html' % quote(developer) more_by_developer = [a for a in items if a.get('developer') == developer and a != item and a not in more_in_category and a.get('status') != 'installed'] if more_by_developer: page['hide_more_by_developer'] = u'' page['moreByDeveloperLabel'] = ( page['moreByDeveloperLabel'] % developer) shuffle(more_by_developer) more_template = get_template( 'detail_more_items_template.html') for more_item in more_by_developer[:4]: more_item['second_line'] = more_item.get('category', '') more_by_developer_html += more_template.safe_substitute(more_item) page['more_by_developer'] = more_by_developer_html footer = get_template('footer_template.html', raw=True) generate_page(page_name, 'detail_template.html', page, footer=footer) return msclog.debug_log('No detail found for %s' % item_name) build_item_not_found_page(page_name)
def build_updates_page(): '''available/pending updates''' page_name = u'updates.html' # need to consolidate/centralize this flag. Accessing it this way is ugly. if NSApp.delegate().mainWindowController._update_in_progress: return build_update_status_page() item_list = MunkiItems.getEffectiveUpdateList() other_updates = [ item for item in MunkiItems.getOptionalInstallItems() if item['status'] == 'update-available'] page = {} page['update_rows'] = u'' page['hide_progress_spinner'] = u'hidden' page['hide_other_updates'] = u'hidden' page['install_all_button_classes'] = u'' item_template = get_template('update_row_template.html') if item_list: for item in item_list: escapeAndQuoteCommonFields(item) page['update_rows'] += item_template.safe_substitute(item) elif not other_updates: status_results_template = get_template('status_results_template.html') alert = {} alert['primary_status_text'] = NSLocalizedString( u"Your software is up to date.", u"No Pending Updates primary text") alert['secondary_status_text'] = NSLocalizedString( u"There is no new software for your computer at this time.", u"No Pending Updates secondary text") alert['hide_progress_bar'] = u'hidden' alert['progress_bar_value'] = u'' page['update_rows'] = status_results_template.safe_substitute(alert) count = len(item_list) page['update_count'] = msclib.updateCountMessage(count) page['install_btn_label'] = msclib.getInstallAllButtonTextForCount(count) page['warning_text'] = get_warning_text() page['other_updates_header_message'] = NSLocalizedString( u"Other available updates", u"Other Available Updates label") page['other_update_rows'] = u'' if other_updates: page['hide_other_updates'] = u'' for item in other_updates: escapeAndQuoteCommonFields(item) page['other_update_rows'] += item_template.safe_substitute(item) footer = get_template('footer_template.html', raw=True) generate_page(page_name, 'updates_template.html', page, footer=footer)
def loadInitialView(self): '''Called by app delegate from applicationDidFinishLaunching:''' self.enableOrDisableSoftwareViewControls() optional_items = MunkiItems.getOptionalInstallItems() if not optional_items or self.getUpdateCount(): self.loadUpdatesPage_(self) else: self.loadAllSoftwarePage_(self) self.displayUpdateCount() self.cached_self_service = MunkiItems.SelfService()
def enableOrDisableSoftwareViewControls(self): '''Disable or enable the controls that let us view optional items''' optional_items = MunkiItems.getOptionalInstallItems() enabled_state = (len(optional_items) > 0) self.enableOrDisableToolbarButtons_(enabled_state) self.searchField.setEnabled_(enabled_state) self.findMenuItem.setEnabled_(enabled_state) self.softwareMenuItem.setEnabled_(enabled_state) self.softwareMenuItem.setEnabled_(enabled_state) self.categoriesMenuItem.setEnabled_(enabled_state) self.myItemsMenuItem.setEnabled_(enabled_state)
def markRequestedItemsAsProcessing(self): '''When an update check session is happening, mark optional items that have been requested as processing''' msclog.debug_log('marking requested items as processing') for item in MunkiItems.getOptionalInstallItems(): new_status = None if item['status'] == 'install-requested': msclog.debug_log('Setting status for %s to "downloading"' % item['name']) new_status = u'downloading' elif item['status'] == 'removal-requested': msclog.debug_log('Setting status for %s to "preparing-removal"' % item['name']) new_status = u'preparing-removal' if new_status: item['status'] = new_status self.updateDOMforOptionalItem(item)
def build_categories_page(): '''Build page showing available categories and some items in each one''' all_items = MunkiItems.getOptionalInstallItems() header = NSLocalizedString(u"Categories", u"Categories label") page_name = u'categories.html' category_list = [] for item in all_items: if 'category' in item and item['category'] not in category_list: category_list.append(item['category']) item_html = build_category_items_html() all_categories_label = NSLocalizedString(u"All Categories", u"AllCategoriesLabel") categories_html = u'<option selected>%s</option>\n' % all_categories_label for item in sorted(category_list): categories_html += u'<option>%s</option>\n' % item page = {} page['list_items'] = item_html page['category_items'] = categories_html page['header_text'] = header footer = get_template('footer_template.html', raw=True) generate_page(page_name, 'list_template.html', page, showcase=u'', sidebar=u'', footer=footer)
def build_updates_page(): '''available/pending updates''' page_name = u'updates.html' # need to consolidate/centralize this flag. Accessing it this way is ugly. if NSApp.delegate().mainWindowController._update_in_progress: return build_update_status_page() item_list = MunkiItems.getEffectiveUpdateList() problem_updates = MunkiItems.getProblemItems() for item in problem_updates: item['hide_cancel_button'] = u'hidden' # find any optional installs with update available other_updates = [ item for item in MunkiItems.getOptionalInstallItems() if item['status'] == 'update-available' ] # find any listed optional install updates that require a higher OS # or have insufficient disk space or other blockers (because they have a # note) blocked_optional_updates = [ item for item in MunkiItems.getOptionalInstallItems() if item['status'] == 'installed' and item.get('note') ] for item in blocked_optional_updates: item['hide_cancel_button'] = u'hidden' other_updates.extend(blocked_optional_updates) page = {} page['update_rows'] = u'' page['hide_progress_spinner'] = u'hidden' page['hide_problem_updates'] = u'hidden' page['hide_other_updates'] = u'hidden' page['install_all_button_classes'] = u'' item_template = get_template('update_row_template.html') # build pending updates table if item_list: for item in item_list: escapeAndQuoteCommonFields(item) page['update_rows'] += item_template.safe_substitute(item) elif not other_updates and not problem_updates: status_results_template = get_template('status_results_template.html') alert = {} alert['primary_status_text'] = NSLocalizedString( u"Your software is up to date.", u"No Pending Updates primary text") alert['secondary_status_text'] = NSLocalizedString( u"There is no new software for your computer at this time.", u"No Pending Updates secondary text") alert['hide_progress_bar'] = u'hidden' alert['progress_bar_value'] = u'' page['update_rows'] = status_results_template.safe_substitute(alert) count = len( [item for item in item_list if item['status'] != 'problem-item']) page['update_count'] = msclib.updateCountMessage(count) page['install_btn_label'] = msclib.getInstallAllButtonTextForCount(count) page['warning_text'] = get_warning_text() # build problem updates table page['problem_updates_header_message'] = NSLocalizedString( u"Problem updates", u"Problem Updates label") page['problem_update_rows'] = u'' if problem_updates: page['hide_problem_updates'] = u'' for item in problem_updates: escapeAndQuoteCommonFields(item) page['problem_update_rows'] += item_template.safe_substitute(item) # build other available updates table page['other_updates_header_message'] = NSLocalizedString( u"Other available updates", u"Other Available Updates label") page['other_update_rows'] = u'' if other_updates: page['hide_other_updates'] = u'' for item in other_updates: escapeAndQuoteCommonFields(item) page['other_update_rows'] += item_template.safe_substitute(item) footer = get_template('footer_template.html', raw=True) generate_page(page_name, 'updates_template.html', page, footer=footer)
def build_list_page_items_html(category=None, developer=None, filter=None): '''Returns HTML for the items on the list page''' items = MunkiItems.getOptionalInstallItems() item_html = u'' if filter: # since the filter term came through the filesystem, # HFS+ does some unicode character decomposition which can cause issue # with comparisons # so before we do our comparison, we normalize the unicode string # using unicodedata.normalize filter = normalize('NFC', filter) msclog.debug_log(u'Filtering on %s' % filter) items = [ item for item in items if filter in item['display_name'].lower() or filter in item['description'].lower() or filter in item['developer'].lower() or filter in item['category'].lower() ] if category: items = [ item for item in items if category.lower() == item.get('category', '').lower() ] if developer: items = [ item for item in items if developer.lower() == item.get('developer', '').lower() ] if category is None and developer is None and filter is None: # this is the default (formerly) "all items" view # look for featured items and display those if we have them featured_items = [item for item in items if item.get('featured')] if featured_items: items = featured_items if items: item_template = get_template('list_item_template.html') for item in sorted(items, key=itemgetter('display_name_lower')): escapeAndQuoteCommonFields(item) item['category_and_developer_escaped'] = escape_html( item['category_and_developer']) item_html += item_template.safe_substitute(item) # pad with extra empty items so we have a multiple of 3 if len(items) % 3: for x in range(3 - (len(items) % 3)): item_html += u'<div class="lockup"></div>\n' else: # no items; build appropriate alert messages status_results_template = get_template('status_results_template.html') alert = {} if filter: alert['primary_status_text'] = NSLocalizedString( u"Your search had no results.", u"No Search Results primary text") alert['secondary_status_text'] = NSLocalizedString( u"Try searching again.", u"No Search Results secondary text") elif category: alert['primary_status_text'] = NSLocalizedString( u"There are no items in this category.", u"No Category Results primary text") alert['secondary_status_text'] = NSLocalizedString( u"Try selecting another category.", u"No Category Results secondary text") elif developer: alert['primary_status_text'] = NSLocalizedString( u"There are no items from this developer.", u"No Developer Results primary text") alert['secondary_status_text'] = NSLocalizedString( u"Try selecting another developer.", u"No Developer Results secondary text") else: alert['primary_status_text'] = NSLocalizedString( u"There are no available software items.", u"No Items primary text") alert['secondary_status_text'] = NSLocalizedString( u"Try again later.", u"No Items secondary text") alert['hide_progress_bar'] = u'hidden' alert['progress_bar_value'] = u'' item_html = status_results_template.safe_substitute(alert) return item_html
def build_list_page(category=None, developer=None, filter=None): '''Build page listing available optional items''' items = MunkiItems.getOptionalInstallItems() header = NSLocalizedString(u"All items", u"AllItemsHeaderText") page_name = u'category-all.html' if category == 'all': category = None if category: header = category page_name = u'category-%s.html' % category if developer: header = developer page_name = u'developer-%s.html' % developer if filter: header = u'Search results for %s' % filter page_name = u'filter-%s.html' % filter featured_items = [item for item in items if item.get('featured')] if (featured_items and category is None and developer is None and filter is None): header = NSLocalizedString(u"Featured items", u"FeaturedItemsHeaderText") category_list = [] for item in items: if 'category' in item and item['category'] not in category_list: category_list.append(item['category']) item_html = build_list_page_items_html(category=category, developer=developer, filter=filter) # make HTML for Categories pop-up menu if featured_items: all_categories_label = NSLocalizedString(u"Featured", u"FeaturedLabel") else: all_categories_label = NSLocalizedString(u"All Categories", u"AllCategoriesLabel") if category: categories_html = u'<option>%s</option>\n' % all_categories_label else: categories_html = u'<option selected>%s</option>\n' % all_categories_label for item in sorted(category_list): if item == category: categories_html += u'<option selected>%s</option>\n' % item else: categories_html += u'<option>%s</option>\n' % item categories_html_list = '' # make HTML for list of categories for item in sorted(category_list): categories_html_list += ( u'<li class="link"><a href="category-%s.html">%s</a></li>\n' % (quote(item), item)) page = {} page['list_items'] = item_html page['category_items'] = categories_html page['category_list'] = categories_html_list page['header_text'] = header if category or filter or developer: showcase = '' else: showcase = get_template('showcase_template.html', raw=True) sidebar = get_template('sidebar_template.html', raw=True) footer = get_template('footer_template.html', raw=True) generate_page(page_name, 'list_template.html', page, showcase=showcase, sidebar=sidebar, footer=footer)
def build_detail_page(item_name): '''Build page showing detail for a single optional item''' msclog.debug_log('build_detail_page for %s' % item_name) items = MunkiItems.getOptionalInstallItems() page_name = u'detail-%s.html' % item_name for item in items: if item['name'] == item_name: # make a copy of the item to use to build our page page = MunkiItems.OptionalItem(item) escapeAndQuoteCommonFields(page) addDetailSidebarLabels(page) # make "More in CategoryFoo" list page['hide_more_in_category'] = u'hidden' more_in_category_html = u'' more_in_category = [] if item.get('category'): category = item['category'] page['category_link'] = u'category-%s.html' % quote(category) more_in_category = [ a for a in items if a.get('category') == category and a != item and a.get('status') != 'installed' ] if more_in_category: page['hide_more_in_category'] = u'' page['moreInCategoryLabel'] = page[ 'moreInCategoryLabel'] % page['category'] shuffle(more_in_category) more_template = get_template( 'detail_more_items_template.html') for more_item in more_in_category[:4]: more_item['display_name_escaped'] = escape_html( more_item['display_name']) more_item['second_line'] = more_item.get( 'developer', '') more_in_category_html += more_template.safe_substitute( more_item) page['more_in_category'] = more_in_category_html # make "More by DeveloperFoo" list page['hide_more_by_developer'] = u'hidden' more_by_developer_html = u'' more_by_developer = [] if item.get('developer'): developer = item['developer'] page['developer_link'] = u'developer-%s.html' % quote( developer) more_by_developer = [ a for a in items if a.get('developer') == developer and a != item and a not in more_in_category and a.get('status') != 'installed' ] if more_by_developer: page['hide_more_by_developer'] = u'' page['moreByDeveloperLabel'] = ( page['moreByDeveloperLabel'] % developer) shuffle(more_by_developer) more_template = get_template( 'detail_more_items_template.html') for more_item in more_by_developer[:4]: escapeAndQuoteCommonFields(more_item) more_item['second_line'] = more_item.get( 'category', '') more_by_developer_html += more_template.safe_substitute( more_item) page['more_by_developer'] = more_by_developer_html footer = get_template('footer_template.html', raw=True) generate_page(page_name, 'detail_template.html', page, footer=footer) return msclog.debug_log('No detail found for %s' % item_name) build_item_not_found_page(page_name)
def build_list_page_items_html(category=None, developer=None, filter=None): '''Returns HTML for the items on the list page''' items = MunkiItems.getOptionalInstallItems() item_html = u'' if filter: # since the filter term came through the filesystem, # HFS+ does some unicode character decomposition which can cause issues with comparisons # so before we do our comparison, we normalize the unicode string # using unicodedata.normalize filter = normalize('NFC', filter) msclog.debug_log(u'Filtering on %s' % filter) items = [item for item in items if filter in item['display_name'].lower() or filter in item['description'].lower() or filter in item['developer'].lower() or filter in item['category'].lower()] if category: items = [item for item in items if category.lower() in item.get('category', '').lower()] if developer: items = [item for item in items if developer.lower() in item.get('developer', '').lower()] if items: item_template = get_template('list_item_template.html') for item in sorted(items, key=itemgetter('display_name_lower')): escapeAndQuoteCommonFields(item) item['category_and_developer_escaped'] = escape_html(item['category_and_developer']) item_html += item_template.safe_substitute(item) # pad with extra empty items so we have a multiple of 3 if len(items) % 3: for x in range(3 - (len(items) % 3)): item_html += u'<div class="lockup"></div>\n' else: # no items; build appropriate alert messages status_results_template = get_template('status_results_template.html') alert = {} if filter: alert['primary_status_text'] = NSLocalizedString( u"Your search had no results.", u"No Search Results primary text") alert['secondary_status_text'] = NSLocalizedString( u"Try searching again.", u"No Search Results secondary text") elif category: alert['primary_status_text'] = NSLocalizedString( u"There are no items in this category.", u"No Category Results primary text") alert['secondary_status_text'] = NSLocalizedString( u"Try selecting another category.", u"No Category Results secondary text") elif developer: alert['primary_status_text'] = NSLocalizedString( u"There are no items from this developer.", u"No Developer Results primary text") alert['secondary_status_text'] = NSLocalizedString( u"Try selecting another developer.", u"No Developer Results secondary text") else: alert['primary_status_text'] = NSLocalizedString( u"There are no available software items.", u"No Items primary text") alert['secondary_status_text'] = NSLocalizedString( u"Try again later.", u"No Items secondary text") alert['hide_progress_bar'] = u'hidden' alert['progress_bar_value'] = u'' item_html = status_results_template.safe_substitute(alert) return item_html
def build_updates_page(): '''available/pending updates''' page_name = u'updates.html' # need to consolidate/centralize this flag. Accessing it this way is ugly. if NSApp.delegate().mainWindowController._update_in_progress: return build_update_status_page() item_list = MunkiItems.getEffectiveUpdateList() problem_updates = MunkiItems.getProblemItems() for item in problem_updates: item['hide_cancel_button'] = u'hidden' # find any optional installs with update available other_updates = [ item for item in MunkiItems.getOptionalInstallItems() if item['status'] == 'update-available'] # find any listed optional install updates that require a higher OS # or have insufficient disk space or other blockers (because they have a # note) blocked_optional_updates = [ item for item in MunkiItems.getOptionalInstallItems() if item['status'] == 'installed' and item.get('note')] for item in blocked_optional_updates: item['hide_cancel_button'] = u'hidden' other_updates.extend(blocked_optional_updates) page = {} page['update_rows'] = u'' page['hide_progress_spinner'] = u'hidden' page['hide_problem_updates'] = u'hidden' page['hide_other_updates'] = u'hidden' page['install_all_button_classes'] = u'' item_template = get_template('update_row_template.html') # build pending updates table if item_list: for item in item_list: escapeAndQuoteCommonFields(item) page['update_rows'] += item_template.safe_substitute(item) elif not other_updates and not problem_updates: status_results_template = get_template('status_results_template.html') alert = {} alert['primary_status_text'] = NSLocalizedString( u"Your software is up to date.", u"No Pending Updates primary text") alert['secondary_status_text'] = NSLocalizedString( u"There is no new software for your computer at this time.", u"No Pending Updates secondary text") alert['hide_progress_bar'] = u'hidden' alert['progress_bar_value'] = u'' page['update_rows'] = status_results_template.safe_substitute(alert) count = len([item for item in item_list if item['status'] != 'problem-item']) page['update_count'] = msclib.updateCountMessage(count) page['install_btn_label'] = msclib.getInstallAllButtonTextForCount(count) page['warning_text'] = get_warning_text() # build problem updates table page['problem_updates_header_message'] = NSLocalizedString( u"Problem updates", u"Problem Updates label") page['problem_update_rows'] = u'' if problem_updates: page['hide_problem_updates'] = u'' for item in problem_updates: escapeAndQuoteCommonFields(item) page['problem_update_rows'] += item_template.safe_substitute(item) # build other available updates table page['other_updates_header_message'] = NSLocalizedString( u"Other available updates", u"Other Available Updates label") page['other_update_rows'] = u'' if other_updates: page['hide_other_updates'] = u'' for item in other_updates: escapeAndQuoteCommonFields(item) page['other_update_rows'] += item_template.safe_substitute(item) footer = get_template('footer_template.html', raw=True) generate_page(page_name, 'updates_template.html', page, footer=footer)
def windowDidBecomeMain_(self, notification): '''Our window was activated, make sure controls enabled as needed''' optional_items = MunkiItems.getOptionalInstallItems() enabled_state = (len(optional_items) > 0) self.enableOrDisableToolbarButtons_(enabled_state)