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 --- diff --git a/Makefile b/Makefile index 9545d1d..2a28311 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,45 @@ COMMANDS_DIR=$(CURDIR)/commands -TOOLS_DIR=$(CURDIR)/tools TIME=time -f "\n= Time =\n\nreal\t%e\nuser\t%U\nsys\t%S\n" -.PHONY: all +.PHONY: build all: build -include Makefile.config -include Makefile.commands +check-system: + @$(COMMANDS_DIR)/check-system $(ARGS) + +pull: + @$(COMMANDS_DIR)/pull $(ARGS) + +build: + @$(TIME) $(COMMANDS_DIR)/build $(ARGS) + +run: + @$(COMMANDS_DIR)/run + +check: + @$(COMMANDS_DIR)/check + +shell: + @$(COMMANDS_DIR)/shell + +bug-report: + @$(COMMANDS_DIR)/bug-report + +clean: + @$(COMMANDS_DIR)/clean + +distribute: + @$(COMMANDS_DIR)/distribute + +snapshot: + @$(COMMANDS_DIR)/snapshot + +build-%: + @$(COMMANDS_DIR)/build $* + +pull-%: + @$(COMMANDS_DIR)/pull $* + +check-%: + @$(COMMANDS_DIR)/check $* diff --git a/Makefile.commands b/Makefile.commands deleted file mode 100644 index 6662a7a..0000000 --- a/Makefile.commands +++ /dev/null @@ -1,43 +0,0 @@ -.PHONY: auto-install check-system build run test shell bug-report clean - -auto-install: - @$(COMMANDS_DIR)/auto-install - -check-system: - @$(COMMANDS_DIR)/check-system $(ARGS) - -pull: - @$(COMMANDS_DIR)/pull $(ARGS) - -build: - @$(TIME) $(COMMANDS_DIR)/build $(ARGS) - -run: - @$(COMMANDS_DIR)/run - -check: - @$(COMMANDS_DIR)/check - -shell: - @$(COMMANDS_DIR)/shell - -bug-report: - @$(COMMANDS_DIR)/bug-report - -clean: - @$(COMMANDS_DIR)/clean - -distribute: - @$(COMMANDS_DIR)/distribute - -snapshot: - @$(COMMANDS_DIR)/snapshot - -build-%: - @$(COMMANDS_DIR)/build $* - -pull-%: - @$(COMMANDS_DIR)/pull $* - -check-%: - @$(COMMANDS_DIR)/check $* diff --git a/Makefile.config b/Makefile.config deleted file mode 100644 index 14ddc61..0000000 --- a/Makefile.config +++ /dev/null @@ -1,30 +0,0 @@ -JSON_FORMAT=$(TOOLS_DIR)/json-format - -CONFIG_DEPS_DIR=config/deps - -CONFIG_DEPS= \ - $(CONFIG_DEPS_DIR)/prerequisites.json \ - $(CONFIG_DEPS_DIR)/sugar-build.json \ - $(CONFIG_DEPS_DIR)/sugar-buildtime.json \ - $(CONFIG_DEPS_DIR)/sugar-buildtime.json \ - $(CONFIG_DEPS_DIR)/sugar-runtime.json \ - $(CONFIG_DEPS_DIR)/system.json - -CONFIG_MODULES_DIR=config/modules - -CONFIG_MODULES= \ - $(CONFIG_MODULES_DIR)/activities.json \ - $(CONFIG_MODULES_DIR)/sugar.json \ - $(CONFIG_MODULES_DIR)/system.json - -CONFIG_PACKAGES_DIR=config/packages - -CONFIG_PACKAGES= \ - $(CONFIG_PACKAGES_DIR)/basesystem.json \ - $(CONFIG_PACKAGES_DIR)/deps.json - -CONFIG_MAIN=config/config.json - -config-format: - @$(JSON_FORMAT) $(CONFIG_MODULES) $(CONFIG_PACKAGES) $(CONFIG_MAIN) - @$(JSON_FORMAT) --sort-by name $(CONFIG_DEPS) diff --git a/config/deps/index.json b/config/deps/index.json index feb7142..d54126e 100644 --- a/config/deps/index.json +++ b/config/deps/index.json @@ -1,4 +1,6 @@ -["system.json", - "sugar-build.json", - "sugar-buildtime.json", - "sugar-runtime.json"] +[ + "system.json", + "sugar-build.json", + "sugar-buildtime.json", + "sugar-runtime.json" +] 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") diff --git a/config/modules/index.json b/config/modules/index.json index 5317772..57611df 100644 --- a/config/modules/index.json +++ b/config/modules/index.json @@ -1,3 +1,5 @@ -["system.json", - "sugar.json", - "activities.json"] +[ + "system.json", + "sugar.json", + "activities.json" +] diff --git a/config/packages/basesystem.json b/config/packages/basesystem.json index 8d1134c..7b5c082 100644 --- a/config/packages/basesystem.json +++ b/config/packages/basesystem.json @@ -58,7 +58,7 @@ ], "fedora": [ "openssh-server", - "avahi", + "avahi", "kernel", "kernel-PAE", "kernel-modules-extra", diff --git a/config/packages/index.json b/config/packages/index.json index bab6e79..59489f5 100644 --- a/config/packages/index.json +++ b/config/packages/index.json @@ -1,2 +1,4 @@ -["basesystem.json", - "deps.json"] +[ + "basesystem.json", + "deps.json" +] diff --git a/tools/json-format b/tools/json-format deleted file mode 100755 index dde3cb0..0000000 --- a/tools/json-format +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python - -import argparse -import json -from operator import itemgetter - -parser = argparse.ArgumentParser() -parser.add_argument("paths", nargs="+", help="path to the json file") -parser.add_argument("--sort-by", help="dictionary key to sort by") -args = parser.parse_args() - -for path in args.paths: - in_file = open(path, "rb") - data = json.load(in_file) - in_file.close() - - if args.sort_by is not None: - data.sort(key=itemgetter(args.sort_by)) - - out_file = open(path, "wb") - json.dump(data, out_file, sort_keys=True, indent=4) - out_file.write('\n') - out_file.close() -- cgit v0.9.1