summaryrefslogtreecommitdiff
path: root/examples/oldconfig.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-05-27 18:34:50 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2018-05-27 18:45:33 +0200
commit58234d60b45ff5a8c04caf2cb5a18f77252cdbca (patch)
tree18d8ae6469df4191c4016673456ebccd32aa803b /examples/oldconfig.py
parent02f7330b450faf99716dbc7eefe3d6d2bdba0253 (diff)
oldconfig: Prepare for packaging
setuptools' 'entry_points' gives nice behavior on Windows. It requires that the module has an entry point function. Create one and move the command line argument handling to it. Piggyback KCONFIG_CONFIG support, and make the script executable (oversight).
Diffstat (limited to 'examples/oldconfig.py')
-rwxr-xr-x[-rw-r--r--]examples/oldconfig.py39
1 files changed, 26 insertions, 13 deletions
diff --git a/examples/oldconfig.py b/examples/oldconfig.py
index 5751fdc..1b58831 100644..100755
--- a/examples/oldconfig.py
+++ b/examples/oldconfig.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python
+
# Implements oldconfig-like functionality:
#
# 1. Load existing .config
@@ -293,6 +295,29 @@ def do_oldconfig_for_node(node):
if sym is not choice.user_selection and sym.visibility:
sym.set_value(0)
+# Entry point when run as an executable, split out so that setuptools'
+# 'entry_points' can be used. It produces a handy oldconfig.exe launcher on
+# Windows.
+def main():
+ if len(sys.argv) > 2:
+ sys.exit("usage: {} [Kconfig]".format(sys.argv[0]))
+
+ kconf = Kconfig("Kconfig" if len(sys.argv) < 2 else sys.argv[1])
+
+ config_filename = os.environ.get("KCONFIG_CONFIG")
+ if config_filename is None:
+ config_filename = ".config"
+
+ if not os.path.exists(config_filename):
+ sys.exit("{}: '{}' does not exist"
+ .format(sys.argv[0], config_filename))
+
+ kconf.load_config(config_filename)
+ do_oldconfig(kconf)
+ kconf.write_config(config_filename)
+
+ print("Configuration saved to '{}'".format(config_filename))
+
def do_oldconfig(kconf):
# An earlier symbol in the Kconfig files might depend on a later symbol and
# become visible if its value changes. This flag is set to True if the
@@ -316,16 +341,4 @@ def do_oldconfig_rec(node):
node = node.next
if __name__ == "__main__":
- if len(sys.argv) != 2:
- sys.exit("error: pass name of base Kconfig file as argument")
-
- if not os.path.exists(".config"):
- sys.exit("error: no existing .config")
-
- kconf = Kconfig(sys.argv[1])
-
- kconf.load_config(".config")
- do_oldconfig(kconf)
- kconf.write_config(".config")
-
- print("Configuration written to .config")
+ main()