We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Bug: conan config install
To help us debug your issue please explain:

- [x] I've read the [CONTRIBUTING guide](https://github.com/conan-io/conan/blob/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.

Following situation:
Running conan 1.15.1 on Linux (Ubuntu 18.4 LTS)
When loading our configuration to a new `CONAN_USER_HOME` and start import our configuration:
`conan config install ~/work/scripts/conan/config/`
I get the following error:
`ERROR: [Errno 2] No such file or directory: '/home/j/tempconan/.conan/remotes.json'`

When I just open in between `conan remote list` it works afterwards.

When running with Conan 1.14.1 it also works. So it must be a bug afterwards.

Here the recipe:
```
mkdir tempconan && cd tempconan
export CONAN_USER_HOME=/home/j/tempconan
conan config install ~/work/scripts/conan/config/
```

And the callstack:
```
j@ubuntu:~/tempconan$ conan config install ~/work/scripts/conan/config/Copying file version.txt to /home/j/tempconan/.conan/.
Copying file artifacts.properties to /home/j/tempconan/.conan/.
Processing conan.conf
Traceback (most recent call last):
  File "/home/j/.local/lib/python3.6/site-packages/conans/client/command.py", line 1607, in run
    method(args[0][1:])
  File "/home/j/.local/lib/python3.6/site-packages/conans/client/command.py", line 478, in config
    target_folder=args.target_folder)
  File "/home/j/.local/lib/python3.6/site-packages/conans/client/conan_api.py", line 92, in wrapper
    return f(*args, **kwargs)
  File "/home/j/.local/lib/python3.6/site-packages/conans/client/conan_api.py", line 621, in config_install
    source_folder=source_folder, target_folder=target_folder)
  File "/home/j/.local/lib/python3.6/site-packages/conans/client/conf/config_installer.py", line 230, in configuration_install
    _process_config(config, cache, output, requester)
  File "/home/j/.local/lib/python3.6/site-packages/conans/client/conf/config_installer.py", line 182, in _process_config
    _process_folder(config, config.uri, cache, output)
  File "/home/j/.local/lib/python3.6/site-packages/conans/client/conf/config_installer.py", line 93, in _process_folder
    os.remove(cache.registry_path)
FileNotFoundError: [Errno 2] No such file or directory: '/home/j/tempconan/.conan/remotes.json'

ERROR: [Errno 2] No such file or directory: '/home/j/tempconan/.conan/remotes.json'

```




--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `conans/client/conf/config_installer.py`
Content:
```
1 import json
2 import os
3 import shutil
4 
5 from contextlib import contextmanager
6 from six.moves.urllib.parse import urlparse
7 
8 from conans import load
9 from conans.client import tools
10 from conans.client.cache.remote_registry import load_registry_txt,\
11     migrate_registry_file
12 from conans.client.tools import Git
13 from conans.client.tools.files import unzip
14 from conans.errors import ConanException
15 from conans.util.files import mkdir, rmdir, walk, save
16 
17 
18 def _hide_password(resource):
19     """
20     Hide password from url/file path
21 
22     :param resource: string with url or file path
23     :return: resource with hidden password if present
24     """
25     password = urlparse(resource).password
26     return resource.replace(password, "<hidden>") if password else resource
27 
28 
29 def _handle_remotes(cache, remote_file):
30     # FIXME: Should we encourage to pass the remotes in json?
31     remotes, _ = load_registry_txt(load(remote_file))
32     cache.registry.define(remotes)
33 
34 
35 @contextmanager
36 def tmp_config_install_folder(cache):
37     tmp_folder = os.path.join(cache.cache_folder, "tmp_config_install")
38     # necessary for Mac OSX, where the temp folders in /var/ are symlinks to /private/var/
39     tmp_folder = os.path.realpath(tmp_folder)
40     mkdir(tmp_folder)
41     try:
42         yield tmp_folder
43     finally:
44         rmdir(tmp_folder)
45 
46 
47 def _process_git_repo(config, cache, output):
48     output.info("Trying to clone repo: %s" % config.uri)
49     with tmp_config_install_folder(cache) as tmp_folder:
50         with tools.chdir(tmp_folder):
51             try:
52                 args = config.args or ""
53                 git = Git(verify_ssl=config.verify_ssl, output=output)
54                 git.clone(config.uri, args=args)
55                 output.info("Repo cloned!")
56             except Exception as e:
57                 raise ConanException("Can't clone repo: %s" % str(e))
58         _process_folder(config, tmp_folder, cache, output)
59 
60 
61 def _process_zip_file(config, zippath, cache, output, tmp_folder, remove=False):
62     unzip(zippath, tmp_folder, output=output)
63     if remove:
64         os.unlink(zippath)
65     _process_folder(config, tmp_folder, cache, output)
66 
67 
68 def _handle_conan_conf(current_conan_conf, new_conan_conf_path):
69     current_conan_conf.read(new_conan_conf_path)
70     with open(current_conan_conf.filename, "w") as f:
71         current_conan_conf.write(f)
72 
73 
74 def _process_folder(config, folder, cache, output):
75     if config.source_folder:
76         folder = os.path.join(folder, config.source_folder)
77     for root, dirs, files in walk(folder):
78         dirs[:] = [d for d in dirs if d != ".git"]
79         if ".git" in root:
80             continue
81         for f in files:
82             if f == "settings.yml":
83                 output.info("Installing settings.yml")
84                 settings_path = cache.settings_path
85                 shutil.copy(os.path.join(root, f), settings_path)
86             elif f == "conan.conf":
87                 output.info("Processing conan.conf")
88                 _handle_conan_conf(cache.config, os.path.join(root, f))
89             elif f == "remotes.txt":
90                 output.info("Defining remotes from remotes.txt")
91                 _handle_remotes(cache, os.path.join(root, f))
92             elif f in ("registry.txt", "registry.json"):
93                 os.remove(cache.registry_path)
94                 shutil.copy(os.path.join(root, f), cache.cache_folder)
95                 migrate_registry_file(cache, output)
96             elif f == "remotes.json":
97                 # Fix for Conan 2.0
98                 raise ConanException("remotes.json install is not supported yet. Use 'remotes.txt'")
99             else:
100                 # This is ugly, should be removed in Conan 2.0
101                 if root == folder and f in ("README.md", "LICENSE.txt"):
102                     output.info("Skip %s" % f)
103                     continue
104                 relpath = os.path.relpath(root, folder)
105                 if config.target_folder:
106                     target_folder = os.path.join(cache.cache_folder, config.target_folder,
107                                                  relpath)
108                 else:
109                     target_folder = os.path.join(cache.cache_folder, relpath)
110                 mkdir(target_folder)
111                 output.info("Copying file %s to %s" % (f, target_folder))
112                 shutil.copy(os.path.join(root, f), target_folder)
113 
114 
115 def _process_download(config, cache, output, requester):
116     with tmp_config_install_folder(cache) as tmp_folder:
117         output.info("Trying to download  %s" % _hide_password(config.uri))
118         zippath = os.path.join(tmp_folder, "config.zip")
119         try:
120             tools.download(config.uri, zippath, out=output, verify=config.verify_ssl,
121                            requester=requester)
122             _process_zip_file(config, zippath, cache, output, tmp_folder, remove=True)
123         except Exception as e:
124             raise ConanException("Error while installing config from %s\n%s" % (config.uri, str(e)))
125 
126 
127 class _ConfigOrigin(object):
128     def __init__(self, data):
129         self.type = data.get("type")
130         self.uri = data.get("uri")
131         self.verify_ssl = data.get("verify_ssl")
132         self.args = data.get("args")
133         self.source_folder = data.get("source_folder")
134         self.target_folder = data.get("target_folder")
135 
136     def __eq__(self, other):
137         return (self.type == other.type and self.uri == other.uri and
138                 self.args == other.args and self.source_folder == other.source_folder
139                 and self.target_folder == other.target_folder)
140 
141     def __ne__(self, other):
142         return not self.__eq__(other)
143 
144     def json(self):
145         return {"type": self.type,
146                 "uri": self.uri,
147                 "verify_ssl": self.verify_ssl,
148                 "args": self.args,
149                 "source_folder": self.source_folder,
150                 "target_folder": self.target_folder}
151 
152     @staticmethod
153     def from_item(uri, config_type, verify_ssl, args, source_folder, target_folder):
154         config = _ConfigOrigin({})
155         if config_type:
156             config.type = config_type
157         else:
158             if uri.endswith(".git"):
159                 config.type = "git"
160             elif os.path.isdir(uri):
161                 config.type = "dir"
162             elif os.path.isfile(uri):
163                 config.type = "file"
164             elif uri.startswith("http"):
165                 config.type = "url"
166             else:
167                 raise ConanException("Unable to deduce type config install: %s" % uri)
168         config.source_folder = source_folder
169         config.target_folder = target_folder
170         config.args = args
171         config.verify_ssl = verify_ssl
172         if os.path.exists(uri):
173             uri = os.path.abspath(uri)
174         config.uri = uri
175         return config
176 
177 
178 def _process_config(config, cache, output, requester):
179     if config.type == "git":
180         _process_git_repo(config, cache, output)
181     elif config.type == "dir":
182         _process_folder(config, config.uri, cache, output)
183     elif config.type == "file":
184         with tmp_config_install_folder(cache) as tmp_folder:
185             _process_zip_file(config, config.uri, cache, output, tmp_folder)
186     elif config.type == "url":
187         _process_download(config, cache, output, requester=requester)
188     else:
189         raise ConanException("Unable to process config install: %s" % config.uri)
190 
191 
192 def _save_configs(configs_file, configs):
193     save(configs_file, json.dumps([config.json() for config in configs],
194                                   indent=True))
195 
196 
197 def configuration_install(uri, cache, output, verify_ssl, requester, config_type=None,
198                           args=None, source_folder=None, target_folder=None):
199     configs = []
200     configs_file = cache.config_install_file
201     if os.path.isfile(configs_file):
202         try:
203             configs = json.loads(load(configs_file))
204         except Exception as e:
205             raise ConanException("Error loading configs-install file: %s\n%"
206                                  % (configs_file, str(e)))
207         configs = [_ConfigOrigin(config) for config in configs]
208     if uri is None:
209         if config_type or args or not verify_ssl:  # Not the defaults
210             if not configs:
211                 raise ConanException("Called config install without arguments")
212             # Modify the last one
213             config = configs[-1]
214             config.config_type = config_type or config.type
215             config.args = args or config.args
216             config.verify_ssl = verify_ssl or config.verify_ssl
217             _process_config(config, cache, output, requester)
218             _save_configs(configs_file, configs)
219         else:
220             if not configs:
221                 raise ConanException("Called config install without arguments")
222             # Execute the previously stored ones
223             for config in configs:
224                 output.info("Config install:  %s" % _hide_password(config.uri))
225                 _process_config(config, cache, output, requester)
226     else:
227         # Execute and store the new one
228         config = _ConfigOrigin.from_item(uri, config_type, verify_ssl, args,
229                                          source_folder, target_folder)
230         _process_config(config, cache, output, requester)
231         if config not in configs:
232             configs.append(config)
233         else:
234             configs = [(c if c != config else config) for c in configs]
235         _save_configs(configs_file, configs)
236
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/conans/client/conf/config_installer.py b/conans/client/conf/config_installer.py
--- a/conans/client/conf/config_installer.py
+++ b/conans/client/conf/config_installer.py
@@ -90,9 +90,13 @@
                 output.info("Defining remotes from remotes.txt")
                 _handle_remotes(cache, os.path.join(root, f))
             elif f in ("registry.txt", "registry.json"):
-                os.remove(cache.registry_path)
-                shutil.copy(os.path.join(root, f), cache.cache_folder)
-                migrate_registry_file(cache, output)
+                try:
+                    os.remove(cache.registry_path)
+                except OSError:
+                    pass
+                finally:
+                    shutil.copy(os.path.join(root, f), cache.cache_folder)
+                    migrate_registry_file(cache, output)
             elif f == "remotes.json":
                 # Fix for Conan 2.0
                 raise ConanException("remotes.json install is not supported yet. Use 'remotes.txt'")

{"golden_diff": "diff --git a/conans/client/conf/config_installer.py b/conans/client/conf/config_installer.py\n--- a/conans/client/conf/config_installer.py\n+++ b/conans/client/conf/config_installer.py\n@@ -90,9 +90,13 @@\n                 output.info(\"Defining remotes from remotes.txt\")\n                 _handle_remotes(cache, os.path.join(root, f))\n             elif f in (\"registry.txt\", \"registry.json\"):\n-                os.remove(cache.registry_path)\n-                shutil.copy(os.path.join(root, f), cache.cache_folder)\n-                migrate_registry_file(cache, output)\n+                try:\n+                    os.remove(cache.registry_path)\n+                except OSError:\n+                    pass\n+                finally:\n+                    shutil.copy(os.path.join(root, f), cache.cache_folder)\n+                    migrate_registry_file(cache, output)\n             elif f == \"remotes.json\":\n                 # Fix for Conan 2.0\n                 raise ConanException(\"remotes.json install is not supported yet. Use 'remotes.txt'\")\n", "issue": "Bug: conan config install\nTo help us debug your issue please explain:\r\n\r\n- [x] I've read the [CONTRIBUTING guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).\r\n- [x] I've specified the Conan version, operating system version and any tool that can be relevant.\r\n- [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.\r\n\r\nFollowing situation:\r\nRunning conan 1.15.1 on Linux (Ubuntu 18.4 LTS)\r\nWhen loading our configuration to a new `CONAN_USER_HOME` and start import our configuration:\r\n`conan config install ~/work/scripts/conan/config/`\r\nI get the following error:\r\n`ERROR: [Errno 2] No such file or directory: '/home/j/tempconan/.conan/remotes.json'`\r\n\r\nWhen I just open in between `conan remote list` it works afterwards.\r\n\r\nWhen running with Conan 1.14.1 it also works. So it must be a bug afterwards.\r\n\r\nHere the recipe:\r\n```\r\nmkdir tempconan && cd tempconan\r\nexport CONAN_USER_HOME=/home/j/tempconan\r\nconan config install ~/work/scripts/conan/config/\r\n```\r\n\r\nAnd the callstack:\r\n```\r\nj@ubuntu:~/tempconan$ conan config install ~/work/scripts/conan/config/Copying file version.txt to /home/j/tempconan/.conan/.\r\nCopying file artifacts.properties to /home/j/tempconan/.conan/.\r\nProcessing conan.conf\r\nTraceback (most recent call last):\r\n  File \"/home/j/.local/lib/python3.6/site-packages/conans/client/command.py\", line 1607, in run\r\n    method(args[0][1:])\r\n  File \"/home/j/.local/lib/python3.6/site-packages/conans/client/command.py\", line 478, in config\r\n    target_folder=args.target_folder)\r\n  File \"/home/j/.local/lib/python3.6/site-packages/conans/client/conan_api.py\", line 92, in wrapper\r\n    return f(*args, **kwargs)\r\n  File \"/home/j/.local/lib/python3.6/site-packages/conans/client/conan_api.py\", line 621, in config_install\r\n    source_folder=source_folder, target_folder=target_folder)\r\n  File \"/home/j/.local/lib/python3.6/site-packages/conans/client/conf/config_installer.py\", line 230, in configuration_install\r\n    _process_config(config, cache, output, requester)\r\n  File \"/home/j/.local/lib/python3.6/site-packages/conans/client/conf/config_installer.py\", line 182, in _process_config\r\n    _process_folder(config, config.uri, cache, output)\r\n  File \"/home/j/.local/lib/python3.6/site-packages/conans/client/conf/config_installer.py\", line 93, in _process_folder\r\n    os.remove(cache.registry_path)\r\nFileNotFoundError: [Errno 2] No such file or directory: '/home/j/tempconan/.conan/remotes.json'\r\n\r\nERROR: [Errno 2] No such file or directory: '/home/j/tempconan/.conan/remotes.json'\r\n\r\n```\r\n\r\n\r\n\n", "before_files": [{"content": "import json\nimport os\nimport shutil\n\nfrom contextlib import contextmanager\nfrom six.moves.urllib.parse import urlparse\n\nfrom conans import load\nfrom conans.client import tools\nfrom conans.client.cache.remote_registry import load_registry_txt,\\\n    migrate_registry_file\nfrom conans.client.tools import Git\nfrom conans.client.tools.files import unzip\nfrom conans.errors import ConanException\nfrom conans.util.files import mkdir, rmdir, walk, save\n\n\ndef _hide_password(resource):\n    \"\"\"\n    Hide password from url/file path\n\n    :param resource: string with url or file path\n    :return: resource with hidden password if present\n    \"\"\"\n    password = urlparse(resource).password\n    return resource.replace(password, \"<hidden>\") if password else resource\n\n\ndef _handle_remotes(cache, remote_file):\n    # FIXME: Should we encourage to pass the remotes in json?\n    remotes, _ = load_registry_txt(load(remote_file))\n    cache.registry.define(remotes)\n\n\n@contextmanager\ndef tmp_config_install_folder(cache):\n    tmp_folder = os.path.join(cache.cache_folder, \"tmp_config_install\")\n    # necessary for Mac OSX, where the temp folders in /var/ are symlinks to /private/var/\n    tmp_folder = os.path.realpath(tmp_folder)\n    mkdir(tmp_folder)\n    try:\n        yield tmp_folder\n    finally:\n        rmdir(tmp_folder)\n\n\ndef _process_git_repo(config, cache, output):\n    output.info(\"Trying to clone repo: %s\" % config.uri)\n    with tmp_config_install_folder(cache) as tmp_folder:\n        with tools.chdir(tmp_folder):\n            try:\n                args = config.args or \"\"\n                git = Git(verify_ssl=config.verify_ssl, output=output)\n                git.clone(config.uri, args=args)\n                output.info(\"Repo cloned!\")\n            except Exception as e:\n                raise ConanException(\"Can't clone repo: %s\" % str(e))\n        _process_folder(config, tmp_folder, cache, output)\n\n\ndef _process_zip_file(config, zippath, cache, output, tmp_folder, remove=False):\n    unzip(zippath, tmp_folder, output=output)\n    if remove:\n        os.unlink(zippath)\n    _process_folder(config, tmp_folder, cache, output)\n\n\ndef _handle_conan_conf(current_conan_conf, new_conan_conf_path):\n    current_conan_conf.read(new_conan_conf_path)\n    with open(current_conan_conf.filename, \"w\") as f:\n        current_conan_conf.write(f)\n\n\ndef _process_folder(config, folder, cache, output):\n    if config.source_folder:\n        folder = os.path.join(folder, config.source_folder)\n    for root, dirs, files in walk(folder):\n        dirs[:] = [d for d in dirs if d != \".git\"]\n        if \".git\" in root:\n            continue\n        for f in files:\n            if f == \"settings.yml\":\n                output.info(\"Installing settings.yml\")\n                settings_path = cache.settings_path\n                shutil.copy(os.path.join(root, f), settings_path)\n            elif f == \"conan.conf\":\n                output.info(\"Processing conan.conf\")\n                _handle_conan_conf(cache.config, os.path.join(root, f))\n            elif f == \"remotes.txt\":\n                output.info(\"Defining remotes from remotes.txt\")\n                _handle_remotes(cache, os.path.join(root, f))\n            elif f in (\"registry.txt\", \"registry.json\"):\n                os.remove(cache.registry_path)\n                shutil.copy(os.path.join(root, f), cache.cache_folder)\n                migrate_registry_file(cache, output)\n            elif f == \"remotes.json\":\n                # Fix for Conan 2.0\n                raise ConanException(\"remotes.json install is not supported yet. Use 'remotes.txt'\")\n            else:\n                # This is ugly, should be removed in Conan 2.0\n                if root == folder and f in (\"README.md\", \"LICENSE.txt\"):\n                    output.info(\"Skip %s\" % f)\n                    continue\n                relpath = os.path.relpath(root, folder)\n                if config.target_folder:\n                    target_folder = os.path.join(cache.cache_folder, config.target_folder,\n                                                 relpath)\n                else:\n                    target_folder = os.path.join(cache.cache_folder, relpath)\n                mkdir(target_folder)\n                output.info(\"Copying file %s to %s\" % (f, target_folder))\n                shutil.copy(os.path.join(root, f), target_folder)\n\n\ndef _process_download(config, cache, output, requester):\n    with tmp_config_install_folder(cache) as tmp_folder:\n        output.info(\"Trying to download  %s\" % _hide_password(config.uri))\n        zippath = os.path.join(tmp_folder, \"config.zip\")\n        try:\n            tools.download(config.uri, zippath, out=output, verify=config.verify_ssl,\n                           requester=requester)\n            _process_zip_file(config, zippath, cache, output, tmp_folder, remove=True)\n        except Exception as e:\n            raise ConanException(\"Error while installing config from %s\\n%s\" % (config.uri, str(e)))\n\n\nclass _ConfigOrigin(object):\n    def __init__(self, data):\n        self.type = data.get(\"type\")\n        self.uri = data.get(\"uri\")\n        self.verify_ssl = data.get(\"verify_ssl\")\n        self.args = data.get(\"args\")\n        self.source_folder = data.get(\"source_folder\")\n        self.target_folder = data.get(\"target_folder\")\n\n    def __eq__(self, other):\n        return (self.type == other.type and self.uri == other.uri and\n                self.args == other.args and self.source_folder == other.source_folder\n                and self.target_folder == other.target_folder)\n\n    def __ne__(self, other):\n        return not self.__eq__(other)\n\n    def json(self):\n        return {\"type\": self.type,\n                \"uri\": self.uri,\n                \"verify_ssl\": self.verify_ssl,\n                \"args\": self.args,\n                \"source_folder\": self.source_folder,\n                \"target_folder\": self.target_folder}\n\n    @staticmethod\n    def from_item(uri, config_type, verify_ssl, args, source_folder, target_folder):\n        config = _ConfigOrigin({})\n        if config_type:\n            config.type = config_type\n        else:\n            if uri.endswith(\".git\"):\n                config.type = \"git\"\n            elif os.path.isdir(uri):\n                config.type = \"dir\"\n            elif os.path.isfile(uri):\n                config.type = \"file\"\n            elif uri.startswith(\"http\"):\n                config.type = \"url\"\n            else:\n                raise ConanException(\"Unable to deduce type config install: %s\" % uri)\n        config.source_folder = source_folder\n        config.target_folder = target_folder\n        config.args = args\n        config.verify_ssl = verify_ssl\n        if os.path.exists(uri):\n            uri = os.path.abspath(uri)\n        config.uri = uri\n        return config\n\n\ndef _process_config(config, cache, output, requester):\n    if config.type == \"git\":\n        _process_git_repo(config, cache, output)\n    elif config.type == \"dir\":\n        _process_folder(config, config.uri, cache, output)\n    elif config.type == \"file\":\n        with tmp_config_install_folder(cache) as tmp_folder:\n            _process_zip_file(config, config.uri, cache, output, tmp_folder)\n    elif config.type == \"url\":\n        _process_download(config, cache, output, requester=requester)\n    else:\n        raise ConanException(\"Unable to process config install: %s\" % config.uri)\n\n\ndef _save_configs(configs_file, configs):\n    save(configs_file, json.dumps([config.json() for config in configs],\n                                  indent=True))\n\n\ndef configuration_install(uri, cache, output, verify_ssl, requester, config_type=None,\n                          args=None, source_folder=None, target_folder=None):\n    configs = []\n    configs_file = cache.config_install_file\n    if os.path.isfile(configs_file):\n        try:\n            configs = json.loads(load(configs_file))\n        except Exception as e:\n            raise ConanException(\"Error loading configs-install file: %s\\n%\"\n                                 % (configs_file, str(e)))\n        configs = [_ConfigOrigin(config) for config in configs]\n    if uri is None:\n        if config_type or args or not verify_ssl:  # Not the defaults\n            if not configs:\n                raise ConanException(\"Called config install without arguments\")\n            # Modify the last one\n            config = configs[-1]\n            config.config_type = config_type or config.type\n            config.args = args or config.args\n            config.verify_ssl = verify_ssl or config.verify_ssl\n            _process_config(config, cache, output, requester)\n            _save_configs(configs_file, configs)\n        else:\n            if not configs:\n                raise ConanException(\"Called config install without arguments\")\n            # Execute the previously stored ones\n            for config in configs:\n                output.info(\"Config install:  %s\" % _hide_password(config.uri))\n                _process_config(config, cache, output, requester)\n    else:\n        # Execute and store the new one\n        config = _ConfigOrigin.from_item(uri, config_type, verify_ssl, args,\n                                         source_folder, target_folder)\n        _process_config(config, cache, output, requester)\n        if config not in configs:\n            configs.append(config)\n        else:\n            configs = [(c if c != config else config) for c in configs]\n        _save_configs(configs_file, configs)\n", "path": "conans/client/conf/config_installer.py"}], "after_files": [{"content": "import json\nimport os\nimport shutil\n\nfrom contextlib import contextmanager\nfrom six.moves.urllib.parse import urlparse\n\nfrom conans import load\nfrom conans.client import tools\nfrom conans.client.cache.remote_registry import load_registry_txt,\\\n    migrate_registry_file\nfrom conans.client.tools import Git\nfrom conans.client.tools.files import unzip\nfrom conans.errors import ConanException\nfrom conans.util.files import mkdir, rmdir, walk, save\n\n\ndef _hide_password(resource):\n    \"\"\"\n    Hide password from url/file path\n\n    :param resource: string with url or file path\n    :return: resource with hidden password if present\n    \"\"\"\n    password = urlparse(resource).password\n    return resource.replace(password, \"<hidden>\") if password else resource\n\n\ndef _handle_remotes(cache, remote_file):\n    # FIXME: Should we encourage to pass the remotes in json?\n    remotes, _ = load_registry_txt(load(remote_file))\n    cache.registry.define(remotes)\n\n\n@contextmanager\ndef tmp_config_install_folder(cache):\n    tmp_folder = os.path.join(cache.cache_folder, \"tmp_config_install\")\n    # necessary for Mac OSX, where the temp folders in /var/ are symlinks to /private/var/\n    tmp_folder = os.path.realpath(tmp_folder)\n    mkdir(tmp_folder)\n    try:\n        yield tmp_folder\n    finally:\n        rmdir(tmp_folder)\n\n\ndef _process_git_repo(config, cache, output):\n    output.info(\"Trying to clone repo: %s\" % config.uri)\n    with tmp_config_install_folder(cache) as tmp_folder:\n        with tools.chdir(tmp_folder):\n            try:\n                args = config.args or \"\"\n                git = Git(verify_ssl=config.verify_ssl, output=output)\n                git.clone(config.uri, args=args)\n                output.info(\"Repo cloned!\")\n            except Exception as e:\n                raise ConanException(\"Can't clone repo: %s\" % str(e))\n        _process_folder(config, tmp_folder, cache, output)\n\n\ndef _process_zip_file(config, zippath, cache, output, tmp_folder, remove=False):\n    unzip(zippath, tmp_folder, output=output)\n    if remove:\n        os.unlink(zippath)\n    _process_folder(config, tmp_folder, cache, output)\n\n\ndef _handle_conan_conf(current_conan_conf, new_conan_conf_path):\n    current_conan_conf.read(new_conan_conf_path)\n    with open(current_conan_conf.filename, \"w\") as f:\n        current_conan_conf.write(f)\n\n\ndef _process_folder(config, folder, cache, output):\n    if config.source_folder:\n        folder = os.path.join(folder, config.source_folder)\n    for root, dirs, files in walk(folder):\n        dirs[:] = [d for d in dirs if d != \".git\"]\n        if \".git\" in root:\n            continue\n        for f in files:\n            if f == \"settings.yml\":\n                output.info(\"Installing settings.yml\")\n                settings_path = cache.settings_path\n                shutil.copy(os.path.join(root, f), settings_path)\n            elif f == \"conan.conf\":\n                output.info(\"Processing conan.conf\")\n                _handle_conan_conf(cache.config, os.path.join(root, f))\n            elif f == \"remotes.txt\":\n                output.info(\"Defining remotes from remotes.txt\")\n                _handle_remotes(cache, os.path.join(root, f))\n            elif f in (\"registry.txt\", \"registry.json\"):\n                try:\n                    os.remove(cache.registry_path)\n                except OSError:\n                    pass\n                finally:\n                    shutil.copy(os.path.join(root, f), cache.cache_folder)\n                    migrate_registry_file(cache, output)\n            elif f == \"remotes.json\":\n                # Fix for Conan 2.0\n                raise ConanException(\"remotes.json install is not supported yet. Use 'remotes.txt'\")\n            else:\n                # This is ugly, should be removed in Conan 2.0\n                if root == folder and f in (\"README.md\", \"LICENSE.txt\"):\n                    output.info(\"Skip %s\" % f)\n                    continue\n                relpath = os.path.relpath(root, folder)\n                if config.target_folder:\n                    target_folder = os.path.join(cache.cache_folder, config.target_folder,\n                                                 relpath)\n                else:\n                    target_folder = os.path.join(cache.cache_folder, relpath)\n                mkdir(target_folder)\n                output.info(\"Copying file %s to %s\" % (f, target_folder))\n                shutil.copy(os.path.join(root, f), target_folder)\n\n\ndef _process_download(config, cache, output, requester):\n    with tmp_config_install_folder(cache) as tmp_folder:\n        output.info(\"Trying to download  %s\" % _hide_password(config.uri))\n        zippath = os.path.join(tmp_folder, \"config.zip\")\n        try:\n            tools.download(config.uri, zippath, out=output, verify=config.verify_ssl,\n                           requester=requester)\n            _process_zip_file(config, zippath, cache, output, tmp_folder, remove=True)\n        except Exception as e:\n            raise ConanException(\"Error while installing config from %s\\n%s\" % (config.uri, str(e)))\n\n\nclass _ConfigOrigin(object):\n    def __init__(self, data):\n        self.type = data.get(\"type\")\n        self.uri = data.get(\"uri\")\n        self.verify_ssl = data.get(\"verify_ssl\")\n        self.args = data.get(\"args\")\n        self.source_folder = data.get(\"source_folder\")\n        self.target_folder = data.get(\"target_folder\")\n\n    def __eq__(self, other):\n        return (self.type == other.type and self.uri == other.uri and\n                self.args == other.args and self.source_folder == other.source_folder\n                and self.target_folder == other.target_folder)\n\n    def __ne__(self, other):\n        return not self.__eq__(other)\n\n    def json(self):\n        return {\"type\": self.type,\n                \"uri\": self.uri,\n                \"verify_ssl\": self.verify_ssl,\n                \"args\": self.args,\n                \"source_folder\": self.source_folder,\n                \"target_folder\": self.target_folder}\n\n    @staticmethod\n    def from_item(uri, config_type, verify_ssl, args, source_folder, target_folder):\n        config = _ConfigOrigin({})\n        if config_type:\n            config.type = config_type\n        else:\n            if uri.endswith(\".git\"):\n                config.type = \"git\"\n            elif os.path.isdir(uri):\n                config.type = \"dir\"\n            elif os.path.isfile(uri):\n                config.type = \"file\"\n            elif uri.startswith(\"http\"):\n                config.type = \"url\"\n            else:\n                raise ConanException(\"Unable to deduce type config install: %s\" % uri)\n        config.source_folder = source_folder\n        config.target_folder = target_folder\n        config.args = args\n        config.verify_ssl = verify_ssl\n        if os.path.exists(uri):\n            uri = os.path.abspath(uri)\n        config.uri = uri\n        return config\n\n\ndef _process_config(config, cache, output, requester):\n    if config.type == \"git\":\n        _process_git_repo(config, cache, output)\n    elif config.type == \"dir\":\n        _process_folder(config, config.uri, cache, output)\n    elif config.type == \"file\":\n        with tmp_config_install_folder(cache) as tmp_folder:\n            _process_zip_file(config, config.uri, cache, output, tmp_folder)\n    elif config.type == \"url\":\n        _process_download(config, cache, output, requester=requester)\n    else:\n        raise ConanException(\"Unable to process config install: %s\" % config.uri)\n\n\ndef _save_configs(configs_file, configs):\n    save(configs_file, json.dumps([config.json() for config in configs],\n                                  indent=True))\n\n\ndef configuration_install(uri, cache, output, verify_ssl, requester, config_type=None,\n                          args=None, source_folder=None, target_folder=None):\n    configs = []\n    configs_file = cache.config_install_file\n    if os.path.isfile(configs_file):\n        try:\n            configs = json.loads(load(configs_file))\n        except Exception as e:\n            raise ConanException(\"Error loading configs-install file: %s\\n%\"\n                                 % (configs_file, str(e)))\n        configs = [_ConfigOrigin(config) for config in configs]\n    if uri is None:\n        if config_type or args or not verify_ssl:  # Not the defaults\n            if not configs:\n                raise ConanException(\"Called config install without arguments\")\n            # Modify the last one\n            config = configs[-1]\n            config.config_type = config_type or config.type\n            config.args = args or config.args\n            config.verify_ssl = verify_ssl or config.verify_ssl\n            _process_config(config, cache, output, requester)\n            _save_configs(configs_file, configs)\n        else:\n            if not configs:\n                raise ConanException(\"Called config install without arguments\")\n            # Execute the previously stored ones\n            for config in configs:\n                output.info(\"Config install:  %s\" % _hide_password(config.uri))\n                _process_config(config, cache, output, requester)\n    else:\n        # Execute and store the new one\n        config = _ConfigOrigin.from_item(uri, config_type, verify_ssl, args,\n                                         source_folder, target_folder)\n        _process_config(config, cache, output, requester)\n        if config not in configs:\n            configs.append(config)\n        else:\n            configs = [(c if c != config else config) for c in configs]\n        _save_configs(configs_file, configs)\n", "path": "conans/client/conf/config_installer.py"}]}