summaryrefslogtreecommitdiff
path: root/scripts/cleanup-patterns.py
blob: ab1e5ecdcd06f7c8c1225e20e7d414760fcfe813 (plain)
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
#!/usr/bin/python

import yaml
import sys, os
import optparse


def sort_pkgs(patterns_dir='patterns'):
    for f in os.listdir(patterns_dir):
        if not f.endswith('.yaml'):
            continue
        print f
        stream = file("%s/%s" %(patterns_dir,f), 'r+')
        y = yaml.load(stream)
        if y.has_key('Packages'):
            y['Packages'] = sorted(y['Packages'])
            yf = yaml.dump(y, default_flow_style=False)
            stream.seek(0)
            stream.write(yf)
        stream.close()

        

if __name__ == '__main__':
    parser = optparse.OptionParser()

    parser.add_option("-s", "--sort", action="store_true", default=False,
                    help="sort packages")
        
    (options, args) = parser.parse_args()

    if options.sort:
        sort_pkgs()