Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/config/format
blob: b3f8aebbc9fb0c8e285ba3d26bc3c1945d53e405 (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
35
36
37
38
39
40
41
42
#!/usr/bin/env python

import os
import json
import fnmatch
from operator import itemgetter

config_dir = os.path.dirname(__file__)

def format_files(json_files, sort_by=None):
    for path in json_files:
        in_file = open(path, "rb")
        data = json.load(in_file)
        in_file.close()

        if sort_by is not None:
            data.sort(key=itemgetter(sort_by))

        out_file = open(path, "wb")
        json.dump(data, out_file, sort_keys=True, indent=4)
        out_file.write('\n')
        out_file.close()

def list_dir(dirname, exclude=[]):
    path = os.path.join(config_dir, dirname)

    json_files = []
    for filename in os.listdir(path):
        if filename in exclude:
            continue

        if fnmatch.fnmatch(filename, '*.json'):
            json_files.append(os.path.join(path, filename))

    return json_files

format_files([os.path.join(config_dir, "config.json"),
              os.path.join(config_dir, "deps", "index.json")])

format_files(list_dir("packages"))
format_files(list_dir("modules"))
format_files(list_dir("deps", exclude=["index.json"]), sort_by="name")