Begin versioning! (better late than never)
[pygrader.git] / pygrader / todo.py
1 # Copyright
2
3 """List grading that still needs to be done.
4 """
5
6 import os as _os
7 import os.path as _os_path
8
9
10 def mtime(path, walk_directories=True):
11     if walk_directories and _os.path.isdir(path):
12         time = mtime(path, walk_directories=False)
13         for dirpath,dirnames,filenames in _os.walk(path):
14             for filename in filenames:
15                 t = mtime(_os_path.join(dirpath, filename))
16                 time = max(time, t)
17         return time
18     stat = _os.stat(path)
19     return stat.st_mtime
20
21 def newer(a, b):
22     """Return ``True`` if ``a`` is newer than ``b``.
23     """
24     return mtime(a) > mtime(b)
25
26 def todo(basedir, source, target):
27     """Yield ``source``\s in ``basedir`` with old/missing ``target``\s.
28     """
29     for dirpath,dirnames,filenames in _os.walk(basedir):
30         names = dirnames + filenames
31         if source in names:
32             s = _os_path.join(dirpath, source)
33             t = _os_path.join(dirpath, target)
34             if target in names:
35                 if newer(s, t):
36                     yield(s)
37             else:
38                 yield s
39
40 def print_todo(basedir, source, target):
41     """Print ``source``\s in ``basedir`` with old/missing ``target``\s.
42     """
43     for path in sorted(todo(basedir, source, target)):
44         print(path)