<commit_before>#!/usr/bin/env python

import datetime
import logging
import os
import os.path
import subprocess
import time

import tornado.template


def timestamp():
    # remove microseconds, use a space
    s = datetime.datetime.utcnow().isoformat(' ')
    return s[0:19]

class CheckoutGit(object):
    """
    does a pull or clone from a git repo as needed
    """

    def __init__(self, url):
        self.url = url

    def run(self, name):
        if os.path.exists(name):
            cwd = name
            cmd = ['git', 'pull']
            logging.info("{0}: git pull (from {1})".format(name, self.url))
        else:
            cwd = None
            cmd = ['git', 'clone', self.url, name, '--depth', '1']
            logging.info("{0}: git clone {1} {2}".format(name, self.url, name))

        p = subprocess.Popen(cmd,
                             cwd=cwd,
                             stdout = subprocess.PIPE,
                             stderr = subprocess.STDOUT)

        (sout,serr) = p.communicate()
        return (sout,serr,p.returncode)

class ExecuteShell(object):
    """
    Executes a bash script
    """
    def __init__(self, script):
        self.script = script

    def run(self, name):
        p = subprocess.Popen(['/bin/bash', '-v', '-c', self.script],
                             cwd=name,
                             stdout = subprocess.PIPE,
                             stderr = subprocess.STDOUT,
                             shell=False)
        (sout, serr) = p.communicate()

        return (sout, serr, p.returncode)

class PublishConsole(object):
    """
    Publish console ouput
    """

    def __init__(self, console):
        self.data = console

    def run(self, rootdir, name):
        fname = os.path.join(rootdir, name + '.txt')
        logging.debug("Writing console to {0}".format(fname))
        with open(fname, 'w') as fd:
            fd.write(self.data)

class PublishArtifact(object):
    """
    Publish console ouput
    """

    def __init__(self, artifact):
        self.data = artifact

    def run(self, pubdir, name):
        destdir = os.path.join(os.path.join(pubdir, name));
        if not os.exists(destdir):
            os.makedirs(name)

        subprocess.call(['cp', '-r', self.artifact, destdir])

class PublishStatus(object):
    """
    Publish project status
    """
    def __init__(self, templatepath):
        self.loader = tornado.template.Loader(".")

    def run(self, pubdir, tests):
        status = []
        for t in tests:
            status.append(t['status'])

        fname = os.path.join(pubdir, 'index.html')
        logging.debug("Writing status to {0}".format(fname))

        with open(fname, 'w') as fd:
            fd.write(self.loader.load('status.html').generate(status = status))

def cicada(workspace, pubspace, tests):<commit_msg>attempt at publishing gcov<commit_after>#!/usr/bin/env python

import datetime
import logging
import os
import os.path
import subprocess
import time

import tornado.template


def timestamp():
    # remove microseconds, use a space
    s = datetime.datetime.utcnow().isoformat(' ')
    return s[0:19]

class CheckoutGit(object):
    """
    does a pull or clone from a git repo as needed
    """

    def __init__(self, url):
        self.url = url

    def run(self, name):
        if os.path.exists(name):
            cwd = name
            cmd = ['git', 'pull']
            logging.info("{0}: git pull (from {1})".format(name, self.url))
        else:
            cwd = None
            cmd = ['git', 'clone', self.url, name, '--depth', '1']
            logging.info("{0}: git clone {1} {2}".format(name, self.url, name))

        p = subprocess.Popen(cmd,
                             cwd=cwd,
                             stdout = subprocess.PIPE,
                             stderr = subprocess.STDOUT)

        (sout,serr) = p.communicate()
        return (sout,serr,p.returncode)

class ExecuteShell(object):
    """
    Executes a bash script
    """
    def __init__(self, script):
        self.script = script

    def run(self, name):
        p = subprocess.Popen(['/bin/bash', '-v', '-c', self.script],
                             cwd=name,
                             stdout = subprocess.PIPE,
                             stderr = subprocess.STDOUT,
                             shell=False)
        (sout, serr) = p.communicate()

        return (sout, serr, p.returncode)

class PublishConsole(object):
    """
    Publish console ouput
    """

    def __init__(self, console):
        self.data = console

    def run(self, rootdir, name):
        fname = os.path.join(rootdir, name + '.txt')
        logging.debug("Writing console to {0}".format(fname))
        with open(fname, 'w') as fd:
            fd.write(self.data)

class PublishArtifact(object):
    """
    Publish console ouput
    """

    def __init__(self, artifact):
        self.data = artifact

    def run(self, pubdir, name):
        destdir = os.path.join(os.path.join(pubdir, name));
        if not os.path.exists(destdir):
            os.makedirs(name)

        subprocess.call(['cp', '-r', self.artifact, destdir])

class PublishStatus(object):
    """
    Publish project status
    """
    def __init__(self, templatepath):
        self.loader = tornado.template.Loader(".")

    def run(self, pubdir, tests):
        status = []
        for t in tests:
            status.append(t['status'])

        fname = os.path.join(pubdir, 'index.html')
        logging.debug("Writing status to {0}".format(fname))

        with open(fname, 'w') as fd:
            fd.write(self.loader.load('status.html').generate(status = status))

def cicada(workspace, pubspace, tests):
{'fraction_non_alphanumeric': 0.1354714335786891, 'fraction_numerical': 0.00385559060637925, 'mean_word_length': 1.940236991241628, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2079264', 'n_tokens_mistral': 1776, 'n_tokens_neox': 1724, 'n_words': 426}