Source code :: base
[Return]
[Download]##!/usr/bin/python2
## -*- coding: utf-8 -*-
<%page args="shot, page"/>
<%!
import os, re, datetime
from bottle import static_file
from pygolem.modules import cat, emph, get_page_paths
from os.path import split, exists
from pygolem.MoinMoin import py2html
from pygolem import modules
from pygolem import Shot, set_backend, change_data_root
%>
<%
title = 'Golem No: ' + str(shot) + '-- the only fully opensource tokamak'
shot = int(shot)
if page == "":
page = "home"
allowed_types = "(htm|html|php|template)" # types allowed for loading as webpage
page_path, base_path, page = get_page_paths(shot, page)
show_source = re.match(".+\.(py|m|pro|c|sh|template)$", page)
def page_list(base):
""" return list of acceptable pages in "base" directory"""
if show_source:
sub = "" # do not replace template ending for source files
else:
sub = "(\.template)"
l = sorted([ re.sub('(.+)'+sub+'$',r"\1", file) \
for file in os.listdir( base) \
if ( re.match(".+\."+allowed_types+"$", file) \
and not re.match('.+~', file))])
return l
def get_page_name(path):
""" remove from page name numbers at beginning and .htm ending"""
name = re.sub('(\d+_)(.+)\.([\.\w]+)$', r'\2', path)
name = re.sub('([\w\ ]+)\.([\.\w]+)$', r'\1', name)
return name
if page == "": # if page is directory take the first web page
page_name = get_page_name(sorted(page_list(page_path+'/'+page))[0])
else:
page_name = get_page_name(page)
###### setup pygolem loading ###########
set_backend('http-cache-npy')
change_data_root('tmp/')
modules.Data = Shot(shot)
######## setup pygolem loading ###########
def make_menu(base, levels):
if levels is 0: # load directly all html
paths = page_list(base)
paths = sorted(paths)
for item in paths:
name = get_page_name(item)
make_item( '/' + base + '/' + item, name)
else:
try:
paths = sorted( [ base + '/' + i for i in os.listdir(base_path + base) ])
for path in paths:
if levels == 1:
make_item( path + '/' , split(path)[-1], True)
elif levels == 2:
for item in os.listdir(base_path + path):
make_item( path+'/'+item+'/' , item, True)
except:
print "!!!!!!!!!!!!!!!!!!!!!!!!!!!! menu loading failed !!!!!!!!!!!!!!!!!!!!"
%>
<%def name="make_item(path, item, value=None)">
<%
# remove names, dates, initials
name = re.sub('(\d+)([a-zA-Z\ ]+)([_\.\w]+)', r'\2', item)
name = re.sub('([\w]+)/([a-zA-Z\ ]+)', r'\2', name)
%>
<li>
%if value == 1:
✓
%elif value == 0:
✕
%elif value == 2:
?
%endif
<a class="reference internal" href="${path}">${name}</a>
</li>
</%def>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${ title } </title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="/_static/default.css" type="text/css" />
<link rel="stylesheet" href="/_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="/_static/lightbox.css" type="text/css" media="screen" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '0.2',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="/_static/jquery.js"></script>
<script type="text/javascript" src="/_static/underscore.js"></script>
<script type="text/javascript" src="/_static/doctools.js"></script>
<script type="text/javascript" src="/_static/sidebar.js"></script>
<script src="/_static/lightbox_plus.js"></script>
## switch shot number
<script type="text/javascript">
function getURL(val){
base = '/shots/'
location = base + val;
return false;
}
</script>
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" ><a href= ${'/shots/0' } title="current shot" >current</a> </li>
<li class="right" ><a href= ${'/shots/' + str(shot + 1) } title="next shot" >next</a> |</li>
<li class="right" ><a href= ${ '/shots/' + str(shot - 1) } title="previous shot" >previous</a> | </li>
<li><a href="/" > GOLEM </a> »
<a href= ${'/shots/'+str(shot)} >Shot ${"#"+str(shot)}</a> » </li>
% if page_path is not base_path :
## add one more level to the top menu
<li><a href=${'/'+page_path+'/'} > ${page_name} </a> »
%endif
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" >
% if page == 'home':
<h1>Tokamak GOLEM - Shot Database - ${shot} <a class="headerlink" href="" title="Permalink to this headline"></a></h1>
% elif show_source:
<h1>${ "Source code :: " + page_name }</a></h1>
% else:
<h1>${ page_name }</a></h1>
%endif
%if show_source: # generate source code web page
${ py2html( page_path+'/'+page ) }
%elif page_path == base_path : # base path, => main pages: data / home / references
<a class="viewcode-back" href="${ page + '.template'}">${emph("[Template source]")}</a>
<%include file="${base_path + page}.template" />
%else:
<%
if re.match(".+\."+allowed_types+"$", page):
index_page = page_path+'/'+page # link to an allowed type
else:
index_page = page_path+'/'+sorted(page_list(page_path+'/'+page))[0] # in case of link to directory
%>
% if exists(index_page + '.template'):
## include with mako preprocessing
<a class="viewcode-back" href="${ '/' + index_page + '.template'}">${emph("[Template source]")}</a>
<%include file="${ index_page + '.template'}" />
% else:
## include without preprocessing
${cat(index_page, [])}
% endif
%endif
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<a href= ${'/shots/'+str(shot)} ><img src="/_static/golem.svg" alt="" width=80 /></a>
% try:
% if page in ["home", 'data', 'references', 'energetics', "about"]:
<h4>Diagnostics</h4>
<ul>
<% make_menu('diagnostics',2) %>
</ul>
<h4>Analysis</h4>
<ul>
<% make_menu('analysis',2) %>
</ul>
<h4>DAS</h4>
<ul>
<% make_menu('DAS',1) %>
</ul>
<h4>Vacuum + Energetics</h4>
<ul>
<% make_menu(base_path + 'nabijeni', 0) %>
</ul>
<h3>Other</h3>
<ul class="this-page-menu">
<%
make_item('data', 'Data')
make_item('references','References')
make_item('about','About')
%>
</ul>
<h4>Navigation</h4>
<ul class="this-page-menu">
<%
make_item('/shots/' + str(shot+1), 'Next')
make_item('/shots/' + str(shot-1), 'Previous')
make_item('/shots/0', 'Current')
%>
</ul>
%elif not show_source:
<h4>Menu</h4>
<ul>
<%
make_menu(page_path, 0)
%>
<b>${make_item('/shots/' + str(shot), '« Back to homepage')}</b>
</ul>
<h4>Navigation</h4>
<ul class="this-page-menu">
<%
page_path_tmp = re.sub("^[\d]+//", "", page_path) # remove shot number from path
make_item('/shots/' + str(shot+1) +'/'+ page_path_tmp, 'Next')
make_item('/shots/' + str(shot-1) +'/'+ page_path_tmp , 'Previous')
make_item('/shots/0/' +'/'+ page_path_tmp, 'Current')
%>
</ul>
%else:
<h4>Navigation</h4>
<ul class="this-page-menu">
<% make_item("javascript:history.go(-1)", "<b>Return</b>") %>
</ul>
%endif
%except:
<h3> Menu failed </h3>
%endtry
<div id="searchbox" style="display: none">
<h3>Go to shot</h3>
<form style='display:inline;' method="post" action="" onsubmit="return getURL(this.shot.value)">
<input size="5" type="text" name="shot" value="${shot}" />
<input size="5" type="submit" name="Go" value="Go" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<span class="base_template"><a href="${ '/' + base_path + 'base.template'}" title="main template">${"[Main template]"}</a></span>
<h3>Navigation</h3>
<ul>
<li class="right" ><a href= ${'/shots/0' } title="current shot" >current</a> </li>
<li class="right" ><a href= ${'/shots/' + str(shot + 1) } title="next shot" >next</a> |</li>
<li class="right" ><a href= ${ '/shots/' + str(shot - 1) } title="previous shot" >previous</a> | </li>
</ul>
</div>
<div class="footer">
© Copyright ${ datetime.datetime.now().year }, <a href="mailto:svoboda@fjfi.cvut.cz">GOLEM Team</a>
</div>
</body>
</html>[Return]