MCPcopy Create free account
hub / github.com/davidblewett/rure-python / main

Function main

regex/scripts/scrape_crates_io.py:54–90  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

52
53
54def main():
55 args = argparser().parse_args()
56 out = open(os.path.abspath(args.output_file), "w")
57 out.write(PRELUDE.format(date=str(datetime.datetime.now())))
58 if args.crates_index:
59 args.crates_index = os.path.abspath(args.crates_index)
60
61 # enter our scratch directory
62 old_dir = os.getcwd()
63 work_dir = tempfile.mkdtemp(prefix="scrape-crates-io")
64 os.chdir(work_dir)
65
66 crates_index = (args.crates_index
67 if os.path.join(old_dir, args.crates_index)
68 else download_crates_index())
69
70 for (name, vers) in iter_crates(crates_index):
71 if name in KNOWN_UNMAINTAINED_CRATES:
72 continue
73
74 with Crate(work_dir, name, vers) as c:
75 i = 0
76 for line in c.iter_lines():
77 for r in RE_REGEX.findall(line):
78 print((name, vers, r))
79 if len(r) >= 2 and r[-2] == "\\":
80 continue
81 out.write("// {}-{}: {}\n".format(name, vers, r))
82 out.write("consistent!({}_{}, {});\n\n".format(
83 name.replace("-", "_"), i, r))
84 out.flush()
85 i += 1
86
87 # Leave the scratch directory
88 os.chdir(old_dir)
89 shutil.rmtree(work_dir)
90 out.close()
91
92
93def download_crates_index():

Callers 1

Calls 7

argparserFunction · 0.85
download_crates_indexFunction · 0.85
iter_cratesFunction · 0.85
CrateClass · 0.85
iter_linesMethod · 0.80
findallMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected