MCPcopy Index your code
hub / github.com/ronreiter/interactive-tutorials / init_tutorials

Function init_tutorials

main.py:166–350  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

164
165
166def init_tutorials():
167 contributing_tutorials = wikify(open(os.path.join(os.path.dirname(__file__), "tutorials", "Contributing Tutorials.md")).read(), "en")
168
169 for domain in os.listdir(os.path.join(os.path.dirname(__file__), "tutorials")):
170 if domain.endswith(".md"):
171 continue
172
173 logging.info("loading data for domain: %s", domain)
174 tutorial_data[domain] = {}
175 if not os.path.isdir(os.path.join(os.path.dirname(__file__), "tutorials", domain)):
176 continue
177
178 if domain not in constants.DOMAIN_DATA:
179 logging.warning("skipping domain %s because no domain data exists" % domain)
180 continue
181
182 # Ensure English tutorials are preloaded
183 if "en" not in tutorial_data[domain]:
184 tutorial_data[domain]["en"] = {}
185
186 for language in os.listdir(os.path.join(os.path.dirname(__file__), "tutorials", domain)):
187 tutorial_data[domain][language] = {}
188
189 tutorials_path = os.path.join(os.path.dirname(__file__), "tutorials", domain, language)
190 if not os.path.isdir(tutorials_path):
191 continue
192
193 tutorials = os.listdir(tutorials_path)
194
195 # place the index file first
196 if "Welcome.md" in tutorials:
197 tutorials.remove("Welcome.md")
198 tutorials = ["Welcome.md"] + tutorials
199 for tutorial_file in tutorials:
200 if not tutorial_file.endswith(".md"):
201 continue
202
203 tutorial = tutorial_file[:-3]
204 logging.debug("loading tutorial %s" % tutorial)
205
206 if not tutorial in tutorial_data[domain][language]:
207 tutorial_data[domain][language][tutorial] = {}
208
209 tutorial_dict = tutorial_data[domain][language][tutorial]
210
211 tutorial_path = os.path.join(os.path.dirname(__file__), "tutorials", domain, language, tutorial_file)
212
213 tutorial_dict["text"] = open(tutorial_path).read().replace("\r\n", "\n")
214
215 if domain == "learnpython.org":
216 # Handle logic specific for `learnpython.org`
217 if "en" not in tutorial_data[domain]:
218 tutorial_data[domain]["en"] = {}
219
220 # Load translated titles from index.json for learnpython.org
221 index_file_path = os.path.join(tutorials_path, "index.json")
222 try:
223 with open(index_file_path, "r", encoding="utf-8") as f:

Callers 1

main.pyFile · 0.85

Calls 11

wikifyFunction · 0.85
untabFunction · 0.85
pageurlFunction · 0.85
removeMethod · 0.80
valuesMethod · 0.80
indexMethod · 0.80
loadMethod · 0.45
itemsMethod · 0.45
getMethod · 0.45
keysMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected