1 """Adds xref targets to the top of files."""
13 if fn
.endswith('.txt'):
15 return '_' + fn
.lstrip('./').replace('/', '-')
17 def process_file(fn
, lines
):
19 lines
.insert(0, '.. %s:\n' % target_name(fn
))
23 print("Can't open %s for writing. Not touching it." % fn
)
28 print("Can't write to %s. Not touching it." % fn
)
36 print("Can't open %s. Not touching it." % fn
)
42 print("Can't read %s. Not touching it." % fn
)
51 print("Not touching empty file %s." % fn
)
53 if lines
[0].startswith('.. _'):
66 for (dirpath
, dirnames
, filenames
) in os
.walk(root
):
67 files
.extend([(dirpath
, f
) for f
in filenames
])
69 files
= [os
.path
.join(p
, fn
) for p
, fn
in files
if fn
.endswith('.txt')]
74 print("Skipping blacklisted file %s." % fn
)
77 target_found
, lines
= has_target(fn
)
80 print '%s: %s' % (fn
, lines
[0]),
82 print "Adding xref to %s" % fn
83 process_file(fn
, lines
)
85 print "Skipping %s: already has a xref" % fn
87 if __name__
== '__main__':