diff options
| author | Tim Graham <timograham@gmail.com> | 2016-01-13 11:49:42 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-01-13 11:49:42 -0500 |
| commit | 8d5d472c6ddf42bacff72e533e7cfa08593fcd1a (patch) | |
| tree | 5c10969d3ed3e697c79921735a2a16f8f48157ca /docs | |
| parent | 03306a187ec3bb5e2592728a900d4a41185f9e30 (diff) | |
Removed unused docs/_ext/applyxrefs.py
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/_ext/applyxrefs.py | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/docs/_ext/applyxrefs.py b/docs/_ext/applyxrefs.py deleted file mode 100644 index ecc67bc877..0000000000 --- a/docs/_ext/applyxrefs.py +++ /dev/null @@ -1,77 +0,0 @@ -"""Adds xref targets to the top of files.""" - -import os -import sys - -testing = False - -DONT_TOUCH = ( - './index.txt', -) - - -def target_name(fn): - if fn.endswith('.txt'): - fn = fn[:-4] - return '_' + fn.lstrip('./').replace('/', '-') - - -def process_file(fn, lines): - lines.insert(0, '\n') - lines.insert(0, '.. %s:\n' % target_name(fn)) - try: - with open(fn, 'w') as fp: - fp.writelines(lines) - except IOError: - print("Can't open %s for writing. Not touching it." % fn) - - -def has_target(fn): - try: - with open(fn, 'r') as fp: - lines = fp.readlines() - except IOError: - print("Can't open or read %s. Not touching it." % fn) - return (True, None) - - # print fn, len(lines) - if len(lines) < 1: - print("Not touching empty file %s." % fn) - return (True, None) - if lines[0].startswith('.. _'): - return (True, None) - return (False, lines) - - -def main(argv=None): - if argv is None: - argv = sys.argv - - if len(argv) == 1: - argv.extend('.') - - files = [] - for root in argv[1:]: - for (dirpath, dirnames, filenames) in os.walk(root): - files.extend((dirpath, f) for f in filenames) - files.sort() - files = [os.path.join(p, fn) for p, fn in files if fn.endswith('.txt')] - # print files - - for fn in files: - if fn in DONT_TOUCH: - print("Skipping blacklisted file %s." % fn) - continue - - target_found, lines = has_target(fn) - if not target_found: - if testing: - print('%s: %s' % (fn, lines[0])) - else: - print("Adding xref to %s" % fn) - process_file(fn, lines) - else: - print("Skipping %s: already has a xref" % fn) - -if __name__ == '__main__': - sys.exit(main()) |
