check_links_in_example_list Namespace Reference

Functions

def search_dead_links (doc_root_directory)
 

Variables

 narg = len(sys.argv)
 

Function Documentation

◆ search_dead_links()

def check_links_in_example_list.search_dead_links (   doc_root_directory)
4 def search_dead_links(doc_root_directory):
5  #Open the list of example codes
6  filename=doc_root_directory + "/example_code_list/html/index.html"
7  index_file=open(filename)
8  entire_file = index_file.read()
9 
10  #Pull out all urls
11  import re
12  urls = re.findall(r'[Hh][Rr][Ee][Ff] *= *[\'"]?([^\'" >]+)',entire_file)
13 
14  import string
15  #Now form the list of local urls
16  #Need to do some mangling to get the correct start, which
17  #may be specific to UNIX installations, but only we are going to be
18  #using this script so it should be OK
19  local_urls = []
20  for url in urls:
21  #Replace items in the header with the same string as those in .txt
22  new_url = string.replace(url,"../../../doc","../..")
23  if new_url.startswith('..'):
24  #Strip out anchors
25  if "#" in new_url:
26  local_urls.append(new_url[4:new_url.index("#")])
27  else:
28  local_urls.append(new_url[4:])
29 
30  #Now find all index.html files in the documentation tree
31  find_command = "find " + doc_root_directory + " -name \'index.html\'"
32  import subprocess
33  proc = subprocess.Popen(find_command, shell=True, stdin=subprocess.PIPE,\
34  stdout=subprocess.PIPE)
35  proc.wait()
36  local_files = proc.stdout.read()
37  new_local_files = local_files.split()
38 
39  #Need to remove the documentation root and replace it by a .
40  local_files = []
41  for url in new_local_files:
42  local_file = string.replace(url,doc_root_directory,"./")
43  local_files.append(local_file)
44 
45  new_local_files = local_files
46 
47  #Finally print out ones that don't match
48  print "Files not linked in example list file\n"
49 
50  for url in new_local_files:
51  if url not in local_urls:
52  print url
53 
54 
55  # for url,file in map(None,local_urls,local_files):
56  # print url,file
57 

Variable Documentation

◆ narg

check_links_in_example_list.narg = len(sys.argv)