#!/usr/bin/python2 """ AUTHOR: Michal Odstrcil 2012 Provide simple web interface for pygolem for data downloading """ from numpy import * import os, re, sys from utilities import * ###################### WEB PAGES ############################## def get_page_paths(shot, page, default_path = 'shots'): """ Return basic paths need for web pages generation """ base_path = default_path + '/' + str(shot)+'/' [ page_path, page] = os.path.split(page) page_path = base_path + page_path return page_path,base_path, page def emph(text): return ''+str(text)+'' def modified(file): try: return datetime.datetime.fromtimestamp(os.stat(file)[-1]).strftime('%Y-%m-%d') except: return 'N/A' def make_image(img_path, name = ""): """ Show image from `img_path` with title `name`. Use loading animation of not avalible. Use svgz if possible and if the browser is capable to load. """ img_path = re.sub("(.+)(\.[\w]{3,4})$",r"\1", img_path) # remove file ending (.png) out = "" if name is not "": out += "

"+name+"

\n" #full_path = './'+img_path full_path = img_path rand_end = "?%s"%random.randint(1e6) out += """
"; } else { echo "%s
"; } } else { echo "
"; echo " " ; } ?>""" % (full_path,full_path, full_path,full_path,rand_end,name,full_path,rand_end,name,full_path,full_path) return out def make_zoom_image(img_path, name = "", group = ""): """ Load image from `img_path` with title 'name`. Make image zoomable, if possible use svgz version. """ rand_end = "?%s"%random.randint(1e6) img_path = re.sub("(.+)(\.[\w]{3,4})$",r"\1", img_path) # remove file ending (.png) out = "" if name is not "": out += "

"+name+"

\n" out += """ """ + \ ""+name + (" " return out def make_config(path): """ Try to nicely load and show config from text file in shape value = 1 value2 = 3 """ try: cfg = cat(path, [], True) out =""" """ for line in cfg: # replace : or = by new cell out += ' ' out += "
' + re.sub('(.+)(\:|=)(.+)', r'\1 \3', line) + '
" except: out = "

Missing config file " + path + "

" return out def wiki(link): """ Short cat to geenrate link to wiki """ if re.match("^\/", link): # link to internal wiki, starts with / return "WIKI" else: return "WIKI" def source_link(path , revision,default_path, link, name): """ Link to formatted link in bitbucket.org """ path = re.sub("^"+default_path+"\/[\d]+\/", "", path) path = re.sub("\/\/", "\/", path + '/') # remove shots/ + shot_number from path return '[' +name+ ']'