~dkuhlman/python-training-materials/Materials

« back to all changes in this revision

Viewing changes to scan_txt_html_dates.py

  • Committer: Dave Kuhlman
  • Date: 2015-10-03 18:25:17 UTC
  • mfrom: (35.1.5 Materials)
  • Revision ID: dkuhlman@davekuhlman.org-20151003182517-b2m7eltjdapw46zh
Review for Cisco.  Merged checkpoint 10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
"""
 
4
synopsis:
 
5
    Scan the current directory and subdirectories for .txt and .html files.
 
6
    Report .html files that are missing or out-of-date.
 
7
usage:
 
8
    python scan_txt_html_dates.py
 
9
"""
 
10
 
 
11
 
 
12
import os
 
13
 
 
14
 
 
15
def scan():
 
16
    for dirname, _, filenames in os.walk('.'):
 
17
        for filename in filenames:
 
18
            parts = os.path.splitext(filename)
 
19
            textname = os.path.join(dirname, filename)
 
20
            htmlname = os.path.join(dirname, parts[0] + '.html')
 
21
            if len(parts) == 2 and parts[1] == '.txt':
 
22
                if os.path.exists(htmlname):
 
23
                    textdate = os.path.getmtime(textname)
 
24
                    htmldate = os.path.getmtime(htmlname)
 
25
                    if textdate > htmldate:
 
26
                        print 'out of date: {}'.format(htmlname)
 
27
                else:
 
28
                    print 'missing: {}'.format(htmlname)
 
29
 
 
30
 
 
31
def main():
 
32
    scan()
 
33
 
 
34
 
 
35
if __name__ == '__main__':
 
36
    #import pdb; pdb.set_trace()
 
37
    main()