<s> """<STR_LIT>""" <EOL> import datetime <EOL> import re <EOL> import time <EOL> import urlparse <EOL> from google . appengine . ext import webapp <EOL> try : <EOL> from google . appengine . _internal . django . utils . safestring import mark_safe <EOL> from google . appengine . _internal . django . utils . html import conditional_escape <EOL> except ImportError : <EOL> mark_safe = lambda x : x <EOL> conditional_escape = lambda x : x <EOL> register = webapp . template . create_template_register ( ) <EOL> @ register . filter <EOL> def install_count ( munki_name , pkgs_dict ) : <EOL> return pkgs_dict . get ( munki_name , { } ) . get ( '<STR_LIT>' , '<STR_LIT:0>' ) <EOL> @ register . filter <EOL> def failure_count ( munki_name , pkgs_dict ) : <EOL> return pkgs_dict . get ( munki_name , { } ) . get ( '<STR_LIT>' , '<STR_LIT:0>' ) <EOL> @ register . filter <EOL> def spacify ( value , autoescape = None ) : <EOL> if autoescape : <EOL> esc = conditional_escape <EOL> else : <EOL> esc = lambda x : x <EOL> return mark_safe ( re . sub ( r'<STR_LIT>' , '<STR_LIT>' , esc ( value ) ) ) <EOL> spacify . needs_autoescape = True <EOL> @ register . filter <EOL> def tracks_display ( track_dict ) : <EOL> """<STR_LIT>""" <EOL> if not track_dict : <EOL> return '<STR_LIT>' <EOL> html = [ ] <EOL> for track in sorted ( track_dict , reverse = True ) : <EOL> html . append ( '<STR_LIT>' % ( <EOL> track , track_dict [ track ] , track ) ) <EOL> return mark_safe ( '<STR_LIT>' . join ( html ) ) <EOL> @ register . filter <EOL> def tracks_display_no_proposals ( track_list ) : <EOL> """<STR_LIT>""" <EOL> if not track_list : <EOL> return '<STR_LIT>' <EOL> html = [ ] <EOL> for track in sorted ( track_list , reverse = True ) : <EOL> html . append ( '<STR_LIT>' % ( <EOL> track , track ) ) <EOL> return mark_safe ( '<STR_LIT>' . join ( html ) ) <EOL> @ register . filter <EOL> def munki_property ( tag , tagname = None ) : <EOL> """<STR_LIT>""" <EOL> if not tag : <EOL> return '<STR_LIT>' <EOL> tags = { <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> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> html = '<STR_LIT>' <EOL> abbr = tags . get ( tag , tag ) <EOL> return mark_safe ( html % ( tagname or tag , tag , abbr ) ) <EOL> @ register . filter <EOL> def munki_properties ( tags ) : <EOL> return mark_safe ( '<STR_LIT:\n>' . join ( [ munki_property ( tag ) for tag in tags ] ) ) <EOL> @ register . filter <EOL> def munki_property_forcedate ( date ) : <EOL> if not date : return '<STR_LIT>' <EOL> return mark_safe ( munki_property ( <EOL> '<STR_LIT>' % date . strftime ( '<STR_LIT>' ) . lower ( ) , <EOL> '<STR_LIT>' ) ) <EOL> @ register . filter <EOL> def avg_download_speed ( installs ) : <EOL> """<STR_LIT>""" <EOL> speeds = [ i . dl_kbytes_per_sec for i in installs if i . dl_kbytes_per_sec ] <EOL> if speeds : <EOL> avg_speed = sum ( speeds ) / len ( speeds ) <EOL> return download_speed ( avg_speed ) <EOL> else : <EOL> return '<STR_LIT>' <EOL> @ register . filter <EOL> def download_speed ( kbytes_per_second ) : <EOL> """<STR_LIT>""" <EOL> if not kbytes_per_second : <EOL> return '<STR_LIT>' <EOL> if kbytes_per_second < <NUM_LIT> : <EOL> return '<STR_LIT>' % kbytes_per_second <EOL> else : <EOL> return '<STR_LIT>' % ( float ( kbytes_per_second ) / <NUM_LIT> ) <EOL> @ register . filter <EOL> def host_details_link ( uri , uuid ) : <EOL> """<STR_LIT>""" <EOL> url = urlparse . urljoin ( uri , uuid ) <EOL> return mark_safe ( '<STR_LIT>' % url ) <EOL> @ register . filter <EOL> def host_uuid_link ( uuid ) : <EOL> """<STR_LIT>""" <EOL> return mark_safe ( <EOL> '<STR_LIT>' % ( uuid , uuid ) ) <EOL> host_uuid_link . allow_tags = True <EOL> host_uuid_link . is_safe = True <EOL> @ register . filter <EOL> def uptime_from_seconds ( seconds_since_reboot ) : <EOL> """<STR_LIT>""" <EOL> if seconds_since_reboot : <EOL> uptime_days = datetime . timedelta ( seconds = seconds_since_reboot ) . days <EOL> uptime_hms = time . strftime ( '<STR_LIT>' , time . gmtime ( seconds_since_reboot ) ) <EOL> return '<STR_LIT>' % ( uptime_days , uptime_hms ) <EOL> else : <EOL> return '<STR_LIT>' </s>
