This file is indexed.

/usr/share/pyshared/pytools/stopwatch.py is in python-pytools 2013.5.7-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from __future__ import division
import time
import pytools




class StopWatch:
    def __init__(self):
        self.Elapsed = 0.
        self.LastStart = None

    def start(self):
        assert self.LastStart is None
        self.LastStart = time.time()
        return self

    def stop(self):
        assert self.LastStart is not None
        self.Elapsed += time.time() - self.LastStart
        self.LastStart = None
        return self

    def elapsed(self):
        if self.LastStart:
            return time.time() - self.LastStart + self.Elapsed
        else:
            return self.Elapsed


class Job:
    def __init__(self, name):
        self.Name = name
        self.StopWatch = StopWatch().start()
        if self.is_visible():
            print "%s..." % name

    def done(self):
        elapsed = self.StopWatch.elapsed()
        JOB_TIMES[self.Name] += elapsed
        if self.is_visible():
            print " " * (len(self.Name) + 2), elapsed, "seconds"
  
    def is_visible(self):
        if PRINT_JOBS.get():
            return not self.Name in HIDDEN_JOBS
        else:
            return self.Name in VISIBLE_JOBS




class EtaEstimator:
    def __init__(self, total_steps):
        self.stopwatch = StopWatch().start()
        self.total_steps = total_steps
        assert total_steps > 0

    def estimate(self, done):
        fraction_done = done/self.total_steps
        time_spent = self.stopwatch.elapsed()
        if fraction_done > 1e-5:
            return time_spent/fraction_done-time_spent
        else:
            return None




def print_job_summary():
    for key in JOB_TIMES:
        print key, " " * (50-len(key)), JOB_TIMES[key]






HIDDEN_JOBS = []
VISIBLE_JOBS = []
JOB_TIMES = pytools.DictionaryWithDefault(lambda x: 0)
PRINT_JOBS = pytools.Reference(True)