From 32e50d8334dab0a1929d3c4ad4e38803fe2dfb35 Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Thu, 16 Nov 2017 00:19:08 +0000 Subject: [PATCH] Fix Makefile. Use Python 3 for scripts. --- Makefile | 27 +++++++++++++++++---------- bin/findtargets.py | 2 +- bin/makemkp.py | 32 ++++++++++++++++---------------- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index fbc4e80..b85aa19 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,29 @@ -ALL_FOLDERS := ${shell find ./src/ -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0} -#ALL_FOLDERS := $(dir $(wildcard ./src/*/.)) - -#ALL_TARGETS = $(ALL_FOLDERS:./src/%=build/%.mkp) +SRC_DIR := src/ +ALL_FOLDERS := $(shell find $(SRC_DIR) -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0) +ALL_MODULES := $(sort $(subst $(SRC_DIR),,$(ALL_FOLDERS))) ALL_TARGETS := ${shell bin/findtargets.py build/ $(ALL_FOLDERS)} all: $(ALL_TARGETS) - -$(ALL_TARGETS): $(ALL_FOLDERS) - @echo "Building $@ from $<" - bin/makemkp.py $< ./build/ - - # cleanup .PHONY: clean show_targets clean: -rm ./build/*.mkp +# debug + show_targets: + @echo $(ALL_FOLDERS) @echo $(ALL_TARGETS) + @echo $(ALL_MODULES) + +# setup + +define make-goal +${shell bin/findtargets.py build/ $(SRC_DIR)$1}: $(SRC_DIR)$1 + echo "Building $$@" + bin/makemkp.py $$< ./build/ +endef + +$(foreach mod,$(ALL_MODULES),$(eval $(call make-goal,$(mod)))) diff --git a/bin/findtargets.py b/bin/findtargets.py index bb0cc12..1fe1c15 100644 --- a/bin/findtargets.py +++ b/bin/findtargets.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- import configparser diff --git a/bin/makemkp.py b/bin/makemkp.py index fdcb117..d3b8f71 100644 --- a/bin/makemkp.py +++ b/bin/makemkp.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- import configparser @@ -45,7 +45,7 @@ cfg = configparser.ConfigParser() cfg.read(src_dir + "/baseinfo.ini") for key in cfg["info"]: - info[key] = cfg["info"][key].encode("utf-8") + info[key] = cfg["info"][key] dst_file = os.path.normpath(dst_dir + "/" + "{}-{}.mkp".format(info["name"], info["version"])) @@ -57,17 +57,17 @@ tar = tarfile.open(name=dst_file, mode="w:gz") # COLLECT FILES package_parts = [ (part, title, perm) for part, title, perm in [ - ( "checks", "Checks", 0644 ), - ( "notifications", "Notification scripts", 0755 ), - ( "inventory", "Inventory plugins", 0644 ), - ( "checkman", "Checks' man pages", 0644 ), - ( "agents", "Agents", 0755 ), - ( "web", "Multisite extensions", 0644 ), - ( "pnp-templates", "PNP4Nagios templates", 0644 ), - ( "doc", "Documentation files", 0644 ), - ( "bin", "Binaries", 0755 ), - ( "lib", "Libraries", 0644 ), - ( "mibs", "SNMP MIBs", 0644 ), + ( "checks", "Checks", 0o644 ), + ( "notifications", "Notification scripts", 0o755 ), + ( "inventory", "Inventory plugins", 0o644 ), + ( "checkman", "Checks' man pages", 0o644 ), + ( "agents", "Agents", 0o755 ), + ( "web", "Multisite extensions", 0o644 ), + ( "pnp-templates", "PNP4Nagios templates", 0o644 ), + ( "doc", "Documentation files", 0o644 ), + ( "bin", "Binaries", 0o755 ), + ( "lib", "Libraries", 0o644 ), + ( "mibs", "SNMP MIBs", 0o644 ), ]] def files_in_dir(dir, prefix = ""): @@ -94,7 +94,7 @@ def create_tar_info(filename, size): info.uid = 0 info.gid = 0 info.size = size - info.mode = 0644 + info.mode = 0o644 info.type = tarfile.REGTYPE info.name = filename return info @@ -116,8 +116,8 @@ info["num_files"] = num_files info_file = pprint.pformat(info) info_json = json.dumps(info) -tar_from_string(tar, "info", info_file) -tar_from_string(tar, "info.json", info_json) +tar_from_string(tar, "info", info_file.encode("utf-8")) +tar_from_string(tar, "info.json", info_json.encode("utf-8")) for part in info["files"]: