diff options
author | Nishanth Amuluru | 2011-01-11 22:41:51 +0530 |
---|---|---|
committer | Nishanth Amuluru | 2011-01-11 22:41:51 +0530 |
commit | b03203c8cb991c16ac8a3d74c8c4078182d0bb48 (patch) | |
tree | 7cf13b2deacbfaaec99edb431b83ddd5ea734a52 /parts/django/docs/_ext/applyxrefs.py | |
parent | 0c50203cd9eb94b819883c3110922e873f003138 (diff) | |
download | pytask-b03203c8cb991c16ac8a3d74c8c4078182d0bb48.tar.gz pytask-b03203c8cb991c16ac8a3d74c8c4078182d0bb48.tar.bz2 pytask-b03203c8cb991c16ac8a3d74c8c4078182d0bb48.zip |
removed all the buildout files
Diffstat (limited to 'parts/django/docs/_ext/applyxrefs.py')
-rw-r--r-- | parts/django/docs/_ext/applyxrefs.py | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/parts/django/docs/_ext/applyxrefs.py b/parts/django/docs/_ext/applyxrefs.py deleted file mode 100644 index 3809088..0000000 --- a/parts/django/docs/_ext/applyxrefs.py +++ /dev/null @@ -1,88 +0,0 @@ -"""Adds xref targets to the top of files.""" - -import sys -import os - -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: - f = open(fn, 'w') - except IOError: - print("Can't open %s for writing. Not touching it." % fn) - return - try: - f.writelines(lines) - except IOError: - print("Can't write to %s. Not touching it." % fn) - finally: - f.close() - -def has_target(fn): - try: - f = open(fn, 'r') - except IOError: - print("Can't open %s. Not touching it." % fn) - return (True, None) - readok = True - try: - lines = f.readlines() - except IOError: - print("Can't read %s. Not touching it." % fn) - readok = False - finally: - f.close() - if not readok: - 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())
\ No newline at end of file |