Repository: conan-io/conan

Issue:
Generate new profiles file with same structure as conan profile show
To help us debug your issue please explain:

- [x] I've read the [CONTRIBUTING guide](https://raw.githubusercontent.com/conan-io/conan/develop/.github/CONTRIBUTING.md).
- [x] I've specified the Conan version, operating system version and any tool that can be relevant.
- [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.

```
$ conan profile new test_profile --detect
```
generates profile file with content:

```
[build_requires]
[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=Visual Studio
compiler.version=14
build_type=Release
[options]
[env]
```
However, when showing a profile it looks like:

```
$ conan profile show test_profile
Configuration for profile test_profile:

[settings]
    os=Windows
    os_build=Windows
    arch=x86_64
    arch_build=x86_64
    compiler=Visual Studio
    compiler.version=14
    build_type=Release
[options]
[build_requires]
[env]
```
It would be better to generate the profile file content with same order and identation of the ``$ conan profile show`` command



Discussion:

Resolving patch:
diff --git a/conans/client/printer.py b/conans/client/printer.py
--- a/conans/client/printer.py
+++ b/conans/client/printer.py
@@ -233,11 +233,11 @@ def print_profile(self, name, profile):
         self._print_profile_section("env", envs, separator='=')
 
     def _print_profile_section(self, name, items, indent=0, separator=": "):
-        self._print_colored_line("[%s]" % name, indent=indent)
+        self._print_colored_line("[%s]" % name, indent=indent, color=Color.BRIGHT_RED)
         for key, value in items:
-            self._print_colored_line(key, value=str(value), indent=indent+1, separator=separator)
+            self._print_colored_line(key, value=str(value), indent=0, separator=separator)
 
-    def _print_colored_line(self, text, value=None, indent=0, separator=": "):
+    def _print_colored_line(self, text, value=None, indent=0, separator=": ", color=None):
         """ Print a colored line depending on its indentation level
             Attributes:
                 text: string line
@@ -248,7 +248,7 @@ def _print_colored_line(self, text, value=None, indent=0, separator=": "):
         if not text:
             return
 
-        text_color = Printer.INDENT_COLOR.get(indent, Color.BRIGHT_WHITE)
+        text_color = Printer.INDENT_COLOR.get(indent, Color.BRIGHT_WHITE) if not color else color
         indent_text = ' ' * Printer.INDENT_SPACES * indent
         if value is not None:
             value_color = Color.BRIGHT_WHITE
diff --git a/conans/model/profile.py b/conans/model/profile.py
--- a/conans/model/profile.py
+++ b/conans/model/profile.py
@@ -31,10 +31,7 @@ def package_settings_values(self):
         return result
 
     def dumps(self):
-        result = ["[build_requires]"]
-        for pattern, req_list in self.build_requires.items():
-            result.append("%s: %s" % (pattern, ", ".join(str(r) for r in req_list)))
-        result.append("[settings]")
+        result = ["[settings]"]
         for name, value in self.settings.items():
             result.append("%s=%s" % (name, value))
         for package, values in self.package_settings.items():
@@ -44,6 +41,10 @@ def dumps(self):
         result.append("[options]")
         result.append(self.options.dumps())
 
+        result.append("[build_requires]")
+        for pattern, req_list in self.build_requires.items():
+            result.append("%s: %s" % (pattern, ", ".join(str(r) for r in req_list)))
+
         result.append("[env]")
         result.append(self.env_values.dumps())
 


Test patch:
diff --git a/conans/test/command/profile_test.py b/conans/test/command/profile_test.py
--- a/conans/test/command/profile_test.py
+++ b/conans/test/command/profile_test.py
@@ -47,12 +47,12 @@ def show_test(self):
                        env=[("package:VAR", "value"), ("CXX", "/path/tomy/g++_build"),
                             ("CC", "/path/tomy/gcc_build")])
         client.run("profile show profile1")
-        self.assertIn("    os=Windows", client.user_io.out)
-        self.assertIn("    MyOption=32", client.user_io.out)
+        self.assertIn("[settings]\nos=Windows", client.user_io.out)
+        self.assertIn("MyOption=32", client.user_io.out)
         client.run("profile show profile3")
-        self.assertIn("    CC=/path/tomy/gcc_build", client.user_io.out)
-        self.assertIn("    CXX=/path/tomy/g++_build", client.user_io.out)
-        self.assertIn("    package:VAR=value", client.user_io.out)
+        self.assertIn("CC=/path/tomy/gcc_build", client.user_io.out)
+        self.assertIn("CXX=/path/tomy/g++_build", client.user_io.out)
+        self.assertIn("package:VAR=value", client.user_io.out)
 
     def profile_update_and_get_test(self):
         client = TestClient()
@@ -130,9 +130,9 @@ def profile_new_test(self):
         client.run("profile new ./MyProfile")
         pr_path = os.path.join(client.current_folder, "MyProfile")
         self.assertTrue(os.path.exists(pr_path))
-        self.assertEquals(load(pr_path), """[build_requires]
-[settings]
+        self.assertEquals(load(pr_path), """[settings]
 [options]
+[build_requires]
 [env]
 """)
 
diff --git a/conans/test/generators/generator_filter_error_test.py b/conans/test/generators/generator_filter_error_test.py
--- a/conans/test/generators/generator_filter_error_test.py
+++ b/conans/test/generators/generator_filter_error_test.py
@@ -41,7 +41,7 @@ def test(self):
                      "myprofile": myprofile}, clean_first=True)
         client.run("create . MyLib/0.1@user/channel -pr=myprofile")
         content = load(os.path.join(client.current_folder,
-                                    "test_package/build/1ce01a69e728d0cf98d738a3dc17cee00c9010d2"
+                                    "test_package/build/91852f76fac8dd11832a54cf197288f5fd7d18f4"
                                     "/conanbuildinfo.txt"))
         self.assertIn(".conan/data/MyLib/0.1/user/channel/package/"
                       "5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include",
diff --git a/conans/test/model/profile_test.py b/conans/test/model/profile_test.py
--- a/conans/test/model/profile_test.py
+++ b/conans/test/model/profile_test.py
@@ -68,15 +68,15 @@ def profile_dump_order_test(self):
         profile.settings["compiler.version"] = "12"
         profile.build_requires["*"] = ["zlib/1.2.8@lasote/testing"]
         profile.build_requires["zlib/*"] = ["aaaa/1.2.3@lasote/testing", "bb/1.2@lasote/testing"]
-        self.assertEqual("""[build_requires]
-*: zlib/1.2.8@lasote/testing
-zlib/*: aaaa/1.2.3@lasote/testing, bb/1.2@lasote/testing
-[settings]
+        self.assertEqual("""[settings]
 arch=x86_64
 compiler=Visual Studio
 compiler.version=12
 zlib:compiler=gcc
 [options]
+[build_requires]
+*: zlib/1.2.8@lasote/testing
+zlib/*: aaaa/1.2.3@lasote/testing, bb/1.2@lasote/testing
 [env]""".splitlines(), profile.dumps().splitlines())
 
     def apply_test(self):
@@ -91,7 +91,8 @@ def apply_test(self):
 
         profile.update_settings(OrderedDict([("compiler.version", "14")]))
 
-        self.assertEqual('[build_requires]\n[settings]\narch=x86_64\ncompiler=Visual Studio\ncompiler.version=14\n'
+        self.assertEqual('[settings]\narch=x86_64\ncompiler=Visual Studio\ncompiler.version=14\n'
                          '[options]\n'
+                         '[build_requires]\n'
                          '[env]\nCC=path/to/my/compiler/gcc\nCXX=path/to/my/compiler/g++',
                          profile.dumps())