Project

General

Profile

Revision 6d0836d4

ID6d0836d4119d64a5cce4982e616ed66547f990ab
Parent a1219504
Child 98a7f961

Added by Alex Zirbel about 11 years ago

Sorted behaviors alphabetically in the generate script.

Lumps together all behaviors (both behaviors/ and test_behaviors/) and sorts them alphabetically by name, ignoring case, before assembling the output lists.

View differences:

scout/libscout/generate_behavior_lists.py
45 45

  
46 46
# Parse the src/behaviors and src/test_behaviors folders
47 47
cur_dir = os.getcwd()
48

  
49
all_paths = []
50
all_fnames = []
51
all_lasts = []
52

  
53
# Extract all the header files for behaviors we want
48 54
for path, dirname, fnames in os.walk('src'):
49 55
    if path == 'src/behaviors' or path == 'src/test_behaviors':
50 56
        path_parts = path.split('/')
57
        for f in fnames:
58
            if f.endswith('.h'):
59
                all_paths.append(path)
60
                all_fnames.append(f)
61
                all_lasts.append(path_parts[-1])
62

  
63
# Sort these headers into a good order and add them to our lists of paths/names
64
all_fnames, all_paths, all_lasts = (list(t) for t in zip(*sorted(zip(all_fnames, all_paths, all_lasts), key=lambda x: x[0].lower())))
51 65

  
52
        for f in sorted(fnames):
53
            # The pause_scout behavior needs to go first!
54
            if f.endswith('.h') and 'pause_scout' in f:
55
                full_paths.insert(0, os.path.join(cur_dir, path, f))
56
                last_paths.insert(0, os.path.join(path_parts[-1], f))
57
                base_names.insert(0, f.split('.')[0])
58
            # Everything else goes in alphabetical order
59
            elif f.endswith('.h'):
60
                full_paths.append(os.path.join(cur_dir, path, f))
61
                last_paths.append(os.path.join(path_parts[-1], f))
62
                base_names.append(f.split('.')[0])
66
for f, path, last in zip(all_fnames, all_paths, all_lasts):
67
    # Pause goes first
68
    if 'pause_scout' in f:
69
        full_paths.insert(0, os.path.join(cur_dir, path, f))
70
        last_paths.insert(0, os.path.join(last, f))
71
        base_names.insert(0, f.split('.')[0])
72
    # Everything else goes in alphabetical order
73
    else:
74
        full_paths.append(os.path.join(cur_dir, path, f))
75
        last_paths.append(os.path.join(last, f))
76
        base_names.append(f.split('.')[0])
63 77

  
64 78
# Now, a dictionary of codes to replace -> things to replace them with.
65 79
replacements = {FULL_PATH_CODE : full_paths,

Also available in: Unified diff