]> granicus.if.org Git - esp-idf/commitdiff
confgen: base config creation on output type args
authorRenz Christian Bagaporo <renz@espressif.com>
Tue, 15 Jan 2019 15:06:50 +0000 (23:06 +0800)
committerRenz Christian Bagaporo <renz@espressif.com>
Wed, 16 Jan 2019 00:16:09 +0000 (08:16 +0800)
tools/kconfig_new/confgen.py

index 1d8989495e010af97a3e1baee794efda9c75bd78..8a590bb3faf32d07cc9c83cab6a5789d4fa04a63 100755 (executable)
@@ -52,10 +52,6 @@ def main():
                         default=[],
                         action='append')
 
-    parser.add_argument('--create-config-if-missing',
-                        help='If set, a new config file will be saved if the old one is not found',
-                        action='store_true')
-
     parser.add_argument('--kconfig',
                         help='KConfig file with config item definitions',
                         required=True)
@@ -95,26 +91,22 @@ def main():
                 raise RuntimeError("Defaults file not found: %s" % name)
             config.load_config(name, replace=False)
 
-    if args.config is not None:
-        if os.path.exists(args.config):
-            config.load_config(args.config)
-        elif args.create_config_if_missing:
-            print("Creating config file %s..." % args.config)
-            config.write_config(args.config)
-        elif args.config is None:
-            raise RuntimeError("Config file not found: %s" % args.config)
-
-        for output_type, filename in args.output:
-            temp_file = tempfile.mktemp(prefix="confgen_tmp")
+    # If config file previously exists, load it
+    if args.config and os.path.exists(args.config):
+        config.load_config(args.config, replace=False)
+
+    # Output the files specified in the arguments
+    for output_type, filename in args.output:
+        temp_file = tempfile.mktemp(prefix="confgen_tmp")
+        try:
+            output_function = OUTPUT_FORMATS[output_type]
+            output_function(config, temp_file)
+            update_if_changed(temp_file, filename)
+        finally:
             try:
-                output_function = OUTPUT_FORMATS[output_type]
-                output_function(config, temp_file)
-                update_if_changed(temp_file, filename)
-            finally:
-                try:
-                    os.remove(temp_file)
-                except OSError:
-                    pass
+                os.remove(temp_file)
+            except OSError:
+                pass
 
 
 def write_config(config, filename):
@@ -275,6 +267,7 @@ def write_json_menus(config, filename):
 def update_if_changed(source, destination):
     with open(source, "r") as f:
         source_contents = f.read()
+
     if os.path.exists(destination):
         with open(destination, "r") as f:
             dest_contents = f.read()