summaryrefslogtreecommitdiff
path: root/tko/utils.py
blob: 8fc3711f9494e3422783976ec6a28cf6108241d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os, sys, datetime


_debug_logger = sys.stderr
def dprint(msg):
    print >> _debug_logger, msg


def redirect_parser_debugging(ostream):
    global _debug_logger
    _debug_logger = ostream


def get_timestamp(mapping, field):
    val = mapping.get(field, None)
    if val is not None:
        val = datetime.datetime.fromtimestamp(int(val))
    return val


def find_toplevel_job_dir(start_dir):
    """ Starting from start_dir and moving upwards, find the top-level
    of the job results dir. We can't just assume that it corresponds to
    the actual job.dir, because job.dir may just be a subdir of the "real"
    job dir that autoserv was launched with. Returns None if it can't find
    a top-level dir. """
    job_dir = start_dir
    while not os.path.exists(os.path.join(job_dir, ".autoserv_execute")):
        if job_dir == "/":
            return None
        job_dir = os.path.dirname(job_dir)
    return job_dir