MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / check

Function check

tools/python-3.11.9-amd64/Tools/scripts/cleanfuture.py:78–131  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

76 check(arg)
77
78def check(file):
79 if os.path.isdir(file) and not os.path.islink(file):
80 if verbose:
81 print("listing directory", file)
82 names = os.listdir(file)
83 for name in names:
84 fullname = os.path.join(file, name)
85 if ((recurse and os.path.isdir(fullname) and
86 not os.path.islink(fullname))
87 or name.lower().endswith(".py")):
88 check(fullname)
89 return
90
91 if verbose:
92 print("checking", file, "...", end=' ')
93 try:
94 f = open(file)
95 except IOError as msg:
96 errprint("%r: I/O Error: %s" % (file, str(msg)))
97 return
98
99 with f:
100 ff = FutureFinder(f, file)
101 changed = ff.run()
102 if changed:
103 ff.gettherest()
104 if changed:
105 if verbose:
106 print("changed.")
107 if dryrun:
108 print("But this is a dry run, so leaving it alone.")
109 for s, e, line in changed:
110 print("%r lines %d-%d" % (file, s+1, e+1))
111 for i in range(s, e+1):
112 print(ff.lines[i], end=' ')
113 if line is None:
114 print("-- deleted")
115 else:
116 print("-- change to:")
117 print(line, end=' ')
118 if not dryrun:
119 bak = file + ".bak"
120 if os.path.exists(bak):
121 os.remove(bak)
122 os.rename(file, bak)
123 if verbose:
124 print("renamed", file, "to", bak)
125 with open(file, "w") as g:
126 ff.write(g)
127 if verbose:
128 print("wrote new", file)
129 else:
130 if verbose:
131 print("unchanged.")
132
133class FutureFinder:
134

Callers 1

mainFunction · 0.70

Calls 15

runMethod · 0.95
gettherestMethod · 0.95
writeMethod · 0.95
strFunction · 0.85
FutureFinderClass · 0.85
listdirMethod · 0.80
endswithMethod · 0.80
errprintFunction · 0.70
printFunction · 0.50
openFunction · 0.50
isdirMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected