@@ -13,23 +13,24 @@ def main():
1313 os .chdir (SOURCE_ROOT )
1414
1515 filepaths = []
16+ totalDirs = 0
1617 try :
1718 for root , dirs , files in os .walk (DOCS_DIR ):
18- for file in files :
19- if file .endswith ('.md' ):
20- filepaths .append (os .path .join (root , file ))
19+ totalDirs += len (dirs )
20+ for f in files :
21+ if f .endswith ('.md' ):
22+ filepaths .append (os .path .join (root , f ))
2123 except KeyboardInterrupt :
2224 print ('Keyboard interruption. Please try again.' )
2325 return
24- except :
25- print ('Error: Could not read files in directories.' )
26- return
2726
2827 totalBrokenLinks = 0
2928 for path in filepaths :
3029 totalBrokenLinks += getBrokenLinks (path )
3130
32- print ('Parsed through ' + str (len (filepaths )) + ' files.' )
31+ print ('Parsed through ' + str (len (filepaths )) +
32+ ' files within docs directory and its ' +
33+ str (totalDirs ) + ' subdirectories.' )
3334 print ('Found ' + str (totalBrokenLinks ) + ' broken relative links.' )
3435
3536
@@ -38,14 +39,12 @@ def getBrokenLinks(filepath):
3839 brokenLinks = []
3940
4041 try :
41- file = open (filepath , 'r' )
42- lines = file .readlines ()
42+ f = open (filepath , 'r' )
43+ lines = f .readlines ()
4344 except KeyboardInterrupt :
4445 print ('Keyboard interruption whle parsing. Please try again.' )
45- except :
46- print ('Error: Could not open file ' , filepath )
4746 finally :
48- file .close ()
47+ f .close ()
4948
5049 regexLink = re .compile ('\[(.*?)\]\((?P<links>(.*?))\)' )
5150 links = []
@@ -60,7 +59,7 @@ def getBrokenLinks(filepath):
6059 sections = link .split ('#' )
6160 if len (sections ) > 1 :
6261 if str (link ).startswith ('#' ):
63- if not checkSections (sections , link , lines , filepath ):
62+ if not checkSections (sections , lines ):
6463 brokenLinks .append (link )
6564 else :
6665 tempFile = os .path .join (currentDir , sections [0 ])
@@ -70,12 +69,10 @@ def getBrokenLinks(filepath):
7069 newLines = newFile .readlines ()
7170 except KeyboardInterrupt :
7271 print ('Keyboard interruption whle parsing. Please try again.' )
73- except :
74- print ('Error: Could not open file ' , filepath )
7572 finally :
7673 newFile .close ()
7774
78- if not checkSections (sections , link , newLines , tempFile ):
75+ if not checkSections (sections , newLines ):
7976 brokenLinks .append (link )
8077 else :
8178 brokenLinks .append (link )
@@ -88,7 +85,7 @@ def getBrokenLinks(filepath):
8885 return len (brokenLinks )
8986
9087
91- def checkSections (sections , link , lines , path ):
88+ def checkSections (sections , lines ):
9289 sectionHeader = sections [1 ].replace ('-' , '' )
9390 regexSectionTitle = re .compile ('# (?P<header>.*)' )
9491 for line in lines :
0 commit comments