def quickstart(ctx): """Quickstart wizard for setting up twtxt.""" width = click.get_terminal_size()[0] width = width if width <= 79 else 79 click.secho("twtxt - quickstart", fg="cyan") click.secho("==================", fg="cyan") click.echo() help = "This wizard will generate a basic configuration file for twtxt with all mandatory options set. " \ "Have a look at the README.rst to get information about the other available options and their meaning." click.echo(textwrap.fill(help, width)) click.echo() nick = click.prompt("➤ Please enter your desired nick", default=os.environ.get("USER", "")) twtfile = click.prompt("➤ Please enter the desired location for your twtxt file", "~/twtxt.txt", type=click.Path()) click.echo() add_news = click.confirm("➤ Do you want to follow the twtxt news feed?", default=True) conf = Config(None) conf.create_config(nick, twtfile, add_news) open(os.path.expanduser(twtfile), 'a').close() click.echo() click.echo("✓ Created config file at '{}'.".format(click.format_filename(conf.config_file)))
def quickstart(ctx): """Quickstart wizard for setting up twtxt.""" width = click.get_terminal_size()[0] width = width if width <= 79 else 79 click.secho("twtxt - quickstart", fg="cyan") click.secho("==================", fg="cyan") click.echo() help = "This wizard will generate a basic configuration file for twtxt with all mandatory options set. " \ "Have a look at the README.rst to get information about the other available options and their meaning." click.echo(textwrap.fill(help, width)) click.echo() nick = click.prompt("➤ Please enter your desired nick", default=os.environ.get("USER", "")) twtfile = click.prompt( "➤ Please enter the desired location for your twtxt file", "~/twtxt.txt", type=click.Path()) click.echo() add_news = click.confirm("➤ Do you want to follow the twtxt news feed?", default=True) conf = Config(None) conf.create_config(nick, twtfile, add_news) open(os.path.expanduser(twtfile), 'a').close() click.echo() click.echo("✓ Created config file at '{}'.".format( click.format_filename(conf.config_file)))
def quickstart(): """Quickstart wizard for setting up twtxt.""" width = click.get_terminal_size()[0] width = width if width <= 79 else 79 click.secho("twtxt - quickstart", fg="cyan") click.secho("==================", fg="cyan") click.echo() help_text = "This wizard will generate a basic configuration file for twtxt with all mandatory options set. " \ "You can change all of these later with either twtxt itself or by editing the config file manually. " \ "Have a look at the docs to get information about the other available options and their meaning." click.echo(textwrap.fill(help_text, width)) click.echo() nick = click.prompt("➤ Please enter your desired nick", default=os.environ.get("USER", "")) def overwrite_check(path): if os.path.isfile(path): click.confirm("➤ '{0}' already exists. Overwrite?".format(path), abort=True) cfgfile = click.prompt("➤ Please enter the desired location for your config file", os.path.join(Config.config_dir, Config.config_name), type=click.Path(readable=True, writable=True, file_okay=True)) cfgfile = os.path.expanduser(cfgfile) overwrite_check(cfgfile) twtfile = click.prompt("➤ Please enter the desired location for your twtxt file", os.path.expanduser("~/twtxt.txt"), type=click.Path(readable=True, writable=True, file_okay=True)) twtfile = os.path.expanduser(twtfile) overwrite_check(twtfile) twturl = click.prompt("➤ Please enter the URL your twtxt file will be accessible from", default="https://example.org/twtxt.txt") disclose_identity = click.confirm("➤ Do you want to disclose your identity? Otherwise your nick and URL will be shared when " "making HTTP requests", default=False) click.echo() add_news = click.confirm("➤ Do you want to follow the twtxt news feed?", default=True) conf = Config.create_config(cfgfile, nick, twtfile, twturl, disclose_identity, add_news) twtfile_dir = os.path.dirname(twtfile) if not os.path.exists(twtfile_dir): os.makedirs(twtfile_dir) open(twtfile, "a").close() click.echo() click.echo("✓ Created config file at '{0}'.".format(click.format_filename(conf.config_file))) click.echo("✓ Created twtxt file at '{0}'.".format(click.format_filename(twtfile)))
def quickstart(): """Quickstart wizard for setting up twtxt.""" width = click.get_terminal_size()[0] width = width if width <= 79 else 79 click.secho("twtxt - quickstart", fg="cyan") click.secho("==================", fg="cyan") click.echo() help_text = "This wizard will generate a basic configuration file for twtxt with all mandatory options set. " \ "You can change all of these later with either twtxt itself or by editing the config file manually. " \ "Have a look at the docs to get information about the other available options and their meaning." click.echo(textwrap.fill(help_text, width)) click.echo() nick = click.prompt("➤ Please enter your desired nick", default=os.environ.get("USER", "")) def overwrite_check(path): if os.path.isfile(path): click.confirm("➤ '{0}' already exists. Overwrite?".format(path), abort=True) cfgfile = click.prompt("➤ Please enter the desired location for your config file", os.path.join(Config.config_dir, Config.config_name), type=click.Path(readable=True, writable=True, file_okay=True)) cfgfile = os.path.expanduser(cfgfile) overwrite_check(cfgfile) twtfile = click.prompt("➤ Please enter the desired location for your twtxt file", os.path.expanduser("~/twtxt.txt"), type=click.Path(readable=True, writable=True, file_okay=True)) twtfile = os.path.expanduser(twtfile) overwrite_check(twtfile) twturl = click.prompt("➤ Please enter the URL your twtxt file will be accessible from", default="https://example.org/twtxt.txt") disclose_identity = click.confirm("➤ Do you want to disclose your identity? Your nick and URL will be shared when " "making HTTP requests", default=False) click.echo() add_news = click.confirm("➤ Do you want to follow the twtxt news feed?", default=True) conf = Config.create_config(cfgfile, nick, twtfile, twturl, disclose_identity, add_news) twtfile_dir = os.path.dirname(twtfile) if not os.path.exists(twtfile_dir): os.makedirs(twtfile_dir) open(twtfile, "a").close() click.echo() click.echo("✓ Created config file at '{0}'.".format(click.format_filename(conf.config_file))) click.echo("✓ Created twtxt file at '{0}'.".format(click.format_filename(twtfile)))
def test_create_config(config_dir): config_dir_old = Config.config_dir Config.config_dir = str(config_dir.join("new")) conf_w = Config.create_config("bar", "batz.txt", True) conf_r = Config.discover() assert conf_r.nick == "bar" assert conf_r.twtfile == "batz.txt" assert conf_r.following[0].nick == "twtxt" assert conf_r.following[0].url == "https://buckket.org/twtxt_news.txt" assert set(conf_r.options.keys()) == {"nick", "twtfile"} conf_r.cfg.remove_section("twtxt") assert conf_r.options == {} conf_r.cfg.remove_section("following") assert conf_r.following == [] Config.config_dir = config_dir_old
def test_create_config(config_dir): config_dir_old = Config.config_dir Config.config_dir = str(config_dir.join("new")) conf_w = Config.create_config("bar", "batz.txt", False, True) conf_r = Config.discover() assert conf_r.nick == "bar" assert conf_r.twtfile == "batz.txt" assert conf_r.character_limit == 140 assert conf_r.following[0].nick == "twtxt" assert conf_r.following[0].url == "https://buckket.org/twtxt_news.txt" assert set(conf_r.options.keys()) == {"nick", "twtfile", "disclose_identity", "character_limit"} conf_r.cfg.remove_section("twtxt") assert conf_r.options == {} conf_r.cfg.remove_section("following") assert conf_r.following == [] Config.config_dir = config_dir_old
def test_create_config(config_dir): config_dir_old = Config.config_dir Config.config_dir = str(config_dir.join("new")) conf_w = Config.create_config( os.path.join(Config.config_dir, Config.config_name), "bar", "batz.txt", False, True) conf_r = Config.discover() assert conf_r.nick == "bar" assert conf_r.twtfile == "batz.txt" assert conf_r.character_limit == 140 assert conf_r.character_warning == 140 assert conf_r.following[0].nick == "twtxt" assert conf_r.following[0].url == "https://buckket.org/twtxt_news.txt" assert set(conf_r.options.keys()) == { "nick", "twtfile", "disclose_identity", "character_limit", "character_warning" } conf_r.cfg.remove_section("twtxt") assert conf_r.options == {} conf_r.cfg.remove_section("following") assert conf_r.following == [] Config.config_dir = config_dir_old