chore: run black

This commit is contained in:
Jose Diaz-Gonzalez
2020-05-14 23:57:49 -04:00
parent 2cc04faf19
commit 60a95a7c4c

View File

@@ -6,22 +6,31 @@ import re
def compile(service, version, alias, scheme, ports, unimplemented, dokku_version): def compile(service, version, alias, scheme, ports, unimplemented, dokku_version):
return "\n\n".join([ return (
header(service), "\n\n".join(
description(service, version), [
requirements_section(dokku_version), header(service),
installation_section(service, dokku_version), description(service, version),
commands_section(service, alias, scheme, ports, unimplemented), requirements_section(dokku_version),
usage_section(service, alias, scheme, ports, unimplemented), installation_section(service, dokku_version),
]).replace("\n\n\n\n\n", "\n").replace("\n\n\n\n", "\n").replace("\n\n\n", "\n\n") commands_section(service, alias, scheme, ports, unimplemented),
usage_section(service, alias, scheme, ports, unimplemented),
]
)
.replace("\n\n\n\n\n", "\n")
.replace("\n\n\n\n", "\n")
.replace("\n\n\n", "\n\n")
)
def header(service): def header(service):
return " ".join([ return " ".join(
f"# dokku {service}", [
f"[![Build Status](https://img.shields.io/circleci/project/github/dokku/dokku-{service}.svg?branch=master&style=flat-square \"Build Status\")](https://circleci.com/gh/dokku/dokku-{service}/tree/master)", f"# dokku {service}",
f"[![IRC Network](https://img.shields.io/badge/irc-freenode-blue.svg?style=flat-square \"IRC Freenode\")](https://webchat.freenode.net/?channels=dokku)", f'[![Build Status](https://img.shields.io/circleci/project/github/dokku/dokku-{service}.svg?branch=master&style=flat-square "Build Status")](https://circleci.com/gh/dokku/dokku-{service}/tree/master)',
]) f'[![IRC Network](https://img.shields.io/badge/irc-freenode-blue.svg?style=flat-square "IRC Freenode")](https://webchat.freenode.net/?channels=dokku)',
]
)
def description(service, version): def description(service, version):
@@ -29,23 +38,22 @@ def description(service, version):
def requirements_section(dokku_version): def requirements_section(dokku_version):
return "\n".join([ return "\n".join(
"## Requirements", ["## Requirements", "", f"- dokku {dokku_version}", "- docker 1.8.x",]
"", )
f"- dokku {dokku_version}",
"- docker 1.8.x",
])
def installation_section(service, dokku_version): def installation_section(service, dokku_version):
return "\n".join([ return "\n".join(
"## Installation", [
"", "## Installation",
"```shell", "",
f"# on {dokku_version}", "```shell",
f"sudo dokku plugin:install https://github.com/dokku/dokku-{service}.git {service}", f"# on {dokku_version}",
"```", f"sudo dokku plugin:install https://github.com/dokku/dokku-{service}.git {service}",
]) "```",
]
)
def commands_section(service, alias, scheme, ports, unimplemented): def commands_section(service, alias, scheme, ports, unimplemented):
@@ -82,27 +90,41 @@ def commands_section(service, alias, scheme, ports, unimplemented):
def usage_section(service, alias, scheme, ports, unimplemented): def usage_section(service, alias, scheme, ports, unimplemented):
return "\n\n".join([ return "\n\n".join(
"## Usage", [
f"Help for any commands can be displayed by specifying the command as an argument to {service}:help. Please consult the `{service}:help` command for any undocumented commands.", "## Usage",
usage_intro(service, alias, scheme, ports, unimplemented), f"Help for any commands can be displayed by specifying the command as an argument to {service}:help. Please consult the `{service}:help` command for any undocumented commands.",
usage_lifecycle(service, alias, scheme, ports, unimplemented), usage_intro(service, alias, scheme, ports, unimplemented),
usage_automation(service, alias, scheme, ports, unimplemented), usage_lifecycle(service, alias, scheme, ports, unimplemented),
usage_data_management(service, alias, scheme, ports, unimplemented), usage_automation(service, alias, scheme, ports, unimplemented),
usage_backup(service, alias, scheme, ports, unimplemented), usage_data_management(service, alias, scheme, ports, unimplemented),
usage_docker_pull(service, alias, scheme, ports, unimplemented), usage_backup(service, alias, scheme, ports, unimplemented),
]) usage_docker_pull(service, alias, scheme, ports, unimplemented),
]
)
def usage_intro(service, alias, scheme, ports, unimplemented): def usage_intro(service, alias, scheme, ports, unimplemented):
commands = ["create", "info", "list", "logs", "link", "unlink"] commands = ["create", "info", "list", "logs", "link", "unlink"]
content = ["### Basic Usage"] content = ["### Basic Usage"]
return fetch_commands_content(service, alias, scheme, ports, unimplemented, commands, content) return fetch_commands_content(
service, alias, scheme, ports, unimplemented, commands, content
)
def usage_lifecycle(service, alias, scheme, ports, unimplemented): def usage_lifecycle(service, alias, scheme, ports, unimplemented):
commands = ["connect", "enter", "expose", "unexpose", "promote", "start", "stop", "restart", "upgrade"] commands = [
"connect",
"enter",
"expose",
"unexpose",
"promote",
"start",
"stop",
"restart",
"upgrade",
]
content = [ content = [
"### Service Lifecycle", "### Service Lifecycle",
"", "",
@@ -110,7 +132,9 @@ def usage_lifecycle(service, alias, scheme, ports, unimplemented):
"", "",
] ]
return fetch_commands_content(service, alias, scheme, ports, unimplemented, commands, content) return fetch_commands_content(
service, alias, scheme, ports, unimplemented, commands, content
)
def usage_automation(service, alias, scheme, ports, unimplemented): def usage_automation(service, alias, scheme, ports, unimplemented):
@@ -122,7 +146,9 @@ def usage_automation(service, alias, scheme, ports, unimplemented):
"", "",
] ]
return fetch_commands_content(service, alias, scheme, ports, unimplemented, commands, content) return fetch_commands_content(
service, alias, scheme, ports, unimplemented, commands, content
)
def usage_data_management(service, alias, scheme, ports, unimplemented): def usage_data_management(service, alias, scheme, ports, unimplemented):
@@ -134,11 +160,22 @@ def usage_data_management(service, alias, scheme, ports, unimplemented):
"", "",
] ]
return fetch_commands_content(service, alias, scheme, ports, unimplemented, commands, content) return fetch_commands_content(
service, alias, scheme, ports, unimplemented, commands, content
)
def usage_backup(service, alias, scheme, ports, unimplemented): def usage_backup(service, alias, scheme, ports, unimplemented):
commands = ["backup-auth", "backup-deauth", "backup", "backup-set-encryption", "backup-unset-encryption", "backup-schedule", "backup-schedule-cat", "backup-unschedule",] commands = [
"backup-auth",
"backup-deauth",
"backup",
"backup-set-encryption",
"backup-unset-encryption",
"backup-schedule",
"backup-schedule-cat",
"backup-unschedule",
]
content = [ content = [
"### Backups", "### Backups",
"", "",
@@ -150,21 +187,27 @@ def usage_backup(service, alias, scheme, ports, unimplemented):
"", "",
] ]
return fetch_commands_content(service, alias, scheme, ports, unimplemented, commands, content) return fetch_commands_content(
service, alias, scheme, ports, unimplemented, commands, content
)
def usage_docker_pull(service, alias, scheme, ports, unimplemented): def usage_docker_pull(service, alias, scheme, ports, unimplemented):
service_prefix = service.upper() service_prefix = service.upper()
return "\n".join([ return "\n".join(
"### Disabling `docker pull` calls", [
"", "### Disabling `docker pull` calls",
f"If you wish to disable the `docker pull` calls that the plugin triggers, you may set the `{service_prefix}_DISABLE_PULL` environment variable to `true`. Once disabled, you will need to pull the service image you wish to deploy as shown in the `stderr` output.", "",
"", f"If you wish to disable the `docker pull` calls that the plugin triggers, you may set the `{service_prefix}_DISABLE_PULL` environment variable to `true`. Once disabled, you will need to pull the service image you wish to deploy as shown in the `stderr` output.",
"Please ensure the proper images are in place when `docker pull` is disabled.", "",
]) "Please ensure the proper images are in place when `docker pull` is disabled.",
]
)
def fetch_commands_content(service, alias, scheme, ports, unimplemented, commands, content): def fetch_commands_content(
service, alias, scheme, ports, unimplemented, commands, content
):
i = 0 i = 0
for command in commands: for command in commands:
output = command_help(command, service, alias, scheme, ports, unimplemented) output = command_help(command, service, alias, scheme, ports, unimplemented)
@@ -350,7 +393,9 @@ def command_data(command, service, alias, scheme, ports):
def process_sentence(sentence_lines): def process_sentence(sentence_lines):
sentence_lines = " ".join(sentence_lines) sentence_lines = " ".join(sentence_lines)
sentences = ". ".join(i.strip().capitalize() for i in sentence_lines.split(".")).strip() sentences = ". ".join(
i.strip().capitalize() for i in sentence_lines.split(".")
).strip()
if not sentences.endswith(".") and not sentences.endswith(":"): if not sentences.endswith(".") and not sentences.endswith(":"):
sentences += ":" sentences += ":"
return sentences return sentences
@@ -386,17 +431,17 @@ def main():
if "PLUGIN_SCHEME=" in line: if "PLUGIN_SCHEME=" in line:
scheme = re.search('"(.+)"', line).group(1) scheme = re.search('"(.+)"', line).group(1)
if "PLUGIN_DATASTORE_PORTS=" in line: if "PLUGIN_DATASTORE_PORTS=" in line:
ports = re.search('\((.+)\)', line).group(1).split(" ") ports = re.search("\((.+)\)", line).group(1).split(" ")
if "PLUGIN_UNIMPLEMENTED_SUBCOMMANDS=" in line: if "PLUGIN_UNIMPLEMENTED_SUBCOMMANDS=" in line:
match = re.search('\((.+)\)', line) match = re.search("\((.+)\)", line)
if match is not None: if match is not None:
unimplemented = [s.strip('"') for s in match.group(1).split(" ")] unimplemented = [s.strip('"') for s in match.group(1).split(" ")]
text = compile(service, version, alias, scheme, ports, unimplemented, "0.12.x+") text = compile(service, version, alias, scheme, ports, unimplemented, "0.12.x+")
base_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) base_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
readme_file = os.path.join(base_path, 'README.md') readme_file = os.path.join(base_path, "README.md")
with open(readme_file, 'w') as f: with open(readme_file, "w") as f:
f.write(text) f.write(text)