File: generate_skeletons.py

package info (click to toggle)
scikit-learn 0.20.2%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 51,036 kB
  • sloc: python: 108,171; ansic: 8,722; cpp: 5,651; makefile: 192; sh: 40
file content (38 lines) | stat: -rw-r--r-- 988 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Generate skeletons from the example code"""
import os

exercise_dir = os.path.dirname(__file__)
if exercise_dir == '':
    exercise_dir = '.'

skeleton_dir = os.path.abspath(os.path.join(exercise_dir, '..', 'skeletons'))
if not os.path.exists(skeleton_dir):
    os.makedirs(skeleton_dir)

solutions = os.listdir(exercise_dir)

for f in solutions:
    if not f.endswith('.py'):
        continue

    if f == os.path.basename(__file__):
        continue

    print("Generating skeleton for %s" % f)

    input_file = open(os.path.join(exercise_dir, f))
    output_file = open(os.path.join(skeleton_dir, f), 'w')

    in_exercise_region = False

    for line in input_file:
        linestrip = line.strip()
        if len(linestrip) == 0:
            in_exercise_region = False
        elif linestrip.startswith('# TASK:'):
            in_exercise_region = True

        if not in_exercise_region or linestrip.startswith('#'):
            output_file.write(line)

    output_file.close()