<s> import os <EOL> from operator import itemgetter <EOL> from random import shuffle <EOL> from string import Template <EOL> from unicodedata import normalize <EOL> import MunkiItems <EOL> import msclib <EOL> import msclog <EOL> import munki <EOL> from AppKit import NSApp <EOL> from Foundation import NSBundle <EOL> from Foundation import NSString , NSLocalizedString , NSUTF8StringEncoding <EOL> def quote ( a_string ) : <EOL> '''<STR_LIT>''' <EOL> return str ( NSString . stringWithString_ ( <EOL> a_string ) . stringByAddingPercentEscapesUsingEncoding_ ( <EOL> NSUTF8StringEncoding ) ) <EOL> def unquote ( a_string ) : <EOL> '''<STR_LIT>''' <EOL> return str ( NSString . stringWithString_ ( <EOL> a_string ) . stringByReplacingPercentEscapesUsingEncoding_ ( <EOL> NSUTF8StringEncoding ) ) <EOL> def get_template ( template_name , raw = False ) : <EOL> '''<STR_LIT>''' <EOL> customTemplatesPath = os . path . join ( msclib . html_dir ( ) , '<STR_LIT>' ) <EOL> resourcesPath = NSBundle . mainBundle ( ) . resourcePath ( ) <EOL> defaultTemplatesPath = os . path . join ( resourcesPath , '<STR_LIT>' ) <EOL> for directory in [ customTemplatesPath , defaultTemplatesPath ] : <EOL> templatePath = os . path . join ( directory , template_name ) <EOL> if os . path . exists ( templatePath ) : <EOL> try : <EOL> file_ref = open ( templatePath ) <EOL> template_html = file_ref . read ( ) <EOL> file_ref . close ( ) <EOL> if raw : <EOL> return template_html . decode ( '<STR_LIT:utf-8>' ) <EOL> else : <EOL> return Template ( template_html . decode ( '<STR_LIT:utf-8>' ) ) <EOL> except ( IOError , OSError ) : <EOL> return None <EOL> return None <EOL> def build_page ( filename ) : <EOL> '''<STR_LIT>''' <EOL> msclog . debug_log ( u'<STR_LIT>' % filename ) <EOL> name = os . path . splitext ( filename ) [ <NUM_LIT:0> ] <EOL> key , p , value = name . partition ( '<STR_LIT:->' ) <EOL> if key == '<STR_LIT>' : <EOL> build_detail_page ( value ) <EOL> elif key == '<STR_LIT>' : <EOL> build_list_page ( category = value ) <EOL> elif key == '<STR_LIT>' : <EOL> build_categories_page ( ) <EOL> elif key == '<STR_LIT>' : <EOL> build_list_page ( filter = value ) <EOL> elif key == '<STR_LIT>' : <EOL> build_list_page ( developer = value ) <EOL> elif key == '<STR_LIT>' : <EOL> build_myitems_page ( ) <EOL> elif key == '<STR_LIT>' : <EOL> build_updates_page ( ) <EOL> elif key == '<STR_LIT>' : <EOL> build_updatedetail_page ( value ) <EOL> else : <EOL> build_item_not_found_page ( filename ) <EOL> def write_page ( page_name , html ) : <EOL> '''<STR_LIT>''' <EOL> html_file = os . path . join ( msclib . html_dir ( ) , page_name ) <EOL> try : <EOL> f = open ( html_file , '<STR_LIT:w>' ) <EOL> f . write ( html . encode ( '<STR_LIT:utf-8>' ) ) <EOL> f . close ( ) <EOL> except ( OSError , IOError ) , err : <EOL> msclog . debug_log ( '<STR_LIT>' , str ( err ) ) <EOL> raise <EOL> def assemble_page ( main_page_template_name , page_dict , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> addGeneralLabels ( page_dict ) <EOL> main_page = get_template ( main_page_template_name ) <EOL> html_template = Template ( main_page . safe_substitute ( ** kwargs ) ) <EOL> html = html_template . safe_substitute ( page_dict ) <EOL> return html <EOL> def generate_page ( page_name , main_page_template_name , page_dict , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> msclog . debug_log ( '<STR_LIT>' % page_name ) <EOL> html = assemble_page ( main_page_template_name , page_dict , ** kwargs ) <EOL> write_page ( page_name , html ) <EOL> def escape_quotes ( text ) : <EOL> """<STR_LIT>""" <EOL> return text . replace ( "<STR_LIT:'>" , r"<STR_LIT>" ) . replace ( '<STR_LIT:">' , r'<STR_LIT>' ) <EOL> def escape_html ( text ) : <EOL> """<STR_LIT>""" <EOL> html_escape_table = { <EOL> "<STR_LIT:&>" : "<STR_LIT>" , <EOL> '<STR_LIT:">' : "<STR_LIT>" , <EOL> "<STR_LIT:'>" : "<STR_LIT>" , <EOL> "<STR_LIT:>>" : "<STR_LIT>" , <EOL> "<STR_LIT:<>" : "<STR_LIT>" , <EOL> } <EOL> return "<STR_LIT>" . join ( html_escape_table . get ( c , c ) for c in text ) <EOL> def escapeAndQuoteCommonFields ( item ) : <EOL> '''<STR_LIT>''' <EOL> item [ '<STR_LIT>' ] = escape_html ( item [ '<STR_LIT:name>' ] ) <EOL> item [ '<STR_LIT>' ] = escape_html ( escape_quotes ( item [ '<STR_LIT:name>' ] ) ) <EOL> item [ '<STR_LIT>' ] = escape_html ( item [ '<STR_LIT>' ] ) <EOL> item [ '<STR_LIT>' ] = escape_html ( item [ '<STR_LIT>' ] ) <EOL> item [ '<STR_LIT>' ] = escape_html ( item [ '<STR_LIT>' ] ) <EOL> def addGeneralLabels ( page ) : <EOL> '''<STR_LIT>''' <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> def addDetailSidebarLabels ( page ) : <EOL> '''<STR_LIT>''' <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> def build_item_not_found_page ( page_name ) : <EOL> '''<STR_LIT>''' <EOL> page = { } <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> footer = get_template ( '<STR_LIT>' , raw = True ) <EOL> generate_page ( page_name , '<STR_LIT>' , page , footer = footer ) <EOL> def build_detail_page ( item_name ) : <EOL> '''<STR_LIT>''' <EOL> msclog . debug_log ( '<STR_LIT>' % item_name ) <EOL> items = MunkiItems . getOptionalInstallItems ( ) <EOL> page_name = u'<STR_LIT>' % item_name <EOL> for item in items : <EOL> if item [ '<STR_LIT:name>' ] == item_name : <EOL> page = MunkiItems . OptionalItem ( item ) <EOL> escapeAndQuoteCommonFields ( page ) <EOL> addDetailSidebarLabels ( page ) <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> more_in_category_html = u'<STR_LIT>' <EOL> more_in_category = [ ] <EOL> if item . get ( '<STR_LIT>' ) : <EOL> category = item [ '<STR_LIT>' ] <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' % quote ( category ) <EOL> more_in_category = [ a for a in items <EOL> if a . get ( '<STR_LIT>' ) == category <EOL> and a != item <EOL> and a . get ( '<STR_LIT:status>' ) != '<STR_LIT>' ] <EOL> if more_in_category : <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> page [ '<STR_LIT>' ] = page [ '<STR_LIT>' ] % page [ '<STR_LIT>' ] <EOL> shuffle ( more_in_category ) <EOL> more_template = get_template ( '<STR_LIT>' ) <EOL> for more_item in more_in_category [ : <NUM_LIT:4> ] : <EOL> more_item [ '<STR_LIT>' ] = escape_html ( more_item [ '<STR_LIT>' ] ) <EOL> more_item [ '<STR_LIT>' ] = more_item . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> more_in_category_html += more_template . safe_substitute ( more_item ) <EOL> page [ '<STR_LIT>' ] = more_in_category_html <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> more_by_developer_html = u'<STR_LIT>' <EOL> more_by_developer = [ ] <EOL> if item . get ( '<STR_LIT>' ) : <EOL> developer = item [ '<STR_LIT>' ] <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' % quote ( developer ) <EOL> more_by_developer = [ a for a in items <EOL> if a . get ( '<STR_LIT>' ) == developer <EOL> and a != item <EOL> and a not in more_in_category <EOL> and a . get ( '<STR_LIT:status>' ) != '<STR_LIT>' ] <EOL> if more_by_developer : <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> page [ '<STR_LIT>' ] = ( <EOL> page [ '<STR_LIT>' ] % developer ) <EOL> shuffle ( more_by_developer ) <EOL> more_template = get_template ( <EOL> '<STR_LIT>' ) <EOL> for more_item in more_by_developer [ : <NUM_LIT:4> ] : <EOL> escapeAndQuoteCommonFields ( more_item ) <EOL> more_item [ '<STR_LIT>' ] = more_item . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> more_by_developer_html += more_template . safe_substitute ( more_item ) <EOL> page [ '<STR_LIT>' ] = more_by_developer_html <EOL> footer = get_template ( '<STR_LIT>' , raw = True ) <EOL> generate_page ( page_name , '<STR_LIT>' , page , footer = footer ) <EOL> return <EOL> msclog . debug_log ( '<STR_LIT>' % item_name ) <EOL> build_item_not_found_page ( page_name ) <EOL> def build_list_page ( category = None , developer = None , filter = None ) : <EOL> '''<STR_LIT>''' <EOL> items = MunkiItems . getOptionalInstallItems ( ) <EOL> header = NSLocalizedString ( u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> page_name = u'<STR_LIT>' <EOL> if category == '<STR_LIT:all>' : <EOL> category = None <EOL> if category : <EOL> header = category <EOL> page_name = u'<STR_LIT>' % category <EOL> if developer : <EOL> header = developer <EOL> page_name = u'<STR_LIT>' % developer <EOL> if filter : <EOL> header = u'<STR_LIT>' % filter <EOL> page_name = u'<STR_LIT>' % filter <EOL> category_list = [ ] <EOL> for item in items : <EOL> if '<STR_LIT>' in item and item [ '<STR_LIT>' ] not in category_list : <EOL> category_list . append ( item [ '<STR_LIT>' ] ) <EOL> item_html = build_list_page_items_html ( <EOL> category = category , developer = developer , filter = filter ) <EOL> all_categories_label = NSLocalizedString ( u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> if category : <EOL> categories_html = u'<STR_LIT>' % all_categories_label <EOL> else : <EOL> categories_html = u'<STR_LIT>' % all_categories_label <EOL> for item in sorted ( category_list ) : <EOL> if item == category : <EOL> categories_html += u'<STR_LIT>' % item <EOL> else : <EOL> categories_html += u'<STR_LIT>' % item <EOL> categories_html_list = '<STR_LIT>' <EOL> for item in sorted ( category_list ) : <EOL> categories_html_list += ( u'<STR_LIT>' <EOL> % ( quote ( item ) , item ) ) <EOL> page = { } <EOL> page [ '<STR_LIT>' ] = item_html <EOL> page [ '<STR_LIT>' ] = categories_html <EOL> page [ '<STR_LIT>' ] = categories_html_list <EOL> page [ '<STR_LIT>' ] = header <EOL> if category or filter or developer : <EOL> showcase = '<STR_LIT>' <EOL> else : <EOL> showcase = get_template ( '<STR_LIT>' , raw = True ) <EOL> sidebar = get_template ( '<STR_LIT>' , raw = True ) <EOL> footer = get_template ( '<STR_LIT>' , raw = True ) <EOL> generate_page ( page_name , '<STR_LIT>' , page , <EOL> showcase = showcase , sidebar = sidebar , footer = footer ) <EOL> def build_list_page_items_html ( category = None , developer = None , filter = None ) : <EOL> '''<STR_LIT>''' <EOL> items = MunkiItems . getOptionalInstallItems ( ) <EOL> item_html = u'<STR_LIT>' <EOL> if filter : <EOL> filter = normalize ( '<STR_LIT>' , filter ) <EOL> msclog . debug_log ( u'<STR_LIT>' % filter ) <EOL> items = [ item for item in items <EOL> if filter in item [ '<STR_LIT>' ] . lower ( ) <EOL> or filter in item [ '<STR_LIT:description>' ] . lower ( ) <EOL> or filter in item [ '<STR_LIT>' ] . lower ( ) <EOL> or filter in item [ '<STR_LIT>' ] . lower ( ) ] <EOL> if category : <EOL> items = [ item for item in items <EOL> if category . lower ( ) in item . get ( '<STR_LIT>' , '<STR_LIT>' ) . lower ( ) ] <EOL> if developer : <EOL> items = [ item for item in items <EOL> if developer . lower ( ) in item . get ( '<STR_LIT>' , '<STR_LIT>' ) . lower ( ) ] <EOL> if items : <EOL> item_template = get_template ( '<STR_LIT>' ) <EOL> for item in sorted ( items , key = itemgetter ( '<STR_LIT>' ) ) : <EOL> escapeAndQuoteCommonFields ( item ) <EOL> item [ '<STR_LIT>' ] = escape_html ( item [ '<STR_LIT>' ] ) <EOL> item_html += item_template . safe_substitute ( item ) <EOL> if len ( items ) % <NUM_LIT:3> : <EOL> for x in range ( <NUM_LIT:3> - ( len ( items ) % <NUM_LIT:3> ) ) : <EOL> item_html += u'<STR_LIT>' <EOL> else : <EOL> status_results_template = get_template ( '<STR_LIT>' ) <EOL> alert = { } <EOL> if filter : <EOL> alert [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> alert [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> elif category : <EOL> alert [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> alert [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> elif developer : <EOL> alert [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> alert [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> else : <EOL> alert [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> alert [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> alert [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> alert [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> item_html = status_results_template . safe_substitute ( alert ) <EOL> return item_html <EOL> def build_categories_page ( ) : <EOL> '''<STR_LIT>''' <EOL> all_items = MunkiItems . getOptionalInstallItems ( ) <EOL> header = NSLocalizedString ( u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> page_name = u'<STR_LIT>' <EOL> category_list = [ ] <EOL> for item in all_items : <EOL> if '<STR_LIT>' in item and item [ '<STR_LIT>' ] not in category_list : <EOL> category_list . append ( item [ '<STR_LIT>' ] ) <EOL> item_html = build_category_items_html ( ) <EOL> all_categories_label = NSLocalizedString ( u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> categories_html = u'<STR_LIT>' % all_categories_label <EOL> for item in sorted ( category_list ) : <EOL> categories_html += u'<STR_LIT>' % item <EOL> page = { } <EOL> page [ '<STR_LIT>' ] = item_html <EOL> page [ '<STR_LIT>' ] = categories_html <EOL> page [ '<STR_LIT>' ] = header <EOL> footer = get_template ( '<STR_LIT>' , raw = True ) <EOL> generate_page ( page_name , '<STR_LIT>' , page , showcase = u'<STR_LIT>' , sidebar = u'<STR_LIT>' , footer = footer ) <EOL> def build_category_items_html ( ) : <EOL> '''<STR_LIT>''' <EOL> all_items = MunkiItems . getOptionalInstallItems ( ) <EOL> if all_items : <EOL> category_list = [ ] <EOL> for item in all_items : <EOL> if '<STR_LIT>' in item and item [ '<STR_LIT>' ] not in category_list : <EOL> category_list . append ( item [ '<STR_LIT>' ] ) <EOL> item_template = get_template ( '<STR_LIT>' ) <EOL> item_html = u'<STR_LIT>' <EOL> for category in sorted ( category_list ) : <EOL> category_data = { } <EOL> category_data [ '<STR_LIT>' ] = escape_html ( category ) <EOL> category_data [ '<STR_LIT>' ] = u'<STR_LIT>' % quote ( category ) <EOL> category_items = [ item for item in all_items if item . get ( '<STR_LIT>' ) == category ] <EOL> shuffle ( category_items ) <EOL> category_data [ '<STR_LIT>' ] = category_items [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> category_data [ '<STR_LIT>' ] = escape_html ( <EOL> category_items [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) <EOL> category_data [ '<STR_LIT>' ] = category_items [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> if len ( category_items ) > <NUM_LIT:1> : <EOL> category_data [ '<STR_LIT>' ] = escape_html ( <EOL> category_items [ <NUM_LIT:1> ] [ '<STR_LIT>' ] ) <EOL> category_data [ '<STR_LIT>' ] = category_items [ <NUM_LIT:1> ] [ '<STR_LIT>' ] <EOL> else : <EOL> category_data [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> category_data [ '<STR_LIT>' ] = u'<STR_LIT:#>' <EOL> if len ( category_items ) > <NUM_LIT:2> : <EOL> category_data [ '<STR_LIT>' ] = escape_html ( <EOL> category_items [ <NUM_LIT:2> ] [ '<STR_LIT>' ] ) <EOL> category_data [ '<STR_LIT>' ] = category_items [ <NUM_LIT:2> ] [ '<STR_LIT>' ] <EOL> else : <EOL> category_data [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> category_data [ '<STR_LIT>' ] = u'<STR_LIT:#>' <EOL> item_html += item_template . safe_substitute ( category_data ) <EOL> if len ( category_list ) % <NUM_LIT:3> : <EOL> for x in range ( <NUM_LIT:3> - ( len ( category_list ) % <NUM_LIT:3> ) ) : <EOL> item_html += u'<STR_LIT>' <EOL> else : <EOL> status_results_template = get_template ( '<STR_LIT>' ) <EOL> alert = { } <EOL> alert [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> alert [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> alert [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> alert [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> item_html = status_results_template . safe_substitute ( alert ) <EOL> return item_html <EOL> def build_myitems_page ( ) : <EOL> '''<STR_LIT>''' <EOL> page_name = u'<STR_LIT>' <EOL> page = { } <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> page [ '<STR_LIT>' ] = build_myitems_rows ( ) <EOL> footer = get_template ( '<STR_LIT>' , raw = True ) <EOL> generate_page ( page_name , '<STR_LIT>' , page , footer = footer ) <EOL> def build_myitems_rows ( ) : <EOL> '''<STR_LIT>''' <EOL> item_list = MunkiItems . getMyItemsList ( ) <EOL> if item_list : <EOL> item_template = get_template ( '<STR_LIT>' ) <EOL> myitems_rows = u'<STR_LIT>' <EOL> for item in sorted ( item_list , key = itemgetter ( '<STR_LIT>' ) ) : <EOL> escapeAndQuoteCommonFields ( item ) <EOL> myitems_rows += item_template . safe_substitute ( item ) <EOL> else : <EOL> status_results_template = get_template ( '<STR_LIT>' ) <EOL> alert = { } <EOL> alert [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> alert [ '<STR_LIT>' ] = ( <EOL> u'<STR_LIT>' % NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) ) <EOL> alert [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> myitems_rows = status_results_template . safe_substitute ( alert ) <EOL> return myitems_rows <EOL> def build_updates_page ( ) : <EOL> '''<STR_LIT>''' <EOL> page_name = u'<STR_LIT>' <EOL> if NSApp . delegate ( ) . mainWindowController . _update_in_progress : <EOL> return build_update_status_page ( ) <EOL> item_list = MunkiItems . getEffectiveUpdateList ( ) <EOL> other_updates = [ <EOL> item for item in MunkiItems . getOptionalInstallItems ( ) <EOL> if item [ '<STR_LIT:status>' ] == '<STR_LIT>' ] <EOL> page = { } <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> item_template = get_template ( '<STR_LIT>' ) <EOL> if item_list : <EOL> for item in item_list : <EOL> escapeAndQuoteCommonFields ( item ) <EOL> page [ '<STR_LIT>' ] += item_template . safe_substitute ( item ) <EOL> elif not other_updates : <EOL> status_results_template = get_template ( '<STR_LIT>' ) <EOL> alert = { } <EOL> alert [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> alert [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> alert [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> alert [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> page [ '<STR_LIT>' ] = status_results_template . safe_substitute ( alert ) <EOL> count = len ( item_list ) <EOL> page [ '<STR_LIT>' ] = msclib . updateCountMessage ( count ) <EOL> page [ '<STR_LIT>' ] = msclib . getInstallAllButtonTextForCount ( count ) <EOL> page [ '<STR_LIT>' ] = get_warning_text ( ) <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> if other_updates : <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> for item in other_updates : <EOL> escapeAndQuoteCommonFields ( item ) <EOL> page [ '<STR_LIT>' ] += item_template . safe_substitute ( item ) <EOL> footer = get_template ( '<STR_LIT>' , raw = True ) <EOL> generate_page ( page_name , '<STR_LIT>' , page , footer = footer ) <EOL> def build_update_status_page ( ) : <EOL> '''<STR_LIT>''' <EOL> page_name = u'<STR_LIT>' <EOL> item_list = [ ] <EOL> other_updates = [ ] <EOL> status_title_default = NSLocalizedString ( u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> page = { } <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> status_controller = NSApp . delegate ( ) . statusController <EOL> status_results_template = get_template ( '<STR_LIT>' ) <EOL> alert = { } <EOL> alert [ '<STR_LIT>' ] = ( <EOL> status_controller . _status_message <EOL> or NSLocalizedString ( u"<STR_LIT>" , u"<STR_LIT>" ) ) <EOL> alert [ '<STR_LIT>' ] = ( status_controller . _status_detail or '<STR_LIT>' ) <EOL> alert [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> if status_controller . _status_percent < <NUM_LIT:0> : <EOL> alert [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> else : <EOL> alert [ '<STR_LIT>' ] = ( u'<STR_LIT>' <EOL> % status_controller . _status_percent ) <EOL> page [ '<STR_LIT>' ] = status_results_template . safe_substitute ( alert ) <EOL> install_all_button_classes = [ ] <EOL> if status_controller . _status_stopBtnHidden : <EOL> install_all_button_classes . append ( u'<STR_LIT>' ) <EOL> if status_controller . _status_stopBtnDisabled : <EOL> install_all_button_classes . append ( u'<STR_LIT>' ) <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT:U+0020>' . join ( install_all_button_classes ) <EOL> page [ '<STR_LIT>' ] = NSApp . delegate ( ) . mainWindowController . _status_title or status_title_default <EOL> page [ '<STR_LIT>' ] = NSLocalizedString ( u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> footer = get_template ( '<STR_LIT>' , raw = True ) <EOL> generate_page ( page_name , '<STR_LIT>' , page , footer = footer ) <EOL> def getRestartActionForUpdateList ( update_list ) : <EOL> '''<STR_LIT>''' <EOL> if not update_list : <EOL> return '<STR_LIT>' <EOL> if [ item for item in update_list if '<STR_LIT>' in item . get ( '<STR_LIT>' , '<STR_LIT>' ) ] : <EOL> return NSLocalizedString ( u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> if ( [ item for item in update_list if '<STR_LIT>' in item . get ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> or munki . installRequiresLogout ( ) ) : <EOL> return NSLocalizedString ( u"<STR_LIT>" , u"<STR_LIT>" ) <EOL> else : <EOL> return '<STR_LIT>' <EOL> def get_warning_text ( ) : <EOL> '''<STR_LIT>''' <EOL> item_list = MunkiItems . getEffectiveUpdateList ( ) <EOL> warning_text = u'<STR_LIT>' <EOL> forced_install_date = munki . earliestForceInstallDate ( item_list ) <EOL> if forced_install_date : <EOL> date_str = munki . stringFromDate ( forced_install_date ) <EOL> forced_date_text = NSLocalizedString ( <EOL> u"<STR_LIT>" , <EOL> u"<STR_LIT>" ) <EOL> warning_text = forced_date_text % date_str <EOL> restart_text = getRestartActionForUpdateList ( item_list ) <EOL> if restart_text : <EOL> if warning_text : <EOL> warning_text += u'<STR_LIT>' + restart_text <EOL> else : <EOL> warning_text = restart_text <EOL> return warning_text <EOL> def build_updatedetail_page ( identifier ) : <EOL> '''<STR_LIT>''' <EOL> items = MunkiItems . getUpdateList ( ) <EOL> page_name = u'<STR_LIT>' % identifier <EOL> name , sep , version = identifier . partition ( '<STR_LIT>' ) <EOL> for item in items : <EOL> if item [ '<STR_LIT:name>' ] == name and item . get ( '<STR_LIT>' , '<STR_LIT>' ) == version : <EOL> page = MunkiItems . UpdateItem ( item ) <EOL> escapeAndQuoteCommonFields ( page ) <EOL> addDetailSidebarLabels ( page ) <EOL> force_install_after_date = item . get ( '<STR_LIT>' ) <EOL> if force_install_after_date : <EOL> try : <EOL> local_date = munki . discardTimeZoneFromDate ( <EOL> force_install_after_date ) <EOL> date_str = munki . shortRelativeStringFromDate ( <EOL> local_date ) <EOL> page [ '<STR_LIT>' ] += u'<STR_LIT:U+0020>' <EOL> page [ '<STR_LIT>' ] = date_str <EOL> except munki . BadDateError : <EOL> msclog . debug_log ( '<STR_LIT>' % identifier ) <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> else : <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> page [ '<STR_LIT>' ] = u'<STR_LIT>' <EOL> footer = get_template ( '<STR_LIT>' , raw = True ) <EOL> generate_page ( page_name , '<STR_LIT>' , page , footer = footer ) <EOL> return <EOL> msclog . debug_log ( '<STR_LIT>' % identifier ) <EOL> build_item_not_found_page ( page_name ) </s>
