#!/usr/bin/env python
import bottle, os, re, string
from os.path import exists
from bottle import route, debug, abort, request, redirect
from commands import getstatusoutput
from time import strptime

app = bottle.default_app()
debug(False)

@route('/<architecture>/<release>/GPUunitTestLogs/<subsystem>/<package>')
@route('/<architecture>/<release>/unitTestLogs/<subsystem>/<package>')
@route('/<architecture>/<release>/addOnTests/logs/<filename>')
@route('/<architecture>/<release>/pyRelValMatrixLogs/run/<workflow:re:[^/]+>/<filename>')
def returnFileReader(**kwds):
    data = None
    with open('/var/www/SDT/html/logreader/index.html', 'r') as myfile:
        data=myfile.read()
    return data


@route('/', defaults={'path': ''})
@route('/<path:path>')
def catch_all(path):
    return redirect("/SDT/cgi-bin/buildlogs/" + path)


if __name__ == '__main__':
    from wsgiref.handlers import CGIHandler

    CGIHandler().run(app)
