def create_config_file(filename):
import textwrap<EOL>from six.moves.urllib import parse<EOL>if not os.path.exists(filename):<EOL><INDENT>old_default_config_file = os.path.join(os.path.dirname(filename),<EOL>'<STR_LIT>')<EOL>if os.path.exists(old_default_config_file):<EOL><INDENT>upgrade = click.confirm("<STR_LIT:\n>".join(textwrap.wrap(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")) + "<STR_LIT>"<EOL>"<STR_LIT>", default=True<EOL>)<EOL>if upgrade:<EOL><INDENT>settings = Settings(old_default_config_file)<EOL>settings.convert_to_4()<EOL>with open(filename, '<STR_LIT:w>') as config_file:<EOL><INDENT>settings.config.write(config_file)<EOL><DEDENT>os.remove(old_default_config_file)<EOL>return<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>")<EOL>sys.exit(<NUM_LIT:0>)<EOL><DEDENT><DEDENT>welcome_msg = "<STR_LIT>"<EOL>click.secho(welcome_msg, fg='<STR_LIT>', bold=True)<EOL>click.secho('<STR_LIT:=>' * len(welcome_msg) + '<STR_LIT:\n>', fg='<STR_LIT>', bold=True)<EOL>click.echo(click.wrap_text(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(<EOL>filename<EOL>)<EOL>) + '<STR_LIT:\n>')<EOL>config = pkg_resources.resource_string('<STR_LIT>', '<STR_LIT>').decode('<STR_LIT:utf-8>')<EOL>context = {}<EOL>available_backends = plugins_registry.get_available_backends()<EOL>context['<STR_LIT>'] = click.prompt(<EOL>"<STR_LIT>" %<EOL>'<STR_LIT:U+002CU+0020>'.join(available_backends),<EOL>type=click.Choice(available_backends)<EOL>)<EOL>context['<STR_LIT:username>'] = click.prompt("<STR_LIT>")<EOL>context['<STR_LIT:password>'] = parse.quote(<EOL>click.prompt("<STR_LIT>"<EOL>"<STR_LIT>", hide_input=True, default='<STR_LIT>'),<EOL>safe='<STR_LIT>'<EOL>)<EOL>if context['<STR_LIT:password>']:<EOL><INDENT>context['<STR_LIT:password>'] = '<STR_LIT::>' + context['<STR_LIT:password>']<EOL><DEDENT>context['<STR_LIT>'] = click.prompt(<EOL>"<STR_LIT>",<EOL>type=Hostname()<EOL>)<EOL>editor = Editor().get_editor()<EOL>context['<STR_LIT>'] = click.prompt(<EOL>"<STR_LIT>", default=editor<EOL>)<EOL>templated_config = config.format(**context)<EOL>directory = os.path.dirname(filename)<EOL>if not os.path.exists(directory):<EOL><INDENT>os.makedirs(directory)<EOL><DEDENT>with open(filename, '<STR_LIT:w>') as f:<EOL><INDENT>f.write(templated_config)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>settings = Settings(filename)<EOL>conversions = settings.needed_conversions<EOL>if conversions:<EOL><INDENT>for conversion in conversions:<EOL><INDENT>conversion()<EOL><DEDENT>settings.write_config()<EOL><DEDENT><DEDENT>
Create main configuration file if it doesn't exist.