<commit_before>import os
import sys

import traceback
import threading

# Dependencies
import flask
import requests
import flask.ext.restful

import ci
import pyblish_ci

app = flask.Flask(__name__)

this = sys.modules[__name__]
this.app = app
this.pages = {}
this.log = pyblish_ci.log
this.root = "/ci"


@app.route("/")
def home():
    return "<h3>Pyblish CI</h3>"


style = """
body {
    background-color: #fff;
    font-family: monospace;
    font-size: 12px;
    line-height: 16px;
    width: 800px;
    margin-left: auto;
    margin-right: auto;
    margin-top: 20px;
}

p {
    white-space: pre-wrap;
    margin: 0;
    padding: 0;
}

p a {
    width: 30px;
    text-align: right;
    color: #777;
}

span {
    display: inline-block;
    padding-left: 10px;
    letter-spacing: 0.4px;
    color: #F1F1F1;
}

a {
    display: inline-block;
    cursor: pointer;
}

p:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.log-body {
    background-color: #222;
    color: rgb(241, 241, 241);
    padding: 10px;
    border-radius: 5px;
}

.image-body {
    background-color: #222;
    color: rgb(241, 241, 241);
    padding: 10px;
    border-radius: 5px;
}

.builds-body {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    flex-wrap: wrap;
    width: 400px;
}

.builds-body a {
    width: 20px;
    height: 20px;
    font-size: 1.3em;

    text-align: center;
    padding: 5px;
    margin: 5px;
    background-color: #eee;
}
"""


@app.route("/jobs/<user>/<repo>")
def browse(user, repo):
    jobs = os.path.join(this.root, user, repo)
    this.log.info("Browsing: %s" % jobs)
    body = """
        <style>{style}</style>
        <h1>Builds for {name}</h1>
        <div class="builds-body">{output}</div>
    """

    builds = sorted(map(int, os.listdir(jobs)), key=int)

    return body.format(
        style=style,
        name=repo,
        output="\n".join("<a href=\"{0}/{1}\">{1}</a>".format(repo, build)
                         for build in builds))


def images(user, repo, build):

    job = "/".join([user, repo, build])

    results = ci.read_results(job)
    if not results:
        return "No results for job: %s" % job

    body = """
        <style>{style}</style>
        <h1>Images for {job}</h1>
        <div class="images-body">{output}</div>
    """

    images = results.keys()
    output = body.format(
        style=style,<commit_msg>Can browse non-existing jobs without a 505<commit_after>import os
import sys

import traceback
import threading

# Dependencies
import flask
import requests
import flask.ext.restful

import ci
import pyblish_ci

app = flask.Flask(__name__)

this = sys.modules[__name__]
this.app = app
this.pages = {}
this.log = pyblish_ci.log
this.root = "/ci"


@app.route("/")
def home():
    return "<h3>Pyblish CI</h3>"


style = """
body {
    background-color: #fff;
    font-family: monospace;
    font-size: 12px;
    line-height: 16px;
    width: 800px;
    margin-left: auto;
    margin-right: auto;
    margin-top: 20px;
}

p {
    white-space: pre-wrap;
    margin: 0;
    padding: 0;
}

p a {
    width: 30px;
    text-align: right;
    color: #777;
}

span {
    display: inline-block;
    padding-left: 10px;
    letter-spacing: 0.4px;
    color: #F1F1F1;
}

a {
    display: inline-block;
    cursor: pointer;
}

p:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.log-body {
    background-color: #222;
    color: rgb(241, 241, 241);
    padding: 10px;
    border-radius: 5px;
}

.image-body {
    background-color: #222;
    color: rgb(241, 241, 241);
    padding: 10px;
    border-radius: 5px;
}

.builds-body {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    flex-wrap: wrap;
    width: 400px;
}

.builds-body a {
    width: 20px;
    height: 20px;
    font-size: 1.3em;

    text-align: center;
    padding: 5px;
    margin: 5px;
    background-color: #eee;
}
"""


@app.route("/jobs/<user>/<repo>")
def browse(user, repo):
    jobs = os.path.join(this.root, user, repo)
    this.log.info("Browsing: %s" % jobs)
    body = """
        <style>{style}</style>
        <h1>Builds for {name}</h1>
        <div class="builds-body">{output}</div>
    """

    try:
        builds = os.listdir(jobs)
    except OSError:
        return "No builds for %s" % jobs

    builds = sorted(map(int, builds), key=int)

    return body.format(
        style=style,
        name=repo,
        output="\n".join("<a href=\"{0}/{1}\">{1}</a>".format(repo, build)
                         for build in builds))


def images(user, repo, build):

    job = "/".join([user, repo, build])

    results = ci.read_results(job)
    if not results:
        return "No results for job: %s" % job

    body = """
        <style>{style}</style>
        <h1>Images for {job}</h1>
        <div class="images-body">{output}</div>
    """

    images = results.keys()
    output = body.format(
        style=style,
{'fraction_non_alphanumeric': 0.16071428571428573, 'fraction_numerical': 0.03510551948051948, 'mean_word_length': 2.4565217391304346, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5855100', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1806, 'n_words': 422}