|
16 | 16 | BUNDLE_TAG = "latest_bundle_tag.json"
|
17 | 17 |
|
18 | 18 | LEARN_GUIDE_REPO = os.environ.get(
|
19 |
| - "LEARN_GUIDE_REPO", "../../Adafruit_Learning_System_Guides/" |
| 19 | + "LEARN_GUIDE_REPO", "../Adafruit_Learning_System_Guides/" |
20 | 20 | )
|
21 | 21 |
|
22 | 22 | SHOWN_FILETYPES = ["py", "mpy", "bmp", "pcf", "bdf", "wav", "mp3", "json", "txt"]
|
@@ -140,28 +140,28 @@ def get_libs_for_project(project_name):
|
140 | 140 | return found_libs
|
141 | 141 |
|
142 | 142 |
|
143 |
| -def get_learn_guide_projects(): |
144 |
| - """Get the list of all folders in the learn guide""" |
145 |
| - return os.listdir(LEARN_GUIDE_REPO) |
146 |
| - |
147 |
| - |
148 | 143 | def get_learn_guide_cp_projects():
|
149 | 144 | """Get the list of all circuitpython projects, according to some heuristics"""
|
150 |
| - cp_projects = [] |
151 |
| - |
152 |
| - def has_py_file(location): |
153 |
| - dir_files = os.listdir(location) |
154 |
| - for file in dir_files: |
155 |
| - if file.endswith(".py"): |
156 |
| - return ".circuitpython.skip" not in dir_files |
157 |
| - return False |
158 |
| - |
159 |
| - all_projects = get_learn_guide_projects() |
160 |
| - for project in all_projects: |
161 |
| - project_dir = "{}/{}/".format(LEARN_GUIDE_REPO, project) |
162 |
| - try: |
163 |
| - if has_py_file(project_dir): |
164 |
| - cp_projects.append(project) |
165 |
| - except NotADirectoryError: |
166 |
| - pass |
167 |
| - return cp_projects |
| 145 | + for dirpath, dirnames, filenames in os.walk(LEARN_GUIDE_REPO): |
| 146 | + # The top-level needs special treatment |
| 147 | + if dirpath == LEARN_GUIDE_REPO: |
| 148 | + dirnames.remove(".git") |
| 149 | + continue |
| 150 | + # Skip this folder and all subfolders |
| 151 | + if ".circuitpython.skip" in filenames: |
| 152 | + del dirnames[:] |
| 153 | + continue |
| 154 | + # Skip files in this folder, but handle sub-folders |
| 155 | + if ".circuitpython.skip-here" in filenames: |
| 156 | + continue |
| 157 | + # Do not reurse, but handle files in this folder |
| 158 | + if ".circuitpython.skip-sub" in filenames: |
| 159 | + del dirnames[:] |
| 160 | + |
| 161 | + if any(f for f in filenames if f.endswith(".py")): |
| 162 | + yield os.path.relpath(dirpath, LEARN_GUIDE_REPO) |
| 163 | + |
| 164 | + |
| 165 | +if __name__ == "__main__": |
| 166 | + for p in get_learn_guide_cp_projects(): |
| 167 | + print("PROJECT", p) |
0 commit comments