File tree 1 file changed +18
-2
lines changed
1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 4
4
import sys
5
5
import re
6
6
import requests
7
+ from subprocess import check_output
8
+ from builtins import input , open
7
9
8
10
PATTERN = (
9
11
"\[!\[View code\]\(https://www\.mbed\.com/embed/\?type=library\)\]"
10
12
"\((.*)\)"
11
13
)
12
14
13
- def main (path ):
15
+ def main (path = None ):
14
16
bad = False
17
+ interactive = False
18
+
19
+ if not path :
20
+ interactive = True
21
+
22
+ # Go to root to make paths easier
23
+ root = check_output (['git' , 'rev-parse' , '--show-toplevel' ]).strip ()
24
+ os .chdir (root )
25
+
26
+ # Ask for path in case user is unfamiliar with command line
27
+ path = input ('What directory should I check? ' )
15
28
16
29
for dir , dirs , files in os .walk (path ):
17
30
for file in files :
18
31
if not file .endswith ('.md' ):
19
32
continue
20
33
21
34
path = os .path .join (dir , file )
22
- with open (path ) as file :
35
+ with open (path , encoding = 'utf-8' ) as file :
23
36
for i , line in enumerate (file ):
24
37
for match in re .findall (PATTERN , line ):
25
38
if match .startswith ('https:' ):
@@ -45,6 +58,9 @@ def main(path):
45
58
dirs .remove (dir )
46
59
47
60
sys .stdout .write ('\n Done!\n ' )
61
+ if interactive :
62
+ input ('Hit any key to continue ' )
63
+
48
64
return 0 if not bad else 1
49
65
50
66
You can’t perform that action at this time.
0 commit comments