本文整理汇总了Python中twtxt.config.Config.create_config方法的典型用法代码示例。如果您正苦于以下问题:Python Config.create_config方法的具体用法?Python Config.create_config怎么用?Python Config.create_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twtxt.config.Config
的用法示例。
在下文中一共展示了Config.create_config方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: quickstart
# 需要导入模块: from twtxt.config import Config [as 别名]
# 或者: from twtxt.config.Config import create_config [as 别名]
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)))
示例2: quickstart
# 需要导入模块: from twtxt.config import Config [as 别名]
# 或者: from twtxt.config.Config import create_config [as 别名]
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)))
示例3: test_create_config
# 需要导入模块: from twtxt.config import Config [as 别名]
# 或者: from twtxt.config.Config import create_config [as 别名]
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