
import os

from travistooling import ROOT


def get_rfc_readmes(repo):
    rfcs_dir = os.path.join(repo, 'docs', 'rfcs')
    for root, _, filenames in os.walk(rfcs_dir):
        for f in filenames:
            if f == 'README.md':
                yield os.path.join(root, f)


print('*** Checking RFC headers')

for f in get_rfc_readmes(ROOT):
    print('*** Checking header for %s' % os.path.relpath(f, start=ROOT))
    filename = os.path.basename(os.path.dirname(f))
    number, name = filename.split('-', 1)

    contents = open(f).read()
    header = contents.splitlines()[:3]

    assert header[0].startswith('# RFC %03d: ' % int(number))
    assert header[1] == ''

    print(f, name)
    print(header)


import datetime as dt
import os

from travistooling import git, ROOT


def get_rfc_readmes(repo):
    rfcs_dir = os.path.join(repo, 'docs', 'rfcs')
    for root, _, filenames in os.walk(rfcs_dir):
        for f in filenames:
            if f == 'README.md':
                yield os.path.join(root, f)


if __name__ == '__main__':
    print('*** Checking RFC headers')

    for f in get_rfc_readmes(ROOT):
        print('*** Checking header for %s' % os.path.relpath(f, start=ROOT))
        filename = os.path.basename(os.path.dirname(f))
        number, name = filename.split('-', 1)

        contents = open(f).read()
        header = contents.splitlines()[:3]

        update_timestamp = git('log', '-1', '--format=%ct', f)
        last_updated = dt.datetime.fromtimestamp(int(update_timestamp))

        assert header[0].startswith('# RFC %03d: ' % int(number))
        assert header[1] == ''
        expected_date_str = '**Last updated: %s.**' % last_updated.strftime('%d %B %Y')
        assert header[2] == expected_date_str, (header[2], expected_date_str)

Check update dates in the RFC headers
Check update dates in the RFC headers

  
+ import datetime as dt
  import os
  
- from travistooling import ROOT
+ from travistooling import git, ROOT
  
  
  def get_rfc_readmes(repo):
      rfcs_dir = os.path.join(repo, 'docs', 'rfcs')
      for root, _, filenames in os.walk(rfcs_dir):
          for f in filenames:
              if f == 'README.md':
                  yield os.path.join(root, f)
  
  
+ if __name__ == '__main__':
- print('*** Checking RFC headers')
+     print('*** Checking RFC headers')
  
- for f in get_rfc_readmes(ROOT):
+     for f in get_rfc_readmes(ROOT):
-     print('*** Checking header for %s' % os.path.relpath(f, start=ROOT))
+         print('*** Checking header for %s' % os.path.relpath(f, start=ROOT))
-     filename = os.path.basename(os.path.dirname(f))
+         filename = os.path.basename(os.path.dirname(f))
-     number, name = filename.split('-', 1)
+         number, name = filename.split('-', 1)
  
-     contents = open(f).read()
+         contents = open(f).read()
-     header = contents.splitlines()[:3]
+         header = contents.splitlines()[:3]
  
-     assert header[0].startswith('# RFC %03d: ' % int(number))
-     assert header[1] == ''
+         update_timestamp = git('log', '-1', '--format=%ct', f)
+         last_updated = dt.datetime.fromtimestamp(int(update_timestamp))
  
-     print(f, name)
-     print(header)
+         assert header[0].startswith('# RFC %03d: ' % int(number))
+         assert header[1] == ''
+         expected_date_str = '**Last updated: %s.**' % last_updated.strftime('%d %B %Y')
+         assert header[2] == expected_date_str, (header[2], expected_date_str)
  
Check update dates in the RFC headers
## Code Before:

import os

from travistooling import ROOT


def get_rfc_readmes(repo):
    rfcs_dir = os.path.join(repo, 'docs', 'rfcs')
    for root, _, filenames in os.walk(rfcs_dir):
        for f in filenames:
            if f == 'README.md':
                yield os.path.join(root, f)


print('*** Checking RFC headers')

for f in get_rfc_readmes(ROOT):
    print('*** Checking header for %s' % os.path.relpath(f, start=ROOT))
    filename = os.path.basename(os.path.dirname(f))
    number, name = filename.split('-', 1)

    contents = open(f).read()
    header = contents.splitlines()[:3]

    assert header[0].startswith('# RFC %03d: ' % int(number))
    assert header[1] == ''

    print(f, name)
    print(header)

## Instruction:
Check update dates in the RFC headers
## Code After:

import datetime as dt
import os

from travistooling import git, ROOT


def get_rfc_readmes(repo):
    rfcs_dir = os.path.join(repo, 'docs', 'rfcs')
    for root, _, filenames in os.walk(rfcs_dir):
        for f in filenames:
            if f == 'README.md':
                yield os.path.join(root, f)


if __name__ == '__main__':
    print('*** Checking RFC headers')

    for f in get_rfc_readmes(ROOT):
        print('*** Checking header for %s' % os.path.relpath(f, start=ROOT))
        filename = os.path.basename(os.path.dirname(f))
        number, name = filename.split('-', 1)

        contents = open(f).read()
        header = contents.splitlines()[:3]

        update_timestamp = git('log', '-1', '--format=%ct', f)
        last_updated = dt.datetime.fromtimestamp(int(update_timestamp))

        assert header[0].startswith('# RFC %03d: ' % int(number))
        assert header[1] == ''
        expected_date_str = '**Last updated: %s.**' % last_updated.strftime('%d %B %Y')
        assert header[2] == expected_date_str, (header[2], expected_date_str)
