From 9df864239ea8e66d9385a66a1b5e20cb0f534217 Mon Sep 17 00:00:00 2001 From: Daniel Narvaez Date: Sat, 12 Jan 2013 03:45:29 +0000 Subject: Cleanup config generation --- (limited to 'config/format') diff --git a/config/format b/config/format new file mode 100755 index 0000000..b3f8aeb --- /dev/null +++ b/config/format @@ -0,0 +1,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") -- cgit v0.9.1