def build_header(prim, webdir=''):
 try:
  uptime = calc_age(sabnzbd.START)
 except:
  uptime = '-'
 if prim:
  color = sabnzbd.WEB_COLOR
 else:
  color = sabnzbd.WEB_COLOR2
 if (not color):
  color = ''
 header = {'T': Ttemplate, 'Tspec': Tspec, 'Tx': Ttemplate, 'version': sabnzbd.__version__, 'paused': (Downloader.do.paused or Downloader.do.postproc), 'pause_int': scheduler.pause_int(), 'paused_all': sabnzbd.PAUSED_ALL, 'uptime': uptime, 'color_scheme': color}
 speed_limit = Downloader.do.get_limit()
 if (speed_limit <= 0):
  speed_limit = 100
 speed_limit_abs = Downloader.do.get_limit_abs()
 if (speed_limit_abs <= 0):
  speed_limit_abs = ''
 free1 = diskfree(cfg.download_dir.get_path())
 free2 = diskfree(cfg.complete_dir.get_path())
 header['helpuri'] = 'https://sabnzbd.org/wiki/'
 header['diskspace1'] = ('%.2f' % free1)
 header['diskspace2'] = ('%.2f' % free2)
 header['diskspace1_norm'] = to_units((free1 * GIGI))
 header['diskspace2_norm'] = to_units((free2 * GIGI))
 header['diskspacetotal1'] = ('%.2f' % disktotal(cfg.download_dir.get_path()))
 header['diskspacetotal2'] = ('%.2f' % disktotal(cfg.complete_dir.get_path()))
 header['loadavg'] = loadavg()
 header['speedlimit'] = '{1:0.{0}f}'.format(int(((speed_limit % 1) > 0)), speed_limit)
 header['speedlimit_abs'] = ('%s' % speed_limit_abs)
 header['restart_req'] = sabnzbd.RESTART_REQ
 header['have_warnings'] = str(sabnzbd.GUIHANDLER.count())
 header['last_warning'] = sabnzbd.GUIHANDLER.last().replace('WARNING', 'WARNING:').replace('ERROR', T('ERROR:'))
 header['active_lang'] = cfg.language()
 header['my_lcldata'] = sabnzbd.DIR_LCLDATA
 header['my_home'] = sabnzbd.DIR_HOME
 header['webdir'] = webdir
 header['pid'] = os.getpid()
 header['finishaction'] = sabnzbd.QUEUECOMPLETE
 header['nt'] = sabnzbd.WIN32
 header['darwin'] = sabnzbd.DARWIN
 header['power_options'] = (sabnzbd.WIN32 or sabnzbd.DARWIN or sabnzbd.LINUX_POWER)
 header['session'] = cfg.api_key()
 header['quota'] = to_units(BPSMeter.do.quota)
 header['have_quota'] = bool((BPSMeter.do.quota > 0.0))
 header['left_quota'] = to_units(BPSMeter.do.left)
 anfo = ArticleCache.do.cache_info()
 header['cache_art'] = str(anfo.article_sum)
 header['cache_size'] = format_bytes(anfo.cache_size)
 header['cache_max'] = str(anfo.cache_limit)
 header['pp_pause_event'] = sabnzbd.scheduler.pp_pause_event()
 if sabnzbd.NEW_VERSION:
  (header['new_release'], header['new_rel_url']) = sabnzbd.NEW_VERSION
 else:
  header['new_release'] = ''
  header['new_rel_url'] = ''
 return header

def build_header ( prim , webdir = '' ) : try : uptime = calc_age ( sabnzbd . START ) except : uptime = '-' if prim : color = sabnzbd . WEB_COLOR else : color = sabnzbd . WEB_COLOR2 if ( not color ) : color = '' header = { 'T' : Ttemplate , 'Tspec' : Tspec , 'Tx' : Ttemplate , 'version' : sabnzbd . __version__ , 'paused' : ( Downloader . do . paused or Downloader . do . postproc ) , 'pause_int' : scheduler . pause_int ( ) , 'paused_all' : sabnzbd . PAUSED_ALL , 'uptime' : uptime , 'color_scheme' : color } speed_limit = Downloader . do . get_limit ( ) if ( speed_limit <= 0 ) : speed_limit = 100 speed_limit_abs = Downloader . do . get_limit_abs ( ) if ( speed_limit_abs <= 0 ) : speed_limit_abs = '' free1 = diskfree ( cfg . download_dir . get_path ( ) ) free2 = diskfree ( cfg . complete_dir . get_path ( ) ) header [ 'helpuri' ] = 'https://sabnzbd.org/wiki/' header [ 'diskspace1' ] = ( '%.2f' % free1 ) header [ 'diskspace2' ] = ( '%.2f' % free2 ) header [ 'diskspace1_norm' ] = to_units ( ( free1 * GIGI ) ) header [ 'diskspace2_norm' ] = to_units ( ( free2 * GIGI ) ) header [ 'diskspacetotal1' ] = ( '%.2f' % disktotal ( cfg . download_dir . get_path ( ) ) ) header [ 'diskspacetotal2' ] = ( '%.2f' % disktotal ( cfg . complete_dir . get_path ( ) ) ) header [ 'loadavg' ] = loadavg ( ) header [ 'speedlimit' ] = '{1:0.{0}f}' . format ( int ( ( ( speed_limit % 1 ) > 0 ) ) , speed_limit ) header [ 'speedlimit_abs' ] = ( '%s' % speed_limit_abs ) header [ 'restart_req' ] = sabnzbd . RESTART_REQ header [ 'have_warnings' ] = str ( sabnzbd . GUIHANDLER . count ( ) ) header [ 'last_warning' ] = sabnzbd . GUIHANDLER . last ( ) . replace ( 'WARNING' , 'WARNING:' ) . replace ( 'ERROR' , T ( 'ERROR:' ) ) header [ 'active_lang' ] = cfg . language ( ) header [ 'my_lcldata' ] = sabnzbd . DIR_LCLDATA header [ 'my_home' ] = sabnzbd . DIR_HOME header [ 'webdir' ] = webdir header [ 'pid' ] = os . getpid ( ) header [ 'finishaction' ] = sabnzbd . QUEUECOMPLETE header [ 'nt' ] = sabnzbd . WIN32 header [ 'darwin' ] = sabnzbd . DARWIN header [ 'power_options' ] = ( sabnzbd . WIN32 or sabnzbd . DARWIN or sabnzbd . LINUX_POWER ) header [ 'session' ] = cfg . api_key ( ) header [ 'quota' ] = to_units ( BPSMeter . do . quota ) header [ 'have_quota' ] = bool ( ( BPSMeter . do . quota > 0.0 ) ) header [ 'left_quota' ] = to_units ( BPSMeter . do . left ) anfo = ArticleCache . do . cache_info ( ) header [ 'cache_art' ] = str ( anfo . article_sum ) header [ 'cache_size' ] = format_bytes ( anfo . cache_size ) header [ 'cache_max' ] = str ( anfo . cache_limit ) header [ 'pp_pause_event' ] = sabnzbd . scheduler . pp_pause_event ( ) if sabnzbd . NEW_VERSION : ( header [ 'new_release' ] , header [ 'new_rel_url' ] ) = sabnzbd . NEW_VERSION else : header [ 'new_release' ] = '' header [ 'new_rel_url' ] = '' return header
build a header from a list of fields .